本文整理汇总了Python中tests.common.async_fire_time_changed函数的典型用法代码示例。如果您正苦于以下问题:Python async_fire_time_changed函数的具体用法?Python async_fire_time_changed怎么用?Python async_fire_time_changed使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了async_fire_time_changed函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_trigger_with_specific_trigger_time
async def test_trigger_with_specific_trigger_time(hass):
"""Test disarm after trigger."""
assert await async_setup_component(
hass, alarm_control_panel.DOMAIN,
{'alarm_control_panel': {
'platform': 'manual',
'name': 'test',
'disarmed': {
'trigger_time': 5
},
'pending_time': 0,
'disarm_after_trigger': True
}})
entity_id = 'alarm_control_panel.test'
assert STATE_ALARM_DISARMED == \
hass.states.get(entity_id).state
common.async_alarm_trigger(hass, entity_id=entity_id)
await hass.async_block_till_done()
assert STATE_ALARM_TRIGGERED == \
hass.states.get(entity_id).state
future = dt_util.utcnow() + timedelta(seconds=5)
with patch(('homeassistant.components.manual.alarm_control_panel.'
'dt_util.utcnow'), return_value=future):
async_fire_time_changed(hass, future)
await hass.async_block_till_done()
assert STATE_ALARM_DISARMED == \
hass.states.get(entity_id).state
示例2: test_trigger_no_pending
async def test_trigger_no_pending(hass):
"""Test triggering when no pending submitted method."""
assert await async_setup_component(
hass, alarm_control_panel.DOMAIN,
{'alarm_control_panel': {
'platform': 'manual',
'name': 'test',
'trigger_time': 1,
'disarm_after_trigger': False
}})
entity_id = 'alarm_control_panel.test'
assert STATE_ALARM_DISARMED == \
hass.states.get(entity_id).state
common.async_alarm_trigger(hass, entity_id=entity_id)
await hass.async_block_till_done()
assert STATE_ALARM_PENDING == \
hass.states.get(entity_id).state
future = dt_util.utcnow() + timedelta(seconds=60)
with patch(('homeassistant.components.manual.alarm_control_panel.'
'dt_util.utcnow'), return_value=future):
async_fire_time_changed(hass, future)
await hass.async_block_till_done()
assert STATE_ALARM_TRIGGERED == \
hass.states.get(entity_id).state
示例3: test_stop_covers
async def test_stop_covers(hass, setup_comp):
"""Test stop cover function."""
await hass.services.async_call(
DOMAIN, SERVICE_OPEN_COVER,
{ATTR_ENTITY_ID: COVER_GROUP}, blocking=True)
future = dt_util.utcnow() + timedelta(seconds=1)
async_fire_time_changed(hass, future)
await hass.async_block_till_done()
await hass.services.async_call(
DOMAIN, SERVICE_STOP_COVER,
{ATTR_ENTITY_ID: COVER_GROUP}, blocking=True)
future = dt_util.utcnow() + timedelta(seconds=1)
async_fire_time_changed(hass, future)
await hass.async_block_till_done()
state = hass.states.get(COVER_GROUP)
assert state.state == STATE_OPEN
assert state.attributes.get(ATTR_CURRENT_POSITION) == 100
assert hass.states.get(DEMO_COVER).state == STATE_OPEN
assert hass.states.get(DEMO_COVER_POS) \
.attributes.get(ATTR_CURRENT_POSITION) == 20
assert hass.states.get(DEMO_COVER_TILT) \
.attributes.get(ATTR_CURRENT_POSITION) == 80
示例4: test_reset_switch
async def test_reset_switch(hass, hk_driver, entity_id, attrs, events):
"""Test if switch accessory is reset correctly."""
domain = split_entity_id(entity_id)[0]
hass.states.async_set(entity_id, None, attrs)
await hass.async_block_till_done()
acc = Switch(hass, hk_driver, 'Switch', entity_id, 2, None)
await hass.async_add_job(acc.run)
await hass.async_block_till_done()
assert acc.activate_only is True
assert acc.char_on.value is False
call_turn_on = async_mock_service(hass, domain, 'turn_on')
call_turn_off = async_mock_service(hass, domain, 'turn_off')
await hass.async_add_job(acc.char_on.client_update_value, True)
await hass.async_block_till_done()
assert acc.char_on.value is True
assert call_turn_on
assert call_turn_on[0].data[ATTR_ENTITY_ID] == entity_id
assert len(events) == 1
assert events[-1].data[ATTR_VALUE] is None
future = dt_util.utcnow() + timedelta(seconds=1)
async_fire_time_changed(hass, future)
await hass.async_block_till_done()
assert acc.char_on.value is False
assert len(events) == 1
assert not call_turn_off
await hass.async_add_job(acc.char_on.client_update_value, False)
await hass.async_block_till_done()
assert acc.char_on.value is False
assert len(events) == 1
示例5: test_if_not_fires_on_entity_change_with_for
async def test_if_not_fires_on_entity_change_with_for(hass, calls):
"""Test for not firing on entity change with for."""
assert await async_setup_component(hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'state',
'entity_id': 'test.entity',
'to': 'world',
'for': {
'seconds': 5
},
},
'action': {
'service': 'test.automation'
}
}
})
hass.states.async_set('test.entity', 'world')
await hass.async_block_till_done()
hass.states.async_set('test.entity', 'not_world')
await hass.async_block_till_done()
async_fire_time_changed(hass, dt_util.utcnow() + timedelta(seconds=10))
await hass.async_block_till_done()
assert 0 == len(calls)
示例6: test_if_fires_when_hour_matches
async def test_if_fires_when_hour_matches(hass, calls):
"""Test for firing if hour is matching."""
assert await async_setup_component(hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'time_pattern',
'hours': 0,
'minutes': '*',
'seconds': '*',
},
'action': {
'service': 'test.automation'
}
}
})
async_fire_time_changed(hass, dt_util.utcnow().replace(hour=0))
await hass.async_block_till_done()
assert 1 == len(calls)
await common.async_turn_off(hass)
await hass.async_block_till_done()
async_fire_time_changed(hass, dt_util.utcnow().replace(hour=0))
await hass.async_block_till_done()
assert 1 == len(calls)
示例7: test_sunset_trigger_with_offset
async def test_sunset_trigger_with_offset(hass, calls):
"""Test the sunset trigger with offset."""
now = datetime(2015, 9, 15, 23, tzinfo=dt_util.UTC)
trigger_time = datetime(2015, 9, 16, 2, 30, tzinfo=dt_util.UTC)
with patch('homeassistant.util.dt.utcnow',
return_value=now):
await async_setup_component(hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'sun',
'event': SUN_EVENT_SUNSET,
'offset': '0:30:00'
},
'action': {
'service': 'test.automation',
'data_template': {
'some':
'{{ trigger.%s }}' % '}} - {{ trigger.'.join((
'platform', 'event', 'offset'))
},
}
}
})
async_fire_time_changed(hass, trigger_time)
await hass.async_block_till_done()
assert 1 == len(calls)
assert 'sun - sunset - 0:30:00' == calls[0].data['some']
示例8: test_update_stale
async def test_update_stale(hass):
"""Test stalled update."""
scanner = get_component(hass, 'device_tracker.test').SCANNER
scanner.reset()
scanner.come_home('DEV1')
register_time = datetime(2015, 9, 15, 23, tzinfo=dt_util.UTC)
scan_time = datetime(2015, 9, 15, 23, 1, tzinfo=dt_util.UTC)
with patch('homeassistant.components.device_tracker.dt_util.utcnow',
return_value=register_time):
with assert_setup_component(1, device_tracker.DOMAIN):
assert await async_setup_component(hass, device_tracker.DOMAIN, {
device_tracker.DOMAIN: {
CONF_PLATFORM: 'test',
device_tracker.CONF_CONSIDER_HOME: 59,
}})
await hass.async_block_till_done()
assert STATE_HOME == \
hass.states.get('device_tracker.dev1').state
scanner.leave_home('DEV1')
with patch('homeassistant.components.device_tracker.dt_util.utcnow',
return_value=scan_time):
async_fire_time_changed(hass, scan_time)
await hass.async_block_till_done()
assert STATE_NOT_HOME == \
hass.states.get('device_tracker.dev1').state
示例9: test_sunset_trigger
async def test_sunset_trigger(hass, calls):
"""Test the sunset trigger."""
now = datetime(2015, 9, 15, 23, tzinfo=dt_util.UTC)
trigger_time = datetime(2015, 9, 16, 2, tzinfo=dt_util.UTC)
with patch('homeassistant.util.dt.utcnow',
return_value=now):
await async_setup_component(hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'sun',
'event': SUN_EVENT_SUNSET,
},
'action': {
'service': 'test.automation',
}
}
})
await common.async_turn_off(hass)
await hass.async_block_till_done()
async_fire_time_changed(hass, trigger_time)
await hass.async_block_till_done()
assert 0 == len(calls)
with patch('homeassistant.util.dt.utcnow',
return_value=now):
await common.async_turn_on(hass)
await hass.async_block_till_done()
async_fire_time_changed(hass, trigger_time)
await hass.async_block_till_done()
assert 1 == len(calls)
示例10: test_arm_home_with_pending
async def test_arm_home_with_pending(hass):
"""Test arm home method."""
assert await async_setup_component(
hass, alarm_control_panel.DOMAIN,
{'alarm_control_panel': {
'platform': 'manual',
'name': 'test',
'code': CODE,
'pending_time': 1,
'disarm_after_trigger': False
}})
entity_id = 'alarm_control_panel.test'
assert STATE_ALARM_DISARMED == \
hass.states.get(entity_id).state
common.async_alarm_arm_home(hass, CODE, entity_id)
await hass.async_block_till_done()
assert STATE_ALARM_PENDING == \
hass.states.get(entity_id).state
state = hass.states.get(entity_id)
assert state.attributes['post_pending_state'] == STATE_ALARM_ARMED_HOME
future = dt_util.utcnow() + timedelta(seconds=1)
with patch(('homeassistant.components.manual.alarm_control_panel.'
'dt_util.utcnow'), return_value=future):
async_fire_time_changed(hass, future)
await hass.async_block_till_done()
state = hass.states.get(entity_id)
assert state.state == STATE_ALARM_ARMED_HOME
示例11: test_if_fires_on_entity_change_with_for_attribute_change
async def test_if_fires_on_entity_change_with_for_attribute_change(hass,
calls):
"""Test for firing on entity change with for and attribute change."""
assert await async_setup_component(hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'numeric_state',
'entity_id': 'test.entity',
'above': 8,
'below': 12,
'for': {
'seconds': 5
},
},
'action': {
'service': 'test.automation'
}
}
})
utcnow = dt_util.utcnow()
with patch('homeassistant.core.dt_util.utcnow') as mock_utcnow:
mock_utcnow.return_value = utcnow
hass.states.async_set('test.entity', 9)
await hass.async_block_till_done()
mock_utcnow.return_value += timedelta(seconds=4)
async_fire_time_changed(hass, mock_utcnow.return_value)
hass.states.async_set('test.entity', 9,
attributes={"mock_attr": "attr_change"})
await hass.async_block_till_done()
assert 0 == len(calls)
mock_utcnow.return_value += timedelta(seconds=4)
async_fire_time_changed(hass, mock_utcnow.return_value)
await hass.async_block_till_done()
assert 1 == len(calls)
示例12: test_armed_night_with_specific_pending
async def test_armed_night_with_specific_pending(hass):
"""Test arm home method."""
assert await async_setup_component(
hass, alarm_control_panel.DOMAIN,
{'alarm_control_panel': {
'platform': 'manual',
'name': 'test',
'pending_time': 10,
'armed_night': {
'pending_time': 2
}
}})
entity_id = 'alarm_control_panel.test'
common.async_alarm_arm_night(hass)
await hass.async_block_till_done()
assert STATE_ALARM_PENDING == \
hass.states.get(entity_id).state
future = dt_util.utcnow() + timedelta(seconds=2)
with patch(('homeassistant.components.manual.alarm_control_panel.'
'dt_util.utcnow'), return_value=future):
async_fire_time_changed(hass, future)
await hass.async_block_till_done()
assert STATE_ALARM_ARMED_NIGHT == \
hass.states.get(entity_id).state
示例13: test_if_fires_on_entity_change_with_for_multiple_force_update
async def test_if_fires_on_entity_change_with_for_multiple_force_update(hass,
calls):
"""Test for firing on entity change with for and force update."""
assert await async_setup_component(hass, automation.DOMAIN, {
automation.DOMAIN: {
'trigger': {
'platform': 'state',
'entity_id': 'test.force_entity',
'to': 'world',
'for': {
'seconds': 5
},
},
'action': {
'service': 'test.automation'
}
}
})
utcnow = dt_util.utcnow()
with patch('homeassistant.core.dt_util.utcnow') as mock_utcnow:
mock_utcnow.return_value = utcnow
hass.states.async_set('test.force_entity', 'world', None, True)
await hass.async_block_till_done()
for _ in range(0, 4):
mock_utcnow.return_value += timedelta(seconds=1)
async_fire_time_changed(hass, mock_utcnow.return_value)
hass.states.async_set('test.force_entity', 'world', None, True)
await hass.async_block_till_done()
assert 0 == len(calls)
mock_utcnow.return_value += timedelta(seconds=4)
async_fire_time_changed(hass, mock_utcnow.return_value)
await hass.async_block_till_done()
assert 1 == len(calls)
示例14: test_saving_and_loading
async def test_saving_and_loading(hass):
"""Test that we're saving and loading correctly."""
loader.set_component(
hass, 'test',
MockModule('test', async_setup_entry=lambda *args: mock_coro(True)))
class TestFlow(config_entries.ConfigFlow):
VERSION = 5
CONNECTION_CLASS = config_entries.CONN_CLASS_LOCAL_POLL
@asyncio.coroutine
def async_step_user(self, user_input=None):
return self.async_create_entry(
title='Test Title',
data={
'token': 'abcd'
}
)
with patch.dict(config_entries.HANDLERS, {'test': TestFlow}):
await hass.config_entries.flow.async_init(
'test', context={'source': config_entries.SOURCE_USER})
class Test2Flow(config_entries.ConfigFlow):
VERSION = 3
CONNECTION_CLASS = config_entries.CONN_CLASS_CLOUD_PUSH
@asyncio.coroutine
def async_step_user(self, user_input=None):
return self.async_create_entry(
title='Test 2 Title',
data={
'username': 'bla'
}
)
with patch('homeassistant.config_entries.HANDLERS.get',
return_value=Test2Flow):
await hass.config_entries.flow.async_init(
'test', context={'source': config_entries.SOURCE_USER})
# To trigger the call_later
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=1))
# To execute the save
await hass.async_block_till_done()
# Now load written data in new config manager
manager = config_entries.ConfigEntries(hass, {})
await manager.async_initialize()
# Ensure same order
for orig, loaded in zip(hass.config_entries.async_entries(),
manager.async_entries()):
assert orig.version == loaded.version
assert orig.domain == loaded.domain
assert orig.title == loaded.title
assert orig.data == loaded.data
assert orig.source == loaded.source
assert orig.connection_class == loaded.connection_class
示例15: test_template_delay_off
def test_template_delay_off(hass):
"""Test binary sensor template delay off."""
config = {
'binary_sensor': {
'platform': 'template',
'sensors': {
'test': {
'friendly_name': 'virtual thingy',
'value_template':
"{{ states.sensor.test_state.state == 'on' }}",
'device_class': 'motion',
'delay_off': 5
},
},
},
}
hass.states.async_set('sensor.test_state', 'on')
yield from setup.async_setup_component(hass, 'binary_sensor', config)
yield from hass.async_start()
hass.states.async_set('sensor.test_state', 'off')
yield from hass.async_block_till_done()
state = hass.states.get('binary_sensor.test')
assert state.state == 'on'
future = dt_util.utcnow() + timedelta(seconds=5)
async_fire_time_changed(hass, future)
yield from hass.async_block_till_done()
state = hass.states.get('binary_sensor.test')
assert state.state == 'off'
# check with time changes
hass.states.async_set('sensor.test_state', 'on')
yield from hass.async_block_till_done()
state = hass.states.get('binary_sensor.test')
assert state.state == 'on'
hass.states.async_set('sensor.test_state', 'off')
yield from hass.async_block_till_done()
state = hass.states.get('binary_sensor.test')
assert state.state == 'on'
hass.states.async_set('sensor.test_state', 'on')
yield from hass.async_block_till_done()
state = hass.states.get('binary_sensor.test')
assert state.state == 'on'
future = dt_util.utcnow() + timedelta(seconds=5)
async_fire_time_changed(hass, future)
yield from hass.async_block_till_done()
state = hass.states.get('binary_sensor.test')
assert state.state == 'on'