From ce4e04358e925cb2e114d3606e8074f1b44eda63 Mon Sep 17 00:00:00 2001 From: Benjamin Auquite Date: Tue, 11 Apr 2023 19:11:28 -0500 Subject: [PATCH] Squashed commit of the following: commit 1ddae7ac4854c9cb8cfedfea829e9b660cc8366d Merge: 0a4c7ed a888afd Author: Benjamin Auquite Date: Mon Apr 10 12:52:56 2023 -0500 Merge branch 'main' into compare-service-datas-with-ignore-fields commit 0a4c7ed1dd3aa2d411bf6bb3a70fb5aacd6c8240 Author: Benjamin Auquite Date: Sun Apr 9 23:26:41 2023 -0500 Revert "keep line length under 100" This reverts commit 461efb5fed6bf42a8d65be41dae761410d3d9dcb. commit 461efb5fed6bf42a8d65be41dae761410d3d9dcb Author: Benjamin Auquite Date: Sun Apr 9 22:38:04 2023 -0500 keep line length under 100 commit beece5c06f3f80b6148e5a5aa8d4ea7dfb39c497 Author: Benjamin Auquite Date: Sun Apr 9 22:33:50 2023 -0500 ignore ATTR_TRANSITION in checks # Conflicts: # README.md --- 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 6437b192..749dd7e0 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -1327,12 +1327,16 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): elif supports_colors 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, @@ -1340,8 +1344,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(