mirror of
https://github.com/basnijholt/adaptive-lighting.git
synced 2026-09-15 00:04:05 +02:00
More tests
This commit is contained in:
parent
a6808816ad
commit
a38b51fcc5
2 changed files with 24 additions and 8 deletions
|
|
@ -1509,11 +1509,6 @@ class AdaptiveSwitch(SwitchEntity, RestoreEntity):
|
|||
event.context.id,
|
||||
)
|
||||
|
||||
if is_our_context(event.context):
|
||||
# AFAIK this can only happen in _service_interceptor_turn_on_handler
|
||||
# when calling _adapt_light
|
||||
return
|
||||
|
||||
if (
|
||||
not self._detect_non_ha_changes
|
||||
and not self.manager.is_proactively_adapting(event.context.id)
|
||||
|
|
@ -2080,10 +2075,13 @@ class AdaptiveLightingManager:
|
|||
continue
|
||||
|
||||
for eid in filtered_entity_ids:
|
||||
context = switch.create_context("intercept")
|
||||
self.clear_proactively_adapting(eid)
|
||||
self.set_proactively_adapting(context.id, eid)
|
||||
await switch._adapt_light(
|
||||
light=eid,
|
||||
# Must add a new context otherwise _adapt_light will bail out
|
||||
context=switch.create_context("intercept"),
|
||||
context=context,
|
||||
transition=transition,
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1550,7 +1550,6 @@ async def setup_proactive_multiple_lights_two_switches(hass):
|
|||
{ATTR_ENTITY_ID: lights},
|
||||
blocking=True,
|
||||
)
|
||||
assert all(hass.states.get(light).state == STATE_OFF for light in lights)
|
||||
defaults = {
|
||||
CONF_SUNRISE_TIME: datetime.time(SUNRISE.hour),
|
||||
CONF_SUNSET_TIME: datetime.time(SUNSET.hour),
|
||||
|
|
@ -1561,7 +1560,6 @@ async def setup_proactive_multiple_lights_two_switches(hass):
|
|||
CONF_MIN_COLOR_TEMP: 2500, # to not coincide with sleep_color_temp}
|
||||
INTERNAL_CONF_PROACTIVE_SERVICE_CALL_ADAPTATION: True,
|
||||
}
|
||||
assert all(hass.states.get(light) is not None for light in lights)
|
||||
_, switch1 = await setup_switch(
|
||||
hass, {CONF_NAME: "switch1", CONF_LIGHTS: [ENTITY_LIGHT_1], **defaults}
|
||||
)
|
||||
|
|
@ -1570,6 +1568,7 @@ async def setup_proactive_multiple_lights_two_switches(hass):
|
|||
)
|
||||
assert hass.states.get(switch1.entity_id).state == STATE_ON
|
||||
assert hass.states.get(switch2.entity_id).state == STATE_ON
|
||||
assert all(hass.states.get(light).state == STATE_OFF for light in lights)
|
||||
return lights, switch1, switch2
|
||||
|
||||
|
||||
|
|
@ -1625,6 +1624,25 @@ async def test_proactive_multiple_lights_turn_on_non_managed_light(hass):
|
|||
assert len(turn_ons) == 1, turn_ons
|
||||
|
||||
|
||||
async def test_proactive_multiple_lights_turn_on_managed_lights_only(hass):
|
||||
"""Create switch and demo lights."""
|
||||
lights, switch1, switch2 = await setup_proactive_multiple_lights_two_switches(hass)
|
||||
_LOGGER.debug("Start test_proactive_multiple_lights_all_at_once")
|
||||
# Setup demo lights and turn on
|
||||
events = await _turn_on_and_track_event_contexts(
|
||||
hass, "test1", lights[:-1], return_full_events=True
|
||||
)
|
||||
assert len(events) == 2, events
|
||||
|
||||
# Original turn_on call that is intercepted
|
||||
assert events[0].context.id == "test1"
|
||||
assert events[0].data["service_data"][ATTR_ENTITY_ID] == lights[:-1]
|
||||
|
||||
# The `has_intercepted` path
|
||||
assert events[1].data["service_data"][ATTR_ENTITY_ID] == ENTITY_LIGHT_2
|
||||
assert ":ntrc:" in events[1].context.id
|
||||
|
||||
|
||||
async def test_two_switches_for_single_light(hass):
|
||||
"""Test the case where someone has two switches for a single light.
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue