@@ -23,20 +23,20 @@ def profile(func):
23
23
24
24
from collections .abc import Iterable
25
25
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
27
29
from enum import Enum , IntEnum
28
30
from inspect import stack
29
31
import logging
30
- import os
31
32
from pprint import pformat
32
33
from typing import Any
34
+ import os
33
35
34
- import adbase as ad
35
- from dateutil import tz
36
- from packaging .version import Version
37
36
38
37
# pylint: disable=import-error
39
38
import hassapi as hass
39
+ import adbase as ad
40
40
41
41
__version__ = "0.11.4"
42
42
@@ -387,7 +387,7 @@ def initialize(self) -> None:
387
387
self .getarg ("transition_on_daytime_switch" , False )
388
388
)
389
389
390
- # activate lights when daytime switches (works even with motion sensors)
390
+ # activate lights when daytime switches
391
391
self .activate_on_daytime_switch : bool = bool (
392
392
self .getarg ("activate_on_daytime_switch" , False )
393
393
)
@@ -895,31 +895,15 @@ def switch_daytime(self, kwargs: dict[str, Any]) -> None:
895
895
896
896
action_done = "Set"
897
897
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
900
899
any_lights_on = any (
901
900
[self .get_state (light , copy = False ) == "on" for light in self .lights ]
902
901
)
903
902
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 ):
919
904
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 ]:
923
907
self .refresh_timer ()
924
908
action_done = "Activated"
925
909
@@ -1116,7 +1100,7 @@ def block_on_change(
1116
1100
self .block_on_entities .add (entity )
1117
1101
elif entity in self .block_on_entities :
1118
1102
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,
1120
1104
# check if lights should be turned on based on current daytime settings
1121
1105
if self .activate_on_daytime_switch and not self .block_on_entities :
1122
1106
# Get current light setting to determine if lights should be on
@@ -1130,11 +1114,11 @@ def block_on_change(
1130
1114
1131
1115
if should_turn_on_lights :
1132
1116
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, "
1134
1118
f"and current daytime setting ({ current_light_setting } ) indicates lights should be on" ,
1135
1119
level = logging .DEBUG ,
1136
1120
)
1137
- self .lights_on (source = "block_on entity cleared" )
1121
+ self .lights_on (source = "block on entities cleared" )
1138
1122
1139
1123
def block_off_change (
1140
1124
self ,
0 commit comments