From b986b3f77cba921cbfb07647dea1d6f876883dd4 Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Mon, 3 Apr 2023 00:20:12 -0700 Subject: [PATCH] Small refactor --- custom_components/adaptive_lighting/switch.py | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index 81bb365d..eb343edc 100644 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -1145,18 +1145,19 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): if lights is None: lights = self._lights - if not force: - if self._only_once: - return - for light in lights: - # Don't adapt lights that haven't finished prior transitions. - if self.turn_on_off_listener.transition_timers.get(light): - lights.remove(light) - - if not len(lights): + if not force and self._only_once: return - await self._adapt_lights(lights, transition, force, context) + filtered_lights = [] + for light in lights: + # Don't adapt lights that haven't finished prior transitions. + if force or not self.turn_on_off_listener.transition_timers.get(light): + filtered_lights.append(light) + + if not filtered_lights: + return + + await self._adapt_lights(filtered_lights, transition, force, context) async def _adapt_lights( self,