From 732fc17c7f291ffaf78dd118465bd982b4cd0b6d Mon Sep 17 00:00:00 2001 From: Benjamin Auquite Date: Sun, 2 Apr 2023 23:56:08 -0500 Subject: [PATCH 1/2] merge related fix --- custom_components/adaptive_lighting/const.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/custom_components/adaptive_lighting/const.py b/custom_components/adaptive_lighting/const.py index 5b8142c5..eb29fa13 100644 --- a/custom_components/adaptive_lighting/const.py +++ b/custom_components/adaptive_lighting/const.py @@ -177,8 +177,6 @@ CONF_USE_DEFAULTS = "use_defaults" TURNING_OFF_DELAY = 5 -CONF_AUTORESET_CONTROL, DEFAULT_AUTORESET_CONTROL = "autoreset_control_seconds", 0 - def int_between(min_int, max_int): """Return an integer between 'min_int' and 'max_int'.""" From 3aa2f3242b06370c0f84248d2c2c21a2556bb5ec Mon Sep 17 00:00:00 2001 From: Benjamin Auquite Date: Mon, 3 Apr 2023 00:55:21 -0500 Subject: [PATCH 2/2] cleanup --- custom_components/adaptive_lighting/switch.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 5d708d60..55479d71 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -1761,6 +1761,9 @@ class TurnOnOffListener: ) if new_state is not None and new_state.state == STATE_ON: + old_state: list[State] | None = self.last_state_change.get(entity_id) + if old_state is None: + return # It is possible to have multiple state change events with the same context. # This can happen because a `turn_on.light(brightness_pct=100, transition=30)` # event leads to an instant state change of @@ -1772,12 +1775,8 @@ class TurnOnOffListener: # called with a color_temp outside of its range (and HA reports the # incorrect 'min_kelvin' and 'max_kelvin', which happens e.g., for # Philips Hue White GU10 Bluetooth lights). - old_state: list[State] | None = self.last_state_change.get(entity_id) if is_our_context(new_state.context): - if ( - old_state is not None - and old_state[0].context.id == new_state.context.id - ): + if old_state[0].context.id == new_state.context.id: _LOGGER.debug( "TurnOnOffListener: State change event of '%s' is already" " in 'self.last_state_change' (%s)" @@ -1794,7 +1793,7 @@ class TurnOnOffListener: ) self.last_state_change[entity_id] = [new_state] self.start_transition_timer(entity_id) - elif old_state is not None: + else: self.last_state_change[entity_id].append(new_state) def is_manually_controlled(