Several optimizations to automations (#35007)

This commit is contained in:
Franck Nijhof 2020-05-01 16:37:25 +02:00 committed by GitHub
parent f3d79104a7
commit 8c65062271
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 330 additions and 325 deletions

View file

@ -1,4 +1,5 @@
"""Allow to set up simple automation rules via the config file.""" """Allow to set up simple automation rules via the config file."""
import asyncio
import importlib import importlib
import logging import logging
from typing import Any, Awaitable, Callable, List, Optional, Set from typing import Any, Awaitable, Callable, List, Optional, Set
@ -127,13 +128,11 @@ def automations_with_entity(hass: HomeAssistant, entity_id: str) -> List[str]:
component = hass.data[DOMAIN] component = hass.data[DOMAIN]
results = [] return [
automation_entity.entity_id
for automation_entity in component.entities: for automation_entity in component.entities
if entity_id in automation_entity.referenced_entities: if entity_id in automation_entity.referenced_entities
results.append(automation_entity.entity_id) ]
return results
@callback @callback
@ -160,13 +159,11 @@ def automations_with_device(hass: HomeAssistant, device_id: str) -> List[str]:
component = hass.data[DOMAIN] component = hass.data[DOMAIN]
results = [] return [
automation_entity.entity_id
for automation_entity in component.entities: for automation_entity in component.entities
if device_id in automation_entity.referenced_devices: if device_id in automation_entity.referenced_devices
results.append(automation_entity.entity_id) ]
return results
@callback @callback
@ -443,26 +440,29 @@ class AutomationEntity(ToggleEntity, RestoreEntity):
self, home_assistant_start: bool self, home_assistant_start: bool
) -> Optional[Callable[[], None]]: ) -> Optional[Callable[[], None]]:
"""Set up the triggers.""" """Set up the triggers."""
removes = []
info = {"name": self._name, "home_assistant_start": home_assistant_start} info = {"name": self._name, "home_assistant_start": home_assistant_start}
triggers = []
for conf in self._trigger_config: for conf in self._trigger_config:
platform = importlib.import_module(f".{conf[CONF_PLATFORM]}", __name__) platform = importlib.import_module(f".{conf[CONF_PLATFORM]}", __name__)
remove = await platform.async_attach_trigger( # type: ignore triggers.append(
self.hass, conf, self.async_trigger, info platform.async_attach_trigger( # type: ignore
self.hass, conf, self.async_trigger, info
)
) )
if not remove: results = await asyncio.gather(*triggers)
_LOGGER.error("Error setting up trigger %s", self._name)
continue
_LOGGER.info("Initialized trigger %s", self._name) if None in results:
removes.append(remove) _LOGGER.error("Error setting up trigger %s", self._name)
removes = [remove for remove in results if remove is not None]
if not removes: if not removes:
return None return None
_LOGGER.info("Initialized trigger %s", self._name)
@callback @callback
def remove_triggers(): def remove_triggers():
"""Remove attached triggers.""" """Remove attached triggers."""

View file

@ -36,17 +36,19 @@ async def async_validate_config_item(hass, config, full_config=None):
config[CONF_TRIGGER] = triggers config[CONF_TRIGGER] = triggers
if CONF_CONDITION in config: if CONF_CONDITION in config:
conditions = [] config[CONF_CONDITION] = await asyncio.gather(
for cond in config[CONF_CONDITION]: *[
cond = await condition.async_validate_condition_config(hass, cond) condition.async_validate_condition_config(hass, cond)
conditions.append(cond) for cond in config[CONF_CONDITION]
config[CONF_CONDITION] = conditions ]
)
actions = [] config[CONF_ACTION] = await asyncio.gather(
for action in config[CONF_ACTION]: *[
action = await script.async_validate_action_config(hass, action) script.async_validate_action_config(hass, action)
actions.append(action) for action in config[CONF_ACTION]
config[CONF_ACTION] = actions ]
)
return config return config
@ -69,16 +71,18 @@ async def _try_async_validate_config_item(hass, config, full_config=None):
async def async_validate_config(hass, config): async def async_validate_config(hass, config):
"""Validate config.""" """Validate config."""
automations = []
validated_automations = await asyncio.gather( validated_automations = await asyncio.gather(
*( *(
_try_async_validate_config_item(hass, p_config, config) _try_async_validate_config_item(hass, p_config, config)
for _, p_config in config_per_platform(config, DOMAIN) for _, p_config in config_per_platform(config, DOMAIN)
) )
) )
for validated_automation in validated_automations:
if validated_automation is not None: automations = [
automations.append(validated_automation) validated_automation
for validated_automation in validated_automations
if validated_automation is not None
]
# Create a copy of the configuration with all config for current # Create a copy of the configuration with all config for current
# component removed and add validated config back in. # component removed and add validated config back in.

View file

@ -85,9 +85,13 @@ async def async_attach_trigger(hass, config, action, automation_info):
cancel_pressed_more_than() cancel_pressed_more_than()
cancel_pressed_more_than = None cancel_pressed_more_than = None
held_time = dt_util.utcnow() - pressed_time held_time = dt_util.utcnow() - pressed_time
if held_less_than is not None and held_time < held_less_than:
if held_more_than is None or held_time > held_more_than: if (
hass.add_job(call_action) held_less_than is not None
and held_time < held_less_than
and (held_more_than is None or held_time > held_more_than)
):
hass.add_job(call_action)
hass.data["litejet_system"].on_switch_pressed(number, pressed) hass.data["litejet_system"].on_switch_pressed(number, pressed)
hass.data["litejet_system"].on_switch_released(number, released) hass.data["litejet_system"].on_switch_released(number, released)

View file

