Fix test_separate_turn_on_commands

This commit is contained in:
Bas Nijholt 2022-08-28 22:02:52 -07:00
commit 60179cbe38
2 changed files with 15 additions and 4 deletions

View file

@ -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

View file

@ -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