本文整理汇总了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函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
开发者ID:fbradyirl,项目名称:home-assistant,代码行数:33,代码来源:test_alarm_control_panel.py
示例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
开发者ID:fbradyirl,项目名称:home-assistant,代码行数:30,代码来源:test_alarm_control_panel.py
示例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
开发者ID:ManHammer,项目名称:home-assistant,代码行数:25,代码来源:test_group.py
示例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
开发者ID:Martwall,项目名称:home-assistant,代码行数:35,代码来源:test_type_switches.py
示例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)
开发者ID:ManHammer,项目名称:home-assistant,代码行数:25,代码来源:test_state.py
示例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)
开发者ID:Martwall,项目名称:home-assistant,代码行数:26,代码来源:test_time_pattern.py
示例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']
开发者ID:ManHammer,项目名称:home-assistant,代码行数:29,代码来源:test_sun.py
示例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
开发者ID:fbradyirl,项目名称:home-assistant,代码行数:31,代码来源:test_init.py
示例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)
开发者ID:ManHammer,项目名称:home-assistant,代码行数:34,代码来源:test_sun.py
示例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
开发者ID:fbradyirl,项目名称:home-assistant,代码行数:34,代码来源:test_alarm_control_panel.py
示例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)
开发者ID:boced66,项目名称:home-assistant,代码行数:35,代码来源:test_numeric_state.py
示例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
开发者ID:fbradyirl,项目名称:home-assistant,代码行数:29,代码来源:test_alarm_control_panel.py
示例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)
开发者ID:ManHammer,项目名称:home-assistant,代码行数:34,代码来源:test_state.py
示例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
开发者ID:boced66,项目名称:home-assistant,代码行数:59,代码来源:test_config_entries.py
示例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'
开发者ID:JiShangShiDai,项目名称:home-assistant,代码行数:58,代码来源:test_template.py
示例16: poll_and_get_state
async def poll_and_get_state(self):
"""Trigger a time based poll and return the current entity state."""
next_update = dt_util.utcnow() + timedelta(seconds=60)
async_fire_time_changed(self.hass, next_update)
await self.hass.async_block_till_done()
state = self.hass.states.get(self.entity_id)
assert state is not None
return state
开发者ID:Martwall,项目名称:home-assistant,代码行数:9,代码来源:common.py
示例17: test_trigger_with_pending_and_specific_delay
async def test_trigger_with_pending_and_specific_delay(hass):
"""Test trigger method and switch from pending to triggered."""
assert await async_setup_component(
hass, alarm_control_panel.DOMAIN,
{'alarm_control_panel': {
'platform': 'manual',
'name': 'test',
'code': CODE,
'delay_time': 10,
'pending_time': 0,
'armed_away': {
'delay_time': 1
},
'triggered': {
'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_away(hass, CODE)
await hass.async_block_till_done()
assert STATE_ALARM_ARMED_AWAY == \
hass.states.get(entity_id).state
common.async_alarm_trigger(hass, entity_id=entity_id)
await hass.async_block_till_done()
state = hass.states.get(entity_id)
assert state.state == STATE_ALARM_PENDING
assert state.attributes['post_pending_state'] == STATE_ALARM_TRIGGERED
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_PENDING
assert state.attributes['post_pending_state'] == STATE_ALARM_TRIGGERED
future += 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_TRIGGERED
开发者ID:fbradyirl,项目名称:home-assistant,代码行数:55,代码来源:test_alarm_control_panel.py
示例18: test_saving_with_delay
async def test_saving_with_delay(hass, store, hass_storage):
"""Test saving data after a delay."""
store.async_delay_save(lambda: MOCK_DATA, 1)
assert store.key not in hass_storage
async_fire_time_changed(hass, dt.utcnow() + timedelta(seconds=1))
await hass.async_block_till_done()
assert hass_storage[store.key] == {
'version': MOCK_VERSION,
'key': MOCK_KEY,
'data': MOCK_DATA,
}
开发者ID:ManHammer,项目名称:home-assistant,代码行数:12,代码来源:test_storage.py
示例19: test_action_delay
async def test_action_delay(hass, calls):
"""Test action delay."""
assert await async_setup_component(hass, automation.DOMAIN, {
automation.DOMAIN: {
'alias': 'hello',
'trigger': {
'platform': 'event',
'event_type': 'test_event',
},
'action': [
{
'service': 'test.automation',
'data_template': {
'some': '{{ trigger.platform }} - '
'{{ trigger.event.event_type }}'
}
},
{'delay': {'minutes': '10'}},
{
'service': 'test.automation',
'data_template': {
'some': '{{ trigger.platform }} - '
'{{ trigger.event.event_type }}'
}
},
]
}
})
time = dt_util.utcnow()
with patch('homeassistant.components.automation.utcnow',
return_value=time):
hass.bus.async_fire('test_event')
await hass.async_block_till_done()
assert len(calls) == 1
assert calls[0].data['some'] == 'event - test_event'
future = dt_util.utcnow() + timedelta(minutes=10)
async_fire_time_changed(hass, future)
await hass.async_block_till_done()
assert len(calls) == 2
assert calls[1].data['some'] == 'event - test_event'
state = hass.states.get('automation.hello')
assert state is not None
assert state.attributes.get('last_triggered') == time
state = hass.states.get('group.all_automations')
assert state is not None
assert state.attributes.get('entity_id') == ('automation.hello',)
开发者ID:boced66,项目名称:home-assistant,代码行数:52,代码来源:test_init.py
示例20: test_auto_heal_disabled
def test_auto_heal_disabled(hass, mock_openzwave):
"""Test network auto-heal disabled."""
assert (yield from async_setup_component(hass, 'zwave', {
'zwave': {
'autoheal': False,
}}))
network = hass.data[zwave.DATA_NETWORK]
assert not network.heal.called
time = datetime(2017, 5, 6, 0, 0, 0)
async_fire_time_changed(hass, time)
yield from hass.async_block_till_done()
assert not network.heal.called
开发者ID:keatontaylor,项目名称:home-assistant,代码行数:13,代码来源:test_init.py
注:本文中的tests.common.async_fire_time_changed函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论