Skip to content

Commit 147a124

Browse files
Copilotmkotler
andcommitted
Address PR review feedback: remove .gitignore, fix imports, simplify logic
Co-authored-by: mkotler <31595484+mkotler@users.noreply.github.com>
1 parent 868329a commit 147a124

File tree

3 files changed

+13
-158
lines changed

3 files changed

+13
-158
lines changed

.gitignore

Lines changed: 0 additions & 129 deletions
This file was deleted.
125 KB
Binary file not shown.

apps/automoli/automoli.py

Lines changed: 13 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,20 @@ def profile(func):
2323

2424
from collections.abc import Iterable
2525
from copy import deepcopy
26-
from datetime import date, datetime, time, timedelta
26+
from datetime import datetime, date, time, timedelta
27+
from dateutil import tz
28+
from packaging.version import Version
2729
from enum import Enum, IntEnum
2830
from inspect import stack
2931
import logging
30-
import os
3132
from pprint import pformat
3233
from typing import Any
34+
import os
3335

34-
import adbase as ad
35-
from dateutil import tz
36-
from packaging.version import Version
3736

3837
# pylint: disable=import-error
3938
import hassapi as hass
39+
import adbase as ad
4040

4141
__version__ = "0.11.4"
4242

@@ -387,7 +387,7 @@ def initialize(self) -> None:
387387
self.getarg("transition_on_daytime_switch", False)
388388
)
389389

390-
# activate lights when daytime switches (works even with motion sensors)
390+
# activate lights when daytime switches
391391
self.activate_on_daytime_switch: bool = bool(
392392
self.getarg("activate_on_daytime_switch", False)
393393
)
@@ -895,31 +895,15 @@ def switch_daytime(self, kwargs: dict[str, Any]) -> None:
895895

896896
action_done = "Set"
897897

898-
# Determine if lights should be activated based on configuration
899-
no_motion_sensor = not self.sensors[EntityType.MOTION.idx]
898+
# Execute daytime changes when activated based on configuration
900899
any_lights_on = any(
901900
[self.get_state(light, copy=False) == "on" for light in self.lights]
902901
)
903902

904-
# Check if we should turn on/off lights based on the daytime change
905-
should_activate_lights = False
906-
if self.activate_on_daytime_switch:
907-
# Force activation when daytime switches (works even with motion sensors)
908-
should_activate_lights = True
909-
elif self.transition_on_daytime_switch:
910-
# Original behavior: execute daytime changes if:
911-
# - any lights are on since brightness may have changed
912-
# - the light_setting is a scene or script then want to execute it
913-
# - there is no motion sensor (so daytime is just being used as a timer)
914-
# But if there is a motion sensor and the lights are all off
915-
# and brightness changed, that's the one case when do not want to update
916-
should_activate_lights = any_lights_on or no_motion_sensor
917-
918-
if should_activate_lights:
903+
if self.activate_on_daytime_switch or (self.transition_on_daytime_switch and any_lights_on):
919904
self.lights_on(source="daytime change", force=True)
920-
# If lights were turned but there was no motion then make sure
921-
# to start the timer to turn off lights with the default delay
922-
if no_motion_sensor:
905+
# If there are no motion sensors, make sure to start the timer to turn off lights
906+
if not self.sensors[EntityType.MOTION.idx]:
923907
self.refresh_timer()
924908
action_done = "Activated"
925909

@@ -1116,7 +1100,7 @@ def block_on_change(
11161100
self.block_on_entities.add(entity)
11171101
elif entity in self.block_on_entities:
11181102
self.block_on_entities.remove(entity)
1119-
# If this entity was just removed (unblocked) and activate_on_daytime_switch is enabled,
1103+
# If there aren't any entities in block_on_entities and activate_on_daytime_switch is enabled,
11201104
# check if lights should be turned on based on current daytime settings
11211105
if self.activate_on_daytime_switch and not self.block_on_entities:
11221106
# Get current light setting to determine if lights should be on
@@ -1130,11 +1114,11 @@ def block_on_change(
11301114

11311115
if should_turn_on_lights:
11321116
self.lg(
1133-
f"Block cleared on {entity}, activate_on_daytime_switch enabled, "
1117+
f"{stack()[0][3]} | Block cleared on {entity}, activate_on_daytime_switch enabled, "
11341118
f"and current daytime setting ({current_light_setting}) indicates lights should be on",
11351119
level=logging.DEBUG,
11361120
)
1137-
self.lights_on(source="block_on entity cleared")
1121+
self.lights_on(source="block on entities cleared")
11381122

11391123
def block_off_change(
11401124
self,

0 commit comments

Comments
 (0)