@ -47,10 +47,7 @@ async def async_attach_trigger(hass, config, action, automation_info):
return return
zone_state = hass.states.get(zone_entity_id) zone_state = hass.states.get(zone_entity_id)
if from_s: from_match = condition.zone(hass, zone_state, from_s) if from_s else False
from_match = condition.zone(hass, zone_state, from_s)
else:
from_match = False
to_match = condition.zone(hass, zone_state, to_s) to_match = condition.zone(hass, zone_state, to_s)
if ( if (

View file

@ -46,7 +46,7 @@ async def test_if_fires_on_event(hass, calls):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_event_extra_data(hass, calls): async def test_if_fires_on_event_extra_data(hass, calls):
@ -64,14 +64,14 @@ async def test_if_fires_on_event_extra_data(hass, calls):
hass.bus.async_fire("test_event", {"extra_key": "extra_data"}) hass.bus.async_fire("test_event", {"extra_key": "extra_data"})
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
await common.async_turn_off(hass) await common.async_turn_off(hass)
await hass.async_block_till_done() await hass.async_block_till_done()
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_event_with_data(hass, calls): async def test_if_fires_on_event_with_data(hass, calls):
@ -93,7 +93,7 @@ async def test_if_fires_on_event_with_data(hass, calls):
hass.bus.async_fire("test_event", {"some_attr": "some_value", "another": "value"}) hass.bus.async_fire("test_event", {"some_attr": "some_value", "another": "value"})
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_event_with_empty_data_config(hass, calls): async def test_if_fires_on_event_with_empty_data_config(hass, calls):
@ -119,7 +119,7 @@ async def test_if_fires_on_event_with_empty_data_config(hass, calls):
hass.bus.async_fire("test_event", {"some_attr": "some_value", "another": "value"}) hass.bus.async_fire("test_event", {"some_attr": "some_value", "another": "value"})
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_event_with_nested_data(hass, calls): async def test_if_fires_on_event_with_nested_data(hass, calls):
@ -143,7 +143,7 @@ async def test_if_fires_on_event_with_nested_data(hass, calls):
"test_event", {"parent_attr": {"some_attr": "some_value", "another": "value"}} "test_event", {"parent_attr": {"some_attr": "some_value", "another": "value"}}
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_not_fires_if_event_data_not_matches(hass, calls): async def test_if_not_fires_if_event_data_not_matches(hass, calls):
@ -165,4 +165,4 @@ async def test_if_not_fires_if_event_data_not_matches(hass, calls):
hass.bus.async_fire("test_event", {"some_attr": "some_other_value"}) hass.bus.async_fire("test_event", {"some_attr": "some_other_value"})
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0

View file

@ -83,11 +83,11 @@ async def test_if_fires_on_zone_enter(hass, calls):
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert calls[0].context.parent_id == context.id assert calls[0].context.parent_id == context.id
assert ( assert (
"geo_location - geo_location.entity - hello - hello - test" calls[0].data["some"]
== calls[0].data["some"] == "geo_location - geo_location.entity - hello - hello - test"
) )
# Set out of zone again so we can trigger call # Set out of zone again so we can trigger call
@ -108,7 +108,7 @@ async def test_if_fires_on_zone_enter(hass, calls):
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_not_fires_for_enter_on_zone_leave(hass, calls): async def test_if_not_fires_for_enter_on_zone_leave(hass, calls):
@ -143,7 +143,7 @@ async def test_if_not_fires_for_enter_on_zone_leave(hass, calls):
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_fires_on_zone_leave(hass, calls): async def test_if_fires_on_zone_leave(hass, calls):
@ -178,7 +178,7 @@ async def test_if_fires_on_zone_leave(hass, calls):
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_not_fires_for_leave_on_zone_enter(hass, calls): async def test_if_not_fires_for_leave_on_zone_enter(hass, calls):
@ -213,7 +213,7 @@ async def test_if_not_fires_for_leave_on_zone_enter(hass, calls):
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_fires_on_zone_appear(hass, calls): async def test_if_fires_on_zone_appear(hass, calls):
@ -258,10 +258,10 @@ async def test_if_fires_on_zone_appear(hass, calls):
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert calls[0].context.parent_id == context.id assert calls[0].context.parent_id == context.id
assert ( assert (
"geo_location - geo_location.entity - - hello - test" == calls[0].data["some"] calls[0].data["some"] == "geo_location - geo_location.entity - - hello - test"
) )
@ -308,7 +308,7 @@ async def test_if_fires_on_zone_disappear(hass, calls):
hass.states.async_remove("geo_location.entity") hass.states.async_remove("geo_location.entity")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert ( assert (
"geo_location - geo_location.entity - hello - - test" == calls[0].data["some"] calls[0].data["some"] == "geo_location - geo_location.entity - hello - - test"
) )

View file

@ -148,7 +148,7 @@ async def test_service_specify_entity_id(hass, calls):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert ["hello.world"] == calls[0].data.get(ATTR_ENTITY_ID) assert ["hello.world"] == calls[0].data.get(ATTR_ENTITY_ID)
@ -170,7 +170,7 @@ async def test_service_specify_entity_id_list(hass, calls):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert ["hello.world", "hello.world2"] == calls[0].data.get(ATTR_ENTITY_ID) assert ["hello.world", "hello.world2"] == calls[0].data.get(ATTR_ENTITY_ID)
@ -192,10 +192,10 @@ async def test_two_triggers(hass, calls):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
hass.states.async_set("test.entity", "hello") hass.states.async_set("test.entity", "hello")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
async def test_trigger_service_ignoring_condition(hass, calls): async def test_trigger_service_ignoring_condition(hass, calls):
@ -268,17 +268,17 @@ async def test_two_conditions_with_and(hass, calls):
hass.states.async_set(entity_id, 100) hass.states.async_set(entity_id, 100)
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
hass.states.async_set(entity_id, 101) hass.states.async_set(entity_id, 101)
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
hass.states.async_set(entity_id, 151) hass.states.async_set(entity_id, 151)
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_automation_list_setting(hass, calls): async def test_automation_list_setting(hass, calls):
@ -302,11 +302,11 @@ async def test_automation_list_setting(hass, calls):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
hass.bus.async_fire("test_event_2") hass.bus.async_fire("test_event_2")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
async def test_automation_calling_two_actions(hass, calls): async def test_automation_calling_two_actions(hass, calls):
@ -368,7 +368,7 @@ async def test_shared_context(hass, calls):
assert event_mock.call_count == 2 assert event_mock.call_count == 2
# Verify automation triggered evenet for 'hello' automation # Verify automation triggered evenet for 'hello' automation
args, kwargs = event_mock.call_args_list[0] args, _ = event_mock.call_args_list[0]
first_trigger_context = args[0].context first_trigger_context = args[0].context
assert first_trigger_context.parent_id == context.id assert first_trigger_context.parent_id == context.id
# Ensure event data has all attributes set # Ensure event data has all attributes set
@ -376,7 +376,7 @@ async def test_shared_context(hass, calls):
assert args[0].data.get(ATTR_ENTITY_ID) is not None assert args[0].data.get(ATTR_ENTITY_ID) is not None
# Ensure context set correctly for event fired by 'hello' automation # Ensure context set correctly for event fired by 'hello' automation
args, kwargs = first_automation_listener.call_args args, _ = first_automation_listener.call_args
assert args[0].context is first_trigger_context assert args[0].context is first_trigger_context
# Ensure the 'hello' automation state has the right context # Ensure the 'hello' automation state has the right context
@ -385,7 +385,7 @@ async def test_shared_context(hass, calls):
assert state.context is first_trigger_context assert state.context is first_trigger_context
# Verify automation triggered evenet for 'bye' automation # Verify automation triggered evenet for 'bye' automation
args, kwargs = event_mock.call_args_list[1] args, _ = event_mock.call_args_list[1]
second_trigger_context = args[0].context second_trigger_context = args[0].context
assert second_trigger_context.parent_id == first_trigger_context.id assert second_trigger_context.parent_id == first_trigger_context.id
# Ensure event data has all attributes set # Ensure event data has all attributes set

View file

@ -57,7 +57,7 @@ async def test_if_fires_on_topic_match(hass, calls):
await hass.async_block_till_done() await hass.async_block_till_done()
async_fire_mqtt_message(hass, "test-topic", "test_payload") async_fire_mqtt_message(hass, "test-topic", "test_payload")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_topic_and_payload_match(hass, calls): async def test_if_fires_on_topic_and_payload_match(hass, calls):
@ -79,7 +79,7 @@ async def test_if_fires_on_topic_and_payload_match(hass, calls):
async_fire_mqtt_message(hass, "test-topic", "hello") async_fire_mqtt_message(hass, "test-topic", "hello")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_not_fires_on_topic_but_no_payload_match(hass, calls): async def test_if_not_fires_on_topic_but_no_payload_match(hass, calls):
@ -101,7 +101,7 @@ async def test_if_not_fires_on_topic_but_no_payload_match(hass, calls):
async_fire_mqtt_message(hass, "test-topic", "no-hello") async_fire_mqtt_message(hass, "test-topic", "no-hello")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_encoding_default(hass, calls): async def test_encoding_default(hass, calls):

View file

@ -52,7 +52,7 @@ async def test_if_fires_on_entity_change_below(hass, calls):
# 9 is below 10 # 9 is below 10
hass.states.async_set("test.entity", 9, context=context) hass.states.async_set("test.entity", 9, context=context)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert calls[0].context.parent_id == context.id assert calls[0].context.parent_id == context.id
# Set above 12 so the automation will fire again # Set above 12 so the automation will fire again
@ -61,7 +61,7 @@ async def test_if_fires_on_entity_change_below(hass, calls):
await hass.async_block_till_done() await hass.async_block_till_done()
hass.states.async_set("test.entity", 9) hass.states.async_set("test.entity", 9)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_entity_change_over_to_below(hass, calls): async def test_if_fires_on_entity_change_over_to_below(hass, calls):
@ -87,7 +87,7 @@ async def test_if_fires_on_entity_change_over_to_below(hass, calls):
# 9 is below 10 # 9 is below 10
hass.states.async_set("test.entity", 9) hass.states.async_set("test.entity", 9)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_entities_change_over_to_below(hass, calls): async def test_if_fires_on_entities_change_over_to_below(hass, calls):
@ -114,10 +114,10 @@ async def test_if_fires_on_entities_change_over_to_below(hass, calls):
# 9 is below 10 # 9 is below 10
hass.states.async_set("test.entity_1", 9) hass.states.async_set("test.entity_1", 9)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
hass.states.async_set("test.entity_2", 9) hass.states.async_set("test.entity_2", 9)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
async def test_if_not_fires_on_entity_change_below_to_below(hass, calls): async def test_if_not_fires_on_entity_change_below_to_below(hass, calls):
@ -144,18 +144,18 @@ async def test_if_not_fires_on_entity_change_below_to_below(hass, calls):
# 9 is below 10 so this should fire # 9 is below 10 so this should fire
hass.states.async_set("test.entity", 9, context=context) hass.states.async_set("test.entity", 9, context=context)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert calls[0].context.parent_id == context.id assert calls[0].context.parent_id == context.id
# already below so should not fire again # already below so should not fire again
hass.states.async_set("test.entity", 5) hass.states.async_set("test.entity", 5)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# still below so should not fire again # still below so should not fire again
hass.states.async_set("test.entity", 3) hass.states.async_set("test.entity", 3)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_not_below_fires_on_entity_change_to_equal(hass, calls): async def test_if_not_below_fires_on_entity_change_to_equal(hass, calls):
@ -181,7 +181,7 @@ async def test_if_not_below_fires_on_entity_change_to_equal(hass, calls):
# 10 is not below 10 so this should not fire again # 10 is not below 10 so this should not fire again
hass.states.async_set("test.entity", 10) hass.states.async_set("test.entity", 10)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_fires_on_initial_entity_below(hass, calls): async def test_if_fires_on_initial_entity_below(hass, calls):
@ -207,7 +207,7 @@ async def test_if_fires_on_initial_entity_below(hass, calls):
# Fire on first update even if initial state was already below # Fire on first update even if initial state was already below
hass.states.async_set("test.entity", 8) hass.states.async_set("test.entity", 8)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_initial_entity_above(hass, calls): async def test_if_fires_on_initial_entity_above(hass, calls):
@ -233,7 +233,7 @@ async def test_if_fires_on_initial_entity_above(hass, calls):
# Fire on first update even if initial state was already above # Fire on first update even if initial state was already above
hass.states.async_set("test.entity", 12) hass.states.async_set("test.entity", 12)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_entity_change_above(hass, calls): async def test_if_fires_on_entity_change_above(hass, calls):
@ -255,7 +255,7 @@ async def test_if_fires_on_entity_change_above(hass, calls):
# 11 is above 10 # 11 is above 10
hass.states.async_set("test.entity", 11) hass.states.async_set("test.entity", 11)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_entity_change_below_to_above(hass, calls): async def test_if_fires_on_entity_change_below_to_above(hass, calls):
@ -282,7 +282,7 @@ async def test_if_fires_on_entity_change_below_to_above(hass, calls):
# 11 is above 10 and 9 is below # 11 is above 10 and 9 is below
hass.states.async_set("test.entity", 11) hass.states.async_set("test.entity", 11)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_not_fires_on_entity_change_above_to_above(hass, calls): async def test_if_not_fires_on_entity_change_above_to_above(hass, calls):
@ -309,12 +309,12 @@ async def test_if_not_fires_on_entity_change_above_to_above(hass, calls):
# 12 is above 10 so this should fire # 12 is above 10 so this should fire
hass.states.async_set("test.entity", 12) hass.states.async_set("test.entity", 12)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# already above, should not fire again # already above, should not fire again
hass.states.async_set("test.entity", 15) hass.states.async_set("test.entity", 15)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_not_above_fires_on_entity_change_to_equal(hass, calls): async def test_if_not_above_fires_on_entity_change_to_equal(hass, calls):
@ -341,7 +341,7 @@ async def test_if_not_above_fires_on_entity_change_to_equal(hass, calls):
# 10 is not above 10 so this should not fire again # 10 is not above 10 so this should not fire again
hass.states.async_set("test.entity", 10) hass.states.async_set("test.entity", 10)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_fires_on_entity_change_below_range(hass, calls): async def test_if_fires_on_entity_change_below_range(hass, calls):
@ -364,7 +364,7 @@ async def test_if_fires_on_entity_change_below_range(hass, calls):
# 9 is below 10 # 9 is below 10
hass.states.async_set("test.entity", 9) hass.states.async_set("test.entity", 9)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_entity_change_below_above_range(hass, calls): async def test_if_fires_on_entity_change_below_above_range(hass, calls):
@ -387,7 +387,7 @@ async def test_if_fires_on_entity_change_below_above_range(hass, calls):
# 4 is below 5 # 4 is below 5
hass.states.async_set("test.entity", 4) hass.states.async_set("test.entity", 4)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_fires_on_entity_change_over_to_below_range(hass, calls): async def test_if_fires_on_entity_change_over_to_below_range(hass, calls):
@ -414,7 +414,7 @@ async def test_if_fires_on_entity_change_over_to_below_range(hass, calls):
# 9 is below 10 # 9 is below 10
hass.states.async_set("test.entity", 9) hass.states.async_set("test.entity", 9)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_entity_change_over_to_below_above_range(hass, calls): async def test_if_fires_on_entity_change_over_to_below_above_range(hass, calls):
@ -441,7 +441,7 @@ async def test_if_fires_on_entity_change_over_to_below_above_range(hass, calls):
# 4 is below 5 so it should not fire # 4 is below 5 so it should not fire
hass.states.async_set("test.entity", 4) hass.states.async_set("test.entity", 4)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_not_fires_if_entity_not_match(hass, calls): async def test_if_not_fires_if_entity_not_match(hass, calls):
@ -463,7 +463,7 @@ async def test_if_not_fires_if_entity_not_match(hass, calls):
hass.states.async_set("test.entity", 11) hass.states.async_set("test.entity", 11)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_fires_on_entity_change_below_with_attribute(hass, calls): async def test_if_fires_on_entity_change_below_with_attribute(hass, calls):
@ -485,7 +485,7 @@ async def test_if_fires_on_entity_change_below_with_attribute(hass, calls):
# 9 is below 10 # 9 is below 10
hass.states.async_set("test.entity", 9, {"test_attribute": 11}) hass.states.async_set("test.entity", 9, {"test_attribute": 11})
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_not_fires_on_entity_change_not_below_with_attribute(hass, calls): async def test_if_not_fires_on_entity_change_not_below_with_attribute(hass, calls):
@ -507,7 +507,7 @@ async def test_if_not_fires_on_entity_change_not_below_with_attribute(hass, call
# 11 is not below 10 # 11 is not below 10
hass.states.async_set("test.entity", 11, {"test_attribute": 9}) hass.states.async_set("test.entity", 11, {"test_attribute": 9})
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_fires_on_attribute_change_with_attribute_below(hass, calls): async def test_if_fires_on_attribute_change_with_attribute_below(hass, calls):
@ -530,7 +530,7 @@ async def test_if_fires_on_attribute_change_with_attribute_below(hass, calls):
# 9 is below 10 # 9 is below 10
hass.states.async_set("test.entity", "entity", {"test_attribute": 9}) hass.states.async_set("test.entity", "entity", {"test_attribute": 9})
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_not_fires_on_attribute_change_with_attribute_not_below(hass, calls): async def test_if_not_fires_on_attribute_change_with_attribute_not_below(hass, calls):
@ -553,7 +553,7 @@ async def test_if_not_fires_on_attribute_change_with_attribute_not_below(hass, c
# 11 is not below 10 # 11 is not below 10
hass.states.async_set("test.entity", "entity", {"test_attribute": 11}) hass.states.async_set("test.entity", "entity", {"test_attribute": 11})
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_not_fires_on_entity_change_with_attribute_below(hass, calls): async def test_if_not_fires_on_entity_change_with_attribute_below(hass, calls):
@ -576,7 +576,7 @@ async def test_if_not_fires_on_entity_change_with_attribute_below(hass, calls):
# 11 is not below 10, entity state value should not be tested # 11 is not below 10, entity state value should not be tested
hass.states.async_set("test.entity", "9", {"test_attribute": 11}) hass.states.async_set("test.entity", "9", {"test_attribute": 11})
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_not_fires_on_entity_change_with_not_attribute_below(hass, calls): async def test_if_not_fires_on_entity_change_with_not_attribute_below(hass, calls):
@ -599,7 +599,7 @@ async def test_if_not_fires_on_entity_change_with_not_attribute_below(hass, call
# 11 is not below 10, entity state value should not be tested # 11 is not below 10, entity state value should not be tested
hass.states.async_set("test.entity", "entity") hass.states.async_set("test.entity", "entity")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_fires_on_attr_change_with_attribute_below_and_multiple_attr(hass, calls): async def test_fires_on_attr_change_with_attribute_below_and_multiple_attr(hass, calls):
@ -624,7 +624,7 @@ async def test_fires_on_attr_change_with_attribute_below_and_multiple_attr(hass,
"test.entity", "entity", {"test_attribute": 9, "not_test_attribute": 11} "test.entity", "entity", {"test_attribute": 9, "not_test_attribute": 11}
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_template_list(hass, calls): async def test_template_list(hass, calls):
@ -647,7 +647,7 @@ async def test_template_list(hass, calls):
# 3 is below 10 # 3 is below 10
hass.states.async_set("test.entity", "entity", {"test_attribute": [11, 15, 3]}) hass.states.async_set("test.entity", "entity", {"test_attribute": [11, 15, 3]})
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_template_string(hass, calls): async def test_template_string(hass, calls):
@ -686,10 +686,10 @@ async def test_template_string(hass, calls):
await hass.async_block_till_done() await hass.async_block_till_done()
hass.states.async_set("test.entity", "test state 2", {"test_attribute": "0.9"}) hass.states.async_set("test.entity", "test state 2", {"test_attribute": "0.9"})
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert ( assert (
"numeric_state - test.entity - 10.0 - None - test state 1 - " calls[0].data["some"]
"test state 2" == calls[0].data["some"] == "numeric_state - test.entity - 10.0 - None - test state 1 - test state 2"
) )
@ -715,7 +715,7 @@ async def test_not_fires_on_attr_change_with_attr_not_below_multiple_attr(hass,
"test.entity", "entity", {"test_attribute": 11, "not_test_attribute": 9} "test.entity", "entity", {"test_attribute": 11, "not_test_attribute": 9}
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_action(hass, calls): async def test_if_action(hass, calls):
@ -742,19 +742,19 @@ async def test_if_action(hass, calls):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
hass.states.async_set(entity_id, 8) hass.states.async_set(entity_id, 8)
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
hass.states.async_set(entity_id, 9) hass.states.async_set(entity_id, 9)
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
async def test_if_fails_setup_bad_for(hass, calls): async def test_if_fails_setup_bad_for(hass, calls):
@ -826,7 +826,7 @@ async def test_if_not_fires_on_entity_change_with_for(hass, calls):
await hass.async_block_till_done() await hass.async_block_till_done()
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_not_fires_on_entities_change_with_for_after_stop(hass, calls): async def test_if_not_fires_on_entities_change_with_for_after_stop(hass, calls):
@ -853,7 +853,7 @@ async def test_if_not_fires_on_entities_change_with_for_after_stop(hass, calls):
await hass.async_block_till_done() await hass.async_block_till_done()
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
hass.states.async_set("test.entity_1", 15) hass.states.async_set("test.entity_1", 15)
hass.states.async_set("test.entity_2", 15) hass.states.async_set("test.entity_2", 15)
@ -866,7 +866,7 @@ async def test_if_not_fires_on_entities_change_with_for_after_stop(hass, calls):
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
async def test_if_fires_on_entity_change_with_for_attribute_change(hass, calls): async def test_if_fires_on_entity_change_with_for_attribute_change(hass, calls):
@ -897,11 +897,11 @@ async def test_if_fires_on_entity_change_with_for_attribute_change(hass, calls):
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
hass.states.async_set("test.entity", 9, attributes={"mock_attr": "attr_change"}) hass.states.async_set("test.entity", 9, attributes={"mock_attr": "attr_change"})
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
mock_utcnow.return_value += timedelta(seconds=4) mock_utcnow.return_value += timedelta(seconds=4)
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_entity_change_with_for(hass, calls): async def test_if_fires_on_entity_change_with_for(hass, calls):
@ -927,7 +927,7 @@ async def test_if_fires_on_entity_change_with_for(hass, calls):
await hass.async_block_till_done() await hass.async_block_till_done()
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_wait_template_with_trigger(hass, calls): async def test_wait_template_with_trigger(hass, calls):
@ -965,7 +965,7 @@ async def test_wait_template_with_trigger(hass, calls):
hass.states.async_set("test.entity", "8") hass.states.async_set("test.entity", "8")
await hass.async_block_till_done() await hass.async_block_till_done()
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert "numeric_state - test.entity - 12" == calls[0].data["some"] assert "numeric_state - test.entity - 12" == calls[0].data["some"]
@ -1000,16 +1000,16 @@ async def test_if_fires_on_entities_change_no_overlap(hass, calls):
mock_utcnow.return_value += timedelta(seconds=10) mock_utcnow.return_value += timedelta(seconds=10)
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert "test.entity_1" == calls[0].data["some"] assert calls[0].data["some"] == "test.entity_1"
hass.states.async_set("test.entity_2", 9) hass.states.async_set("test.entity_2", 9)
await hass.async_block_till_done() await hass.async_block_till_done()
mock_utcnow.return_value += timedelta(seconds=10) mock_utcnow.return_value += timedelta(seconds=10)
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
assert "test.entity_2" == calls[1].data["some"] assert calls[1].data["some"] == "test.entity_2"
async def test_if_fires_on_entities_change_overlap(hass, calls): async def test_if_fires_on_entities_change_overlap(hass, calls):
@ -1052,18 +1052,18 @@ async def test_if_fires_on_entities_change_overlap(hass, calls):
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
hass.states.async_set("test.entity_2", 9) hass.states.async_set("test.entity_2", 9)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
mock_utcnow.return_value += timedelta(seconds=3) mock_utcnow.return_value += timedelta(seconds=3)
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert "test.entity_1" == calls[0].data["some"] assert calls[0].data["some"] == "test.entity_1"
mock_utcnow.return_value += timedelta(seconds=3) mock_utcnow.return_value += timedelta(seconds=3)
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
assert "test.entity_2" == calls[1].data["some"] assert calls[1].data["some"] == "test.entity_2"
async def test_if_fires_on_change_with_for_template_1(hass, calls): async def test_if_fires_on_change_with_for_template_1(hass, calls):
@ -1087,10 +1087,10 @@ async def test_if_fires_on_change_with_for_template_1(hass, calls):
hass.states.async_set("test.entity", 9) hass.states.async_set("test.entity", 9)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_change_with_for_template_2(hass, calls): async def test_if_fires_on_change_with_for_template_2(hass, calls):
@ -1114,10 +1114,10 @@ async def test_if_fires_on_change_with_for_template_2(hass, calls):
hass.states.async_set("test.entity", 9) hass.states.async_set("test.entity", 9)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_change_with_for_template_3(hass, calls): async def test_if_fires_on_change_with_for_template_3(hass, calls):
@ -1141,10 +1141,10 @@ async def test_if_fires_on_change_with_for_template_3(hass, calls):
hass.states.async_set("test.entity", 9) hass.states.async_set("test.entity", 9)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_invalid_for_template(hass, calls): async def test_invalid_for_template(hass, calls):
@ -1215,22 +1215,22 @@ async def test_if_fires_on_entities_change_overlap_for_template(hass, calls):
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
hass.states.async_set("test.entity_2", 9) hass.states.async_set("test.entity_2", 9)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
mock_utcnow.return_value += timedelta(seconds=3) mock_utcnow.return_value += timedelta(seconds=3)
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert "test.entity_1 - 0:00:05" == calls[0].data["some"] assert calls[0].data["some"] == "test.entity_1 - 0:00:05"
mock_utcnow.return_value += timedelta(seconds=3) mock_utcnow.return_value += timedelta(seconds=3)
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
mock_utcnow.return_value += timedelta(seconds=5) mock_utcnow.return_value += timedelta(seconds=5)
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
assert "test.entity_2 - 0:00:10" == calls[1].data["some"] assert calls[1].data["some"] == "test.entity_2 - 0:00:10"
def test_below_above(): def test_below_above():

View file

@ -65,15 +65,15 @@ async def test_if_fires_on_entity_change(hass, calls):
hass.states.async_set("test.entity", "world", context=context) hass.states.async_set("test.entity", "world", context=context)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert calls[0].context.parent_id == context.id assert calls[0].context.parent_id == context.id
assert "state - test.entity - hello - world - None" == calls[0].data["some"] assert calls[0].data["some"] == "state - test.entity - hello - world - None"
await common.async_turn_off(hass) await common.async_turn_off(hass)
await hass.async_block_till_done() await hass.async_block_till_done()
hass.states.async_set("test.entity", "planet") hass.states.async_set("test.entity", "planet")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_entity_change_with_from_filter(hass, calls): async def test_if_fires_on_entity_change_with_from_filter(hass, calls):
@ -96,7 +96,7 @@ async def test_if_fires_on_entity_change_with_from_filter(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_entity_change_with_to_filter(hass, calls): async def test_if_fires_on_entity_change_with_to_filter(hass, calls):
@ -119,7 +119,7 @@ async def test_if_fires_on_entity_change_with_to_filter(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_attribute_change_with_to_filter(hass, calls): async def test_if_fires_on_attribute_change_with_to_filter(hass, calls):
@ -143,7 +143,7 @@ async def test_if_fires_on_attribute_change_with_to_filter(hass, calls):
hass.states.async_set("test.entity", "world", {"test_attribute": 11}) hass.states.async_set("test.entity", "world", {"test_attribute": 11})
hass.states.async_set("test.entity", "world", {"test_attribute": 12}) hass.states.async_set("test.entity", "world", {"test_attribute": 12})
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_entity_change_with_both_filters(hass, calls): async def test_if_fires_on_entity_change_with_both_filters(hass, calls):
@ -167,7 +167,7 @@ async def test_if_fires_on_entity_change_with_both_filters(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_not_fires_if_to_filter_not_match(hass, calls): async def test_if_not_fires_if_to_filter_not_match(hass, calls):
@ -191,7 +191,7 @@ async def test_if_not_fires_if_to_filter_not_match(hass, calls):
hass.states.async_set("test.entity", "moon") hass.states.async_set("test.entity", "moon")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_not_fires_if_from_filter_not_match(hass, calls): async def test_if_not_fires_if_from_filter_not_match(hass, calls):
@ -217,7 +217,7 @@ async def test_if_not_fires_if_from_filter_not_match(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_not_fires_if_entity_not_match(hass, calls): async def test_if_not_fires_if_entity_not_match(hass, calls):
@ -236,7 +236,7 @@ async def test_if_not_fires_if_entity_not_match(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_action(hass, calls): async def test_if_action(hass, calls):
@ -262,13 +262,13 @@ async def test_if_action(hass, calls):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
hass.states.async_set(entity_id, test_state + "something") hass.states.async_set(entity_id, test_state + "something")
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fails_setup_if_to_boolean_value(hass, calls): async def test_if_fails_setup_if_to_boolean_value(hass, calls):
@ -377,7 +377,7 @@ async def test_if_not_fires_on_entity_change_with_for(hass, calls):
await hass.async_block_till_done() await hass.async_block_till_done()
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_not_fires_on_entities_change_with_for_after_stop(hass, calls): async def test_if_not_fires_on_entities_change_with_for_after_stop(hass, calls):
@ -404,7 +404,7 @@ async def test_if_not_fires_on_entities_change_with_for_after_stop(hass, calls):
await hass.async_block_till_done() await hass.async_block_till_done()
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
hass.states.async_set("test.entity_1", "world_no") hass.states.async_set("test.entity_1", "world_no")
hass.states.async_set("test.entity_2", "world_no") hass.states.async_set("test.entity_2", "world_no")
@ -417,7 +417,7 @@ async def test_if_not_fires_on_entities_change_with_for_after_stop(hass, calls):
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
async def test_if_fires_on_entity_change_with_for_attribute_change(hass, calls): async def test_if_fires_on_entity_change_with_for_attribute_change(hass, calls):
@ -450,11 +450,11 @@ async def test_if_fires_on_entity_change_with_for_attribute_change(hass, calls):
"test.entity", "world", attributes={"mock_attr": "attr_change"} "test.entity", "world", attributes={"mock_attr": "attr_change"}
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
mock_utcnow.return_value += timedelta(seconds=4) mock_utcnow.return_value += timedelta(seconds=4)
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_entity_change_with_for_multiple_force_update(hass, calls): async def test_if_fires_on_entity_change_with_for_multiple_force_update(hass, calls):
@ -481,16 +481,16 @@ async def test_if_fires_on_entity_change_with_for_multiple_force_update(hass, ca
mock_utcnow.return_value = utcnow mock_utcnow.return_value = utcnow
hass.states.async_set("test.force_entity", "world", None, True) hass.states.async_set("test.force_entity", "world", None, True)
await hass.async_block_till_done() await hass.async_block_till_done()
for _ in range(0, 4): for _ in range(4):
mock_utcnow.return_value += timedelta(seconds=1) mock_utcnow.return_value += timedelta(seconds=1)
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
hass.states.async_set("test.force_entity", "world", None, True) hass.states.async_set("test.force_entity", "world", None, True)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
mock_utcnow.return_value += timedelta(seconds=4) mock_utcnow.return_value += timedelta(seconds=4)
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_entity_change_with_for(hass, calls): async def test_if_fires_on_entity_change_with_for(hass, calls):
@ -539,7 +539,7 @@ async def test_if_fires_on_entity_removal(hass, calls):
assert hass.states.async_remove("test.entity", context=context) assert hass.states.async_remove("test.entity", context=context)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert calls[0].context.parent_id == context.id assert calls[0].context.parent_id == context.id
@ -571,13 +571,13 @@ async def test_if_fires_on_for_condition(hass, calls):
# not enough time has passed # not enough time has passed
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
# Time travel 10 secs into the future # Time travel 10 secs into the future
mock_utcnow.return_value = point2 mock_utcnow.return_value = point2
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_for_condition_attribute_change(hass, calls): async def test_if_fires_on_for_condition_attribute_change(hass, calls):
@ -609,7 +609,7 @@ async def test_if_fires_on_for_condition_attribute_change(hass, calls):
# not enough time has passed # not enough time has passed
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
# Still not enough time has passed, but an attribute is changed # Still not enough time has passed, but an attribute is changed
mock_utcnow.return_value = point2 mock_utcnow.return_value = point2
@ -618,13 +618,13 @@ async def test_if_fires_on_for_condition_attribute_change(hass, calls):
) )
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
# Enough time has now passed # Enough time has now passed
mock_utcnow.return_value = point3 mock_utcnow.return_value = point3
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fails_setup_for_without_time(hass, calls): async def test_if_fails_setup_for_without_time(hass, calls):
@ -707,8 +707,8 @@ async def test_wait_template_with_trigger(hass, calls):
await hass.async_block_till_done() await hass.async_block_till_done()
hass.states.async_set("test.entity", "hello") hass.states.async_set("test.entity", "hello")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert "state - test.entity - hello - world" == calls[0].data["some"] assert calls[0].data["some"] == "state - test.entity - hello - world"
async def test_if_fires_on_entities_change_no_overlap(hass, calls): async def test_if_fires_on_entities_change_no_overlap(hass, calls):
@ -741,16 +741,16 @@ async def test_if_fires_on_entities_change_no_overlap(hass, calls):
mock_utcnow.return_value += timedelta(seconds=10) mock_utcnow.return_value += timedelta(seconds=10)
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert "test.entity_1" == calls[0].data["some"] assert calls[0].data["some"] == "test.entity_1"
hass.states.async_set("test.entity_2", "world") hass.states.async_set("test.entity_2", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
mock_utcnow.return_value += timedelta(seconds=10) mock_utcnow.return_value += timedelta(seconds=10)
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
assert "test.entity_2" == calls[1].data["some"] assert calls[1].data["some"] == "test.entity_2"
async def test_if_fires_on_entities_change_overlap(hass, calls): async def test_if_fires_on_entities_change_overlap(hass, calls):
@ -792,18 +792,18 @@ async def test_if_fires_on_entities_change_overlap(hass, calls):
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
hass.states.async_set("test.entity_2", "world") hass.states.async_set("test.entity_2", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
mock_utcnow.return_value += timedelta(seconds=3) mock_utcnow.return_value += timedelta(seconds=3)
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert "test.entity_1" == calls[0].data["some"] assert calls[0].data["some"] == "test.entity_1"
mock_utcnow.return_value += timedelta(seconds=3) mock_utcnow.return_value += timedelta(seconds=3)
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
assert "test.entity_2" == calls[1].data["some"] assert calls[1].data["some"] == "test.entity_2"
async def test_if_fires_on_change_with_for_template_1(hass, calls): async def test_if_fires_on_change_with_for_template_1(hass, calls):
@ -826,10 +826,10 @@ async def test_if_fires_on_change_with_for_template_1(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_change_with_for_template_2(hass, calls): async def test_if_fires_on_change_with_for_template_2(hass, calls):
@ -852,10 +852,10 @@ async def test_if_fires_on_change_with_for_template_2(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_change_with_for_template_3(hass, calls): async def test_if_fires_on_change_with_for_template_3(hass, calls):
@ -878,10 +878,10 @@ async def test_if_fires_on_change_with_for_template_3(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_invalid_for_template_1(hass, calls): async def test_invalid_for_template_1(hass, calls):
@ -950,19 +950,19 @@ async def test_if_fires_on_entities_change_overlap_for_template(hass, calls):
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
hass.states.async_set("test.entity_2", "world") hass.states.async_set("test.entity_2", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
mock_utcnow.return_value += timedelta(seconds=3) mock_utcnow.return_value += timedelta(seconds=3)
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert "test.entity_1 - 0:00:05" == calls[0].data["some"] assert calls[0].data["some"] == "test.entity_1 - 0:00:05"
mock_utcnow.return_value += timedelta(seconds=3) mock_utcnow.return_value += timedelta(seconds=3)
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
mock_utcnow.return_value += timedelta(seconds=5) mock_utcnow.return_value += timedelta(seconds=5)
async_fire_time_changed(hass, mock_utcnow.return_value) async_fire_time_changed(hass, mock_utcnow.return_value)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
assert "test.entity_2 - 0:00:10" == calls[1].data["some"] assert calls[1].data["some"] == "test.entity_2 - 0:00:10"

View file

@ -59,7 +59,7 @@ async def test_sunset_trigger(hass, calls):
async_fire_time_changed(hass, trigger_time) async_fire_time_changed(hass, trigger_time)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
await common.async_turn_on(hass) await common.async_turn_on(hass)
@ -67,7 +67,7 @@ async def test_sunset_trigger(hass, calls):
async_fire_time_changed(hass, trigger_time) async_fire_time_changed(hass, trigger_time)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_sunrise_trigger(hass, calls): async def test_sunrise_trigger(hass, calls):
@ -89,7 +89,7 @@ async def test_sunrise_trigger(hass, calls):
async_fire_time_changed(hass, trigger_time) async_fire_time_changed(hass, trigger_time)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_sunset_trigger_with_offset(hass, calls): async def test_sunset_trigger_with_offset(hass, calls):
@ -121,8 +121,8 @@ async def test_sunset_trigger_with_offset(hass, calls):
async_fire_time_changed(hass, trigger_time) async_fire_time_changed(hass, trigger_time)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert "sun - sunset - 0:30:00" == calls[0].data["some"] assert calls[0].data["some"] == "sun - sunset - 0:30:00"
async def test_sunrise_trigger_with_offset(hass, calls): async def test_sunrise_trigger_with_offset(hass, calls):
@ -148,7 +148,7 @@ async def test_sunrise_trigger_with_offset(hass, calls):
async_fire_time_changed(hass, trigger_time) async_fire_time_changed(hass, trigger_time)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_action_before_sunrise_no_offset(hass, calls): async def test_if_action_before_sunrise_no_offset(hass, calls):
@ -176,28 +176,28 @@ async def test_if_action_before_sunrise_no_offset(hass, calls):
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
# now = sunrise -> 'before sunrise' true # now = sunrise -> 'before sunrise' true
now = datetime(2015, 9, 16, 13, 32, 43, tzinfo=dt_util.UTC) now = datetime(2015, 9, 16, 13, 32, 43, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# now = local midnight -> 'before sunrise' true # now = local midnight -> 'before sunrise' true
now = datetime(2015, 9, 16, 7, 0, 0, tzinfo=dt_util.UTC) now = datetime(2015, 9, 16, 7, 0, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
# now = local midnight - 1s -> 'before sunrise' not true # now = local midnight - 1s -> 'before sunrise' not true
now = datetime(2015, 9, 17, 6, 59, 59, tzinfo=dt_util.UTC) now = datetime(2015, 9, 17, 6, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
async def test_if_action_after_sunrise_no_offset(hass, calls): async def test_if_action_after_sunrise_no_offset(hass, calls):
@ -225,28 +225,28 @@ async def test_if_action_after_sunrise_no_offset(hass, calls):
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
# now = sunrise + 1s -> 'after sunrise' true # now = sunrise + 1s -> 'after sunrise' true
now = datetime(2015, 9, 16, 13, 32, 43, tzinfo=dt_util.UTC) now = datetime(2015, 9, 16, 13, 32, 43, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# now = local midnight -> 'after sunrise' not true # now = local midnight -> 'after sunrise' not true
now = datetime(2015, 9, 16, 7, 0, 0, tzinfo=dt_util.UTC) now = datetime(2015, 9, 16, 7, 0, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# now = local midnight - 1s -> 'after sunrise' true # now = local midnight - 1s -> 'after sunrise' true
now = datetime(2015, 9, 17, 6, 59, 59, tzinfo=dt_util.UTC) now = datetime(2015, 9, 17, 6, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
async def test_if_action_before_sunrise_with_offset(hass, calls): async def test_if_action_before_sunrise_with_offset(hass, calls):
@ -278,56 +278,56 @@ async def test_if_action_before_sunrise_with_offset(hass, calls):
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
# now = sunrise + 1h -> 'before sunrise' with offset +1h true # now = sunrise + 1h -> 'before sunrise' with offset +1h true
now = datetime(2015, 9, 16, 14, 32, 43, tzinfo=dt_util.UTC) now = datetime(2015, 9, 16, 14, 32, 43, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# now = UTC midnight -> 'before sunrise' with offset +1h not true # now = UTC midnight -> 'before sunrise' with offset +1h not true
now = datetime(2015, 9, 17, 0, 0, 0, tzinfo=dt_util.UTC) now = datetime(2015, 9, 17, 0, 0, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# now = UTC midnight - 1s -> 'before sunrise' with offset +1h not true # now = UTC midnight - 1s -> 'before sunrise' with offset +1h not true
now = datetime(2015, 9, 16, 23, 59, 59, tzinfo=dt_util.UTC) now = datetime(2015, 9, 16, 23, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# now = local midnight -> 'before sunrise' with offset +1h true # now = local midnight -> 'before sunrise' with offset +1h true
now = datetime(2015, 9, 16, 7, 0, 0, tzinfo=dt_util.UTC) now = datetime(2015, 9, 16, 7, 0, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
# now = local midnight - 1s -> 'before sunrise' with offset +1h not true # now = local midnight - 1s -> 'before sunrise' with offset +1h not true
now = datetime(2015, 9, 17, 6, 59, 59, tzinfo=dt_util.UTC) now = datetime(2015, 9, 17, 6, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
# now = sunset -> 'before sunrise' with offset +1h not true # now = sunset -> 'before sunrise' with offset +1h not true
now = datetime(2015, 9, 17, 1, 56, 48, tzinfo=dt_util.UTC) now = datetime(2015, 9, 17, 1, 56, 48, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
# now = sunset -1s -> 'before sunrise' with offset +1h not true # now = sunset -1s -> 'before sunrise' with offset +1h not true
now = datetime(2015, 9, 17, 1, 56, 45, tzinfo=dt_util.UTC) now = datetime(2015, 9, 17, 1, 56, 45, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
async def test_if_action_before_sunset_with_offset(hass, calls): async def test_if_action_before_sunset_with_offset(hass, calls):
@ -359,56 +359,56 @@ async def test_if_action_before_sunset_with_offset(hass, calls):
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# now = sunset + 1s + 1h -> 'before sunset' with offset +1h not true # now = sunset + 1s + 1h -> 'before sunset' with offset +1h not true
now = datetime(2015, 9, 17, 2, 55, 25, tzinfo=dt_util.UTC) now = datetime(2015, 9, 17, 2, 55, 25, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# now = sunset + 1h -> 'before sunset' with offset +1h true # now = sunset + 1h -> 'before sunset' with offset +1h true
now = datetime(2015, 9, 17, 2, 55, 24, tzinfo=dt_util.UTC) now = datetime(2015, 9, 17, 2, 55, 24, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
# now = UTC midnight -> 'before sunset' with offset +1h true # now = UTC midnight -> 'before sunset' with offset +1h true
now = datetime(2015, 9, 17, 0, 0, 0, tzinfo=dt_util.UTC) now = datetime(2015, 9, 17, 0, 0, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 3 == len(calls) assert len(calls) == 3
# now = UTC midnight - 1s -> 'before sunset' with offset +1h true # now = UTC midnight - 1s -> 'before sunset' with offset +1h true
now = datetime(2015, 9, 16, 23, 59, 59, tzinfo=dt_util.UTC) now = datetime(2015, 9, 16, 23, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 4 == len(calls) assert len(calls) == 4
# now = sunrise -> 'before sunset' with offset +1h true # now = sunrise -> 'before sunset' with offset +1h true
now = datetime(2015, 9, 16, 13, 32, 43, tzinfo=dt_util.UTC) now = datetime(2015, 9, 16, 13, 32, 43, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 5 == len(calls) assert len(calls) == 5
# now = sunrise -1s -> 'before sunset' with offset +1h true # now = sunrise -1s -> 'before sunset' with offset +1h true
now = datetime(2015, 9, 16, 13, 32, 42, tzinfo=dt_util.UTC) now = datetime(2015, 9, 16, 13, 32, 42, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 6 == len(calls) assert len(calls) == 6
# now = local midnight-1s -> 'after sunrise' with offset +1h not true # now = local midnight-1s -> 'after sunrise' with offset +1h not true
now = datetime(2015, 9, 17, 6, 59, 59, tzinfo=dt_util.UTC) now = datetime(2015, 9, 17, 6, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 6 == len(calls) assert len(calls) == 6
async def test_if_action_after_sunrise_with_offset(hass, calls): async def test_if_action_after_sunrise_with_offset(hass, calls):
@ -440,70 +440,70 @@ async def test_if_action_after_sunrise_with_offset(hass, calls):
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
# now = sunrise + 1h -> 'after sunrise' with offset +1h true # now = sunrise + 1h -> 'after sunrise' with offset +1h true
now = datetime(2015, 9, 16, 14, 32, 43, tzinfo=dt_util.UTC) now = datetime(2015, 9, 16, 14, 32, 43, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# now = UTC noon -> 'after sunrise' with offset +1h not true # now = UTC noon -> 'after sunrise' with offset +1h not true
now = datetime(2015, 9, 16, 12, 0, 0, tzinfo=dt_util.UTC) now = datetime(2015, 9, 16, 12, 0, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# now = UTC noon - 1s -> 'after sunrise' with offset +1h not true # now = UTC noon - 1s -> 'after sunrise' with offset +1h not true
now = datetime(2015, 9, 16, 11, 59, 59, tzinfo=dt_util.UTC) now = datetime(2015, 9, 16, 11, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# now = local noon -> 'after sunrise' with offset +1h true # now = local noon -> 'after sunrise' with offset +1h true
now = datetime(2015, 9, 16, 19, 1, 0, tzinfo=dt_util.UTC) now = datetime(2015, 9, 16, 19, 1, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
# now = local noon - 1s -> 'after sunrise' with offset +1h true # now = local noon - 1s -> 'after sunrise' with offset +1h true
now = datetime(2015, 9, 16, 18, 59, 59, tzinfo=dt_util.UTC) now = datetime(2015, 9, 16, 18, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 3 == len(calls) assert len(calls) == 3
# now = sunset -> 'after sunrise' with offset +1h true # now = sunset -> 'after sunrise' with offset +1h true
now = datetime(2015, 9, 17, 1, 55, 24, tzinfo=dt_util.UTC) now = datetime(2015, 9, 17, 1, 55, 24, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 4 == len(calls) assert len(calls) == 4
# now = sunset + 1s -> 'after sunrise' with offset +1h true # now = sunset + 1s -> 'after sunrise' with offset +1h true
now = datetime(2015, 9, 17, 1, 55, 25, tzinfo=dt_util.UTC) now = datetime(2015, 9, 17, 1, 55, 25, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 5 == len(calls) assert len(calls) == 5
# now = local midnight-1s -> 'after sunrise' with offset +1h true # now = local midnight-1s -> 'after sunrise' with offset +1h true
now = datetime(2015, 9, 17, 6, 59, 59, tzinfo=dt_util.UTC) now = datetime(2015, 9, 17, 6, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 6 == len(calls) assert len(calls) == 6
# now = local midnight -> 'after sunrise' with offset +1h not true # now = local midnight -> 'after sunrise' with offset +1h not true
now = datetime(2015, 9, 17, 7, 0, 0, tzinfo=dt_util.UTC) now = datetime(2015, 9, 17, 7, 0, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 6 == len(calls) assert len(calls) == 6
async def test_if_action_after_sunset_with_offset(hass, calls): async def test_if_action_after_sunset_with_offset(hass, calls):
@ -535,28 +535,28 @@ async def test_if_action_after_sunset_with_offset(hass, calls):
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
# now = sunset + 1h -> 'after sunset' with offset +1h true # now = sunset + 1h -> 'after sunset' with offset +1h true
now = datetime(2015, 9, 16, 2, 56, 46, tzinfo=dt_util.UTC) now = datetime(2015, 9, 16, 2, 56, 46, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# now = midnight-1s -> 'after sunset' with offset +1h true # now = midnight-1s -> 'after sunset' with offset +1h true
now = datetime(2015, 9, 16, 6, 59, 59, tzinfo=dt_util.UTC) now = datetime(2015, 9, 16, 6, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
# now = midnight -> 'after sunset' with offset +1h not true # now = midnight -> 'after sunset' with offset +1h not true
now = datetime(2015, 9, 16, 7, 0, 0, tzinfo=dt_util.UTC) now = datetime(2015, 9, 16, 7, 0, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
async def test_if_action_before_and_after_during(hass, calls): async def test_if_action_before_and_after_during(hass, calls):
@ -588,35 +588,35 @@ async def test_if_action_before_and_after_during(hass, calls):
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
# now = sunset + 1s -> 'after sunrise' + 'before sunset' not true # now = sunset + 1s -> 'after sunrise' + 'before sunset' not true
now = datetime(2015, 9, 17, 1, 55, 25, tzinfo=dt_util.UTC) now = datetime(2015, 9, 17, 1, 55, 25, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
# now = sunrise -> 'after sunrise' + 'before sunset' true # now = sunrise -> 'after sunrise' + 'before sunset' true
now = datetime(2015, 9, 16, 13, 32, 43, tzinfo=dt_util.UTC) now = datetime(2015, 9, 16, 13, 32, 43, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# now = sunset -> 'after sunrise' + 'before sunset' true # now = sunset -> 'after sunrise' + 'before sunset' true
now = datetime(2015, 9, 17, 1, 55, 24, tzinfo=dt_util.UTC) now = datetime(2015, 9, 17, 1, 55, 24, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
# now = 9AM local -> 'after sunrise' + 'before sunset' true # now = 9AM local -> 'after sunrise' + 'before sunset' true
now = datetime(2015, 9, 16, 16, tzinfo=dt_util.UTC) now = datetime(2015, 9, 16, 16, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 3 == len(calls) assert len(calls) == 3
async def test_if_action_before_sunrise_no_offset_kotzebue(hass, calls): async def test_if_action_before_sunrise_no_offset_kotzebue(hass, calls):
@ -651,28 +651,28 @@ async def test_if_action_before_sunrise_no_offset_kotzebue(hass, calls):
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
# now = sunrise -> 'before sunrise' true # now = sunrise -> 'before sunrise' true
now = datetime(2015, 7, 24, 15, 17, 24, tzinfo=dt_util.UTC) now = datetime(2015, 7, 24, 15, 17, 24, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# now = local midnight -> 'before sunrise' true # now = local midnight -> 'before sunrise' true
now = datetime(2015, 7, 24, 8, 0, 0, tzinfo=dt_util.UTC) now = datetime(2015, 7, 24, 8, 0, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
# now = local midnight - 1s -> 'before sunrise' not true # now = local midnight - 1s -> 'before sunrise' not true
now = datetime(2015, 7, 24, 7, 59, 59, tzinfo=dt_util.UTC) now = datetime(2015, 7, 24, 7, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
async def test_if_action_after_sunrise_no_offset_kotzebue(hass, calls): async def test_if_action_after_sunrise_no_offset_kotzebue(hass, calls):
@ -707,28 +707,28 @@ async def test_if_action_after_sunrise_no_offset_kotzebue(hass, calls):
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# now = sunrise - 1s -> 'after sunrise' not true # now = sunrise - 1s -> 'after sunrise' not true
now = datetime(2015, 7, 24, 15, 17, 23, tzinfo=dt_util.UTC) now = datetime(2015, 7, 24, 15, 17, 23, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# now = local midnight -> 'after sunrise' not true # now = local midnight -> 'after sunrise' not true
now = datetime(2015, 7, 24, 8, 0, 1, tzinfo=dt_util.UTC) now = datetime(2015, 7, 24, 8, 0, 1, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# now = local midnight - 1s -> 'after sunrise' true # now = local midnight - 1s -> 'after sunrise' true
now = datetime(2015, 7, 24, 7, 59, 59, tzinfo=dt_util.UTC) now = datetime(2015, 7, 24, 7, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
async def test_if_action_before_sunset_no_offset_kotzebue(hass, calls): async def test_if_action_before_sunset_no_offset_kotzebue(hass, calls):
@ -763,28 +763,28 @@ async def test_if_action_before_sunset_no_offset_kotzebue(hass, calls):
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
# now = sunrise -> 'before sunrise' true # now = sunrise -> 'before sunrise' true
now = datetime(2015, 7, 25, 11, 16, 27, tzinfo=dt_util.UTC) now = datetime(2015, 7, 25, 11, 16, 27, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# now = local midnight -> 'before sunrise' true # now = local midnight -> 'before sunrise' true
now = datetime(2015, 7, 24, 8, 0, 0, tzinfo=dt_util.UTC) now = datetime(2015, 7, 24, 8, 0, 0, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
# now = local midnight - 1s -> 'before sunrise' not true # now = local midnight - 1s -> 'before sunrise' not true
now = datetime(2015, 7, 24, 7, 59, 59, tzinfo=dt_util.UTC) now = datetime(2015, 7, 24, 7, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
async def test_if_action_after_sunset_no_offset_kotzebue(hass, calls): async def test_if_action_after_sunset_no_offset_kotzebue(hass, calls):
@ -819,25 +819,25 @@ async def test_if_action_after_sunset_no_offset_kotzebue(hass, calls):
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# now = sunset - 1s -> 'after sunset' not true # now = sunset - 1s -> 'after sunset' not true
now = datetime(2015, 7, 25, 11, 16, 26, tzinfo=dt_util.UTC) now = datetime(2015, 7, 25, 11, 16, 26, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# now = local midnight -> 'after sunset' not true # now = local midnight -> 'after sunset' not true
now = datetime(2015, 7, 24, 8, 0, 1, tzinfo=dt_util.UTC) now = datetime(2015, 7, 24, 8, 0, 1, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# now = local midnight - 1s -> 'after sunset' true # now = local midnight - 1s -> 'after sunset' true
now = datetime(2015, 7, 24, 7, 59, 59, tzinfo=dt_util.UTC) now = datetime(2015, 7, 24, 7, 59, 59, tzinfo=dt_util.UTC)
with patch("homeassistant.util.dt.utcnow", return_value=now): with patch("homeassistant.util.dt.utcnow", return_value=now):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2

View file

@ -46,14 +46,14 @@ async def test_if_fires_on_change_bool(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
await common.async_turn_off(hass) await common.async_turn_off(hass)
await hass.async_block_till_done() await hass.async_block_till_done()
hass.states.async_set("test.entity", "planet") hass.states.async_set("test.entity", "planet")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_change_str(hass, calls): async def test_if_fires_on_change_str(hass, calls):
@ -71,7 +71,7 @@ async def test_if_fires_on_change_str(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_change_str_crazy(hass, calls): async def test_if_fires_on_change_str_crazy(hass, calls):
@ -89,7 +89,7 @@ async def test_if_fires_on_change_str_crazy(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_not_fires_on_change_bool(hass, calls): async def test_if_not_fires_on_change_bool(hass, calls):
@ -107,7 +107,7 @@ async def test_if_not_fires_on_change_bool(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_not_fires_on_change_str(hass, calls): async def test_if_not_fires_on_change_str(hass, calls):
@ -125,7 +125,7 @@ async def test_if_not_fires_on_change_str(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_not_fires_on_change_str_crazy(hass, calls): async def test_if_not_fires_on_change_str_crazy(hass, calls):
@ -146,7 +146,7 @@ async def test_if_not_fires_on_change_str_crazy(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_fires_on_no_change(hass, calls): async def test_if_fires_on_no_change(hass, calls):
@ -186,12 +186,12 @@ async def test_if_fires_on_two_change(hass, calls):
# Trigger once # Trigger once
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
# Trigger again # Trigger again
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_change_with_template(hass, calls): async def test_if_fires_on_change_with_template(hass, calls):
@ -212,7 +212,7 @@ async def test_if_fires_on_change_with_template(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_not_fires_on_change_with_template(hass, calls): async def test_if_not_fires_on_change_with_template(hass, calls):
@ -273,7 +273,7 @@ async def test_if_fires_on_change_with_template_advanced(hass, calls):
hass.states.async_set("test.entity", "world", context=context) hass.states.async_set("test.entity", "world", context=context)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert calls[0].context.parent_id == context.id assert calls[0].context.parent_id == context.id
assert "template - test.entity - hello - world - None" == calls[0].data["some"] assert "template - test.entity - hello - world - None" == calls[0].data["some"]
@ -301,12 +301,12 @@ async def test_if_fires_on_no_change_with_template_advanced(hass, calls):
# Different state # Different state
hass.states.async_set("test.entity", "worldz") hass.states.async_set("test.entity", "worldz")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
# Different state # Different state
hass.states.async_set("test.entity", "hello") hass.states.async_set("test.entity", "hello")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_fires_on_change_with_template_2(hass, calls): async def test_if_fires_on_change_with_template_2(hass, calls):
@ -374,17 +374,17 @@ async def test_if_action(hass, calls):
# Condition is not true yet # Condition is not true yet
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
# Change condition to true, but it shouldn't be triggered yet # Change condition to true, but it shouldn't be triggered yet
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
# Condition is true and event is triggered # Condition is true and event is triggered
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_change_with_bad_template(hass, calls): async def test_if_fires_on_change_with_bad_template(hass, calls):
@ -420,7 +420,7 @@ async def test_if_fires_on_change_with_bad_template_2(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_wait_template_with_trigger(hass, calls): async def test_wait_template_with_trigger(hass, calls):
@ -462,8 +462,8 @@ async def test_wait_template_with_trigger(hass, calls):
await hass.async_block_till_done() await hass.async_block_till_done()
hass.states.async_set("test.entity", "hello") hass.states.async_set("test.entity", "hello")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert "template - test.entity - hello - world - None" == calls[0].data["some"] assert calls[0].data["some"] == "template - test.entity - hello - world - None"
async def test_if_fires_on_change_with_for(hass, calls): async def test_if_fires_on_change_with_for(hass, calls):
@ -485,10 +485,10 @@ async def test_if_fires_on_change_with_for(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_change_with_for_advanced(hass, calls): async def test_if_fires_on_change_with_for_advanced(hass, calls):
@ -527,10 +527,10 @@ async def test_if_fires_on_change_with_for_advanced(hass, calls):
hass.states.async_set("test.entity", "world", context=context) hass.states.async_set("test.entity", "world", context=context)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert calls[0].context.parent_id == context.id assert calls[0].context.parent_id == context.id
assert "template - test.entity - hello - world - 0:00:05" == calls[0].data["some"] assert "template - test.entity - hello - world - 0:00:05" == calls[0].data["some"]
@ -554,7 +554,7 @@ async def test_if_fires_on_change_with_for_0(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_change_with_for_0_advanced(hass, calls): async def test_if_fires_on_change_with_for_0_advanced(hass, calls):
@ -593,9 +593,9 @@ async def test_if_fires_on_change_with_for_0_advanced(hass, calls):
hass.states.async_set("test.entity", "world", context=context) hass.states.async_set("test.entity", "world", context=context)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert calls[0].context.parent_id == context.id assert calls[0].context.parent_id == context.id
assert "template - test.entity - hello - world - 0:00:00" == calls[0].data["some"] assert calls[0].data["some"] == "template - test.entity - hello - world - 0:00:00"
async def test_if_fires_on_change_with_for_2(hass, calls): async def test_if_fires_on_change_with_for_2(hass, calls):
@ -617,10 +617,10 @@ async def test_if_fires_on_change_with_for_2(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_not_fires_on_change_with_for(hass, calls): async def test_if_not_fires_on_change_with_for(hass, calls):
@ -642,16 +642,16 @@ async def test_if_not_fires_on_change_with_for(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=4)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=4))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
hass.states.async_set("test.entity", "hello") hass.states.async_set("test.entity", "hello")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=6)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=6))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_not_fires_when_turned_off_with_for(hass, calls): async def test_if_not_fires_when_turned_off_with_for(hass, calls):
@ -673,16 +673,16 @@ async def test_if_not_fires_when_turned_off_with_for(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=4)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=4))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
await common.async_turn_off(hass) await common.async_turn_off(hass)
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=6)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=6))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_fires_on_change_with_for_template_1(hass, calls): async def test_if_fires_on_change_with_for_template_1(hass, calls):
@ -704,10 +704,10 @@ async def test_if_fires_on_change_with_for_template_1(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_change_with_for_template_2(hass, calls): async def test_if_fires_on_change_with_for_template_2(hass, calls):
@ -729,10 +729,10 @@ async def test_if_fires_on_change_with_for_template_2(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_on_change_with_for_template_3(hass, calls): async def test_if_fires_on_change_with_for_template_3(hass, calls):
@ -754,10 +754,10 @@ async def test_if_fires_on_change_with_for_template_3(hass, calls):
hass.states.async_set("test.entity", "world") hass.states.async_set("test.entity", "world")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10)) async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_invalid_for_template_1(hass, calls): async def test_invalid_for_template_1(hass, calls):

View file

@ -49,8 +49,8 @@ async def test_if_fires_using_at(hass, calls):
async_fire_time_changed(hass, dt_util.utcnow().replace(hour=5, minute=0, second=0)) async_fire_time_changed(hass, dt_util.utcnow().replace(hour=5, minute=0, second=0))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert "time - 5" == calls[0].data["some"] assert calls[0].data["some"] == "time - 5"
async def test_if_not_fires_using_wrong_at(hass, calls): async def test_if_not_fires_using_wrong_at(hass, calls):
@ -77,7 +77,7 @@ async def test_if_not_fires_using_wrong_at(hass, calls):
async_fire_time_changed(hass, dt_util.utcnow().replace(hour=1, minute=0, second=5)) async_fire_time_changed(hass, dt_util.utcnow().replace(hour=1, minute=0, second=5))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_action_before(hass, calls): async def test_if_action_before(hass, calls):
@ -101,13 +101,13 @@ async def test_if_action_before(hass, calls):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
with patch("homeassistant.helpers.condition.dt_util.now", return_value=after_10): with patch("homeassistant.helpers.condition.dt_util.now", return_value=after_10):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_action_after(hass, calls): async def test_if_action_after(hass, calls):
@ -131,13 +131,13 @@ async def test_if_action_after(hass, calls):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
with patch("homeassistant.helpers.condition.dt_util.now", return_value=after_10): with patch("homeassistant.helpers.condition.dt_util.now", return_value=after_10):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_action_one_weekday(hass, calls): async def test_if_action_one_weekday(hass, calls):
@ -162,13 +162,13 @@ async def test_if_action_one_weekday(hass, calls):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
with patch("homeassistant.helpers.condition.dt_util.now", return_value=tuesday): with patch("homeassistant.helpers.condition.dt_util.now", return_value=tuesday):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_action_list_weekday(hass, calls): async def test_if_action_list_weekday(hass, calls):
@ -194,16 +194,16 @@ async def test_if_action_list_weekday(hass, calls):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
with patch("homeassistant.helpers.condition.dt_util.now", return_value=tuesday): with patch("homeassistant.helpers.condition.dt_util.now", return_value=tuesday):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2
with patch("homeassistant.helpers.condition.dt_util.now", return_value=wednesday): with patch("homeassistant.helpers.condition.dt_util.now", return_value=wednesday):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2

View file

@ -41,14 +41,14 @@ async def test_if_fires_when_hour_matches(hass, calls):
async_fire_time_changed(hass, dt_util.utcnow().replace(hour=0)) async_fire_time_changed(hass, dt_util.utcnow().replace(hour=0))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
await common.async_turn_off(hass) await common.async_turn_off(hass)
await hass.async_block_till_done() await hass.async_block_till_done()
async_fire_time_changed(hass, dt_util.utcnow().replace(hour=0)) async_fire_time_changed(hass, dt_util.utcnow().replace(hour=0))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_when_minute_matches(hass, calls): async def test_if_fires_when_minute_matches(hass, calls):
@ -72,7 +72,7 @@ async def test_if_fires_when_minute_matches(hass, calls):
async_fire_time_changed(hass, dt_util.utcnow().replace(minute=0)) async_fire_time_changed(hass, dt_util.utcnow().replace(minute=0))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_when_second_matches(hass, calls): async def test_if_fires_when_second_matches(hass, calls):
@ -96,7 +96,7 @@ async def test_if_fires_when_second_matches(hass, calls):
async_fire_time_changed(hass, dt_util.utcnow().replace(second=0)) async_fire_time_changed(hass, dt_util.utcnow().replace(second=0))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_when_all_matches(hass, calls): async def test_if_fires_when_all_matches(hass, calls):
@ -120,7 +120,7 @@ async def test_if_fires_when_all_matches(hass, calls):
async_fire_time_changed(hass, dt_util.utcnow().replace(hour=1, minute=2, second=3)) async_fire_time_changed(hass, dt_util.utcnow().replace(hour=1, minute=2, second=3))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_periodic_seconds(hass, calls): async def test_if_fires_periodic_seconds(hass, calls):
@ -144,7 +144,7 @@ async def test_if_fires_periodic_seconds(hass, calls):
async_fire_time_changed(hass, dt_util.utcnow().replace(hour=0, minute=0, second=2)) async_fire_time_changed(hass, dt_util.utcnow().replace(hour=0, minute=0, second=2))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_periodic_minutes(hass, calls): async def test_if_fires_periodic_minutes(hass, calls):
@ -168,7 +168,7 @@ async def test_if_fires_periodic_minutes(hass, calls):
async_fire_time_changed(hass, dt_util.utcnow().replace(hour=0, minute=2, second=0)) async_fire_time_changed(hass, dt_util.utcnow().replace(hour=0, minute=2, second=0))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_fires_periodic_hours(hass, calls): async def test_if_fires_periodic_hours(hass, calls):
@ -192,7 +192,7 @@ async def test_if_fires_periodic_hours(hass, calls):
async_fire_time_changed(hass, dt_util.utcnow().replace(hour=2, minute=0, second=0)) async_fire_time_changed(hass, dt_util.utcnow().replace(hour=2, minute=0, second=0))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_default_values(hass, calls): async def test_default_values(hass, calls):
@ -211,14 +211,14 @@ async def test_default_values(hass, calls):
async_fire_time_changed(hass, dt_util.utcnow().replace(hour=1, minute=2, second=0)) async_fire_time_changed(hass, dt_util.utcnow().replace(hour=1, minute=2, second=0))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async_fire_time_changed(hass, dt_util.utcnow().replace(hour=1, minute=2, second=1)) async_fire_time_changed(hass, dt_util.utcnow().replace(hour=1, minute=2, second=1))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async_fire_time_changed(hass, dt_util.utcnow().replace(hour=2, minute=2, second=0)) async_fire_time_changed(hass, dt_util.utcnow().replace(hour=2, minute=2, second=0))
await hass.async_block_till_done() await hass.async_block_till_done()
assert 2 == len(calls) assert len(calls) == 2

View file

@ -81,7 +81,7 @@ async def test_if_fires_on_zone_enter(hass, calls):
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
assert calls[0].context.parent_id == context.id assert calls[0].context.parent_id == context.id
assert "zone - test.entity - hello - hello - test" == calls[0].data["some"] assert "zone - test.entity - hello - hello - test" == calls[0].data["some"]
@ -99,7 +99,7 @@ async def test_if_fires_on_zone_enter(hass, calls):
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_not_fires_for_enter_on_zone_leave(hass, calls): async def test_if_not_fires_for_enter_on_zone_leave(hass, calls):
@ -130,7 +130,7 @@ async def test_if_not_fires_for_enter_on_zone_leave(hass, calls):
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_if_fires_on_zone_leave(hass, calls): async def test_if_fires_on_zone_leave(hass, calls):
@ -161,7 +161,7 @@ async def test_if_fires_on_zone_leave(hass, calls):
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1
async def test_if_not_fires_for_leave_on_zone_enter(hass, calls): async def test_if_not_fires_for_leave_on_zone_enter(hass, calls):
@ -192,7 +192,7 @@ async def test_if_not_fires_for_leave_on_zone_enter(hass, calls):
) )
await hass.async_block_till_done() await hass.async_block_till_done()
assert 0 == len(calls) assert len(calls) == 0
async def test_zone_condition(hass, calls): async def test_zone_condition(hass, calls):
@ -220,4 +220,4 @@ async def test_zone_condition(hass, calls):
hass.bus.async_fire("test_event") hass.bus.async_fire("test_event")
await hass.async_block_till_done() await hass.async_block_till_done()
assert 1 == len(calls) assert len(calls) == 1