From 60179cbe38c3179766877d954cf7538fb8fd315a Mon Sep 17 00:00:00 2001 From: Bas Nijholt Date: Sun, 28 Aug 2022 22:02:52 -0700 Subject: [PATCH] Fix test_separate_turn_on_commands --- custom_components/adaptive_lighting/switch.py | 3 +++ tests/test_switch.py | 16 ++++++++++++---- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/custom_components/adaptive_lighting/switch.py b/custom_components/adaptive_lighting/switch.py index b013d17e..349f36e7 100755 --- a/custom_components/adaptive_lighting/switch.py +++ b/custom_components/adaptive_lighting/switch.py @@ -902,6 +902,7 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity): async def _sleep_mode_switch_state_event(self, event: Event) -> None: if not match_switch_state_event(event, (STATE_ON, STATE_OFF)): + _LOGGER.debug("%s: Ignoring sleep event %s", self._name, event) return _LOGGER.debug( "%s: _sleep_mode_switch_state_event, event: '%s'", self._name, event @@ -1015,10 +1016,12 @@ class SimpleSwitch(SwitchEntity, RestoreEntity): async def async_turn_on(self, **kwargs) -> None: """Turn on adaptive lighting sleep mode.""" + _LOGGER.debug("%s: Turning on", self._name) self._state = True async def async_turn_off(self, **kwargs) -> None: """Turn off adaptive lighting sleep mode.""" + _LOGGER.debug("%s: Turning off", self._name) self._state = False diff --git a/tests/test_switch.py b/tests/test_switch.py index 9aeb131a..5c785bce 100644 --- a/tests/test_switch.py +++ b/tests/test_switch.py @@ -879,14 +879,22 @@ async def test_separate_turn_on_commands(hass, separate_turn_on_commands): await switch.sleep_mode_switch.async_turn_on() await switch._update_attrs_and_maybe_adapt_lights(context=context) await hass.async_block_till_done() - sleep_brightness = light.brightness - sleep_color_temp = light.color_temp + + # TODO: figure out why `light.brightness` is not updating + attrs = hass.states.get(light.entity_id).attributes + sleep_brightness = attrs["brightness"] + sleep_color_temp = attrs["color_temp"] + assert sleep_brightness != brightness assert sleep_color_temp != color_temp + await switch.sleep_mode_switch.async_turn_off() await switch._update_attrs_and_maybe_adapt_lights(context=context) await hass.async_block_till_done() - brightness = light.brightness - color_temp = light.color_temp + + attrs = hass.states.get(light.entity_id).attributes + brightness = attrs["brightness"] + color_temp = attrs["color_temp"] + assert sleep_brightness != brightness assert sleep_color_temp != color_temp