From beece5c06f3f80b6148e5a5aa8d4ea7dfb39c497 Mon Sep 17 00:00:00 2001 From: Benjamin Auquite Date: Sun, 9 Apr 2023 22:33:50 -0500 Subject: [PATCH 1/3] ignore ATTR_TRANSITION in checks --- custom_components/adaptive_lighting/switch.py | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 98747a17..75f90361 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -1133,12 +1133,16 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): elif "color" in features and adapt_color: _LOGGER.debug("%s: Setting rgb_color of light %s", self._name, light) service_data[ATTR_RGB_COLOR] = self._settings["rgb_color"] - - context = context or self.create_context("adapt_lights") - - # See #80. Doesn't check if transitions differ but it does the job. - last_service_data = self.turn_on_off_listener.last_service_data - if not force and last_service_data.get(light) == service_data: + # Check if service data differs from the last. See #80. + listener = self.turn_on_off_listener + last_service_data = listener.last_service_data.get(light) + ignore_fields = {ATTR_TRANSITION} + if ( + not force + and last_service_data + and {k for k, _ in last_service_data.items() ^ service_data.items()} + == ignore_fields + ): _LOGGER.debug( "%s: Cancelling adapt to light %s, there's no new values to set (context.id='%s')", self._name, @@ -1146,8 +1150,9 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): context.id, ) return - else: - self.turn_on_off_listener.last_service_data[light] = service_data + listener.last_service_data[light] = service_data + + context = context or self.create_context("adapt_lights") async def turn_on(service_data): _LOGGER.debug( From 461efb5fed6bf42a8d65be41dae761410d3d9dcb Mon Sep 17 00:00:00 2001 From: Benjamin Auquite Date: Sun, 9 Apr 2023 22:38:04 -0500 Subject: [PATCH 2/3] keep line length under 100 --- custom_components/adaptive_lighting/switch.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 75f90361..759bc891 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -1137,12 +1137,10 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): listener = self.turn_on_off_listener last_service_data = listener.last_service_data.get(light) ignore_fields = {ATTR_TRANSITION} - if ( - not force - and last_service_data - and {k for k, _ in last_service_data.items() ^ service_data.items()} - == ignore_fields - ): + differing_fields = { + k for k, _ in last_service_data.items() ^ service_data.items() + } + if not force and last_service_data and differing_fields == ignore_fields: _LOGGER.debug( "%s: Cancelling adapt to light %s, there's no new values to set (context.id='%s')", self._name, From 0a4c7ed1dd3aa2d411bf6bb3a70fb5aacd6c8240 Mon Sep 17 00:00:00 2001 From: Benjamin Auquite Date: Sun, 9 Apr 2023 23:26:41 -0500 Subject: [PATCH 3/3] Revert "keep line length under 100" This reverts commit 461efb5fed6bf42a8d65be41dae761410d3d9dcb. --- custom_components/adaptive_lighting/switch.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 759bc891..75f90361 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -1137,10 +1137,12 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): listener = self.turn_on_off_listener last_service_data = listener.last_service_data.get(light) ignore_fields = {ATTR_TRANSITION} - differing_fields = { - k for k, _ in last_service_data.items() ^ service_data.items() - } - if not force and last_service_data and differing_fields == ignore_fields: + if ( + not force + and last_service_data + and {k for k, _ in last_service_data.items() ^ service_data.items()} + == ignore_fields + ): _LOGGER.debug( "%s: Cancelling adapt to light %s, there's no new values to set (context.id='%s')", self._name,