本文整理汇总了Python中tests.common.mock_restore_cache函数的典型用法代码示例。如果您正苦于以下问题:Python mock_restore_cache函数的具体用法?Python mock_restore_cache怎么用?Python mock_restore_cache使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mock_restore_cache函数的18个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: test_no_initial_value_and_restore_off
def test_no_initial_value_and_restore_off(hass):
"""Test initial value off and restored state is turned on."""
calls = async_mock_service(hass, 'test', 'automation')
mock_restore_cache(hass, (
State('automation.hello', STATE_OFF),
))
res = yield from async_setup_component(hass, automation.DOMAIN, {
automation.DOMAIN: {
'alias': 'hello',
'trigger': {
'platform': 'event',
'event_type': 'test_event',
},
'action': {
'service': 'test.automation',
'entity_id': 'hello.world'
}
}
})
assert res
assert not automation.is_on(hass, 'automation.hello')
hass.bus.async_fire('test_event')
yield from hass.async_block_till_done()
assert len(calls) == 0
开发者ID:EarthlingRich,项目名称:home-assistant,代码行数:26,代码来源:test_init.py
示例2: test_initial_state_overrules_restore_state
def test_initial_state_overrules_restore_state(hass):
"""Ensure states are restored on startup."""
mock_restore_cache(hass, (
State('input_number.b1', '70'),
State('input_number.b2', '200'),
))
hass.state = CoreState.starting
yield from async_setup_component(hass, DOMAIN, {
DOMAIN: {
'b1': {
'initial': 50,
'min': 0,
'max': 100,
},
'b2': {
'initial': 60,
'min': 0,
'max': 100,
},
}})
state = hass.states.get('input_number.b1')
assert state
assert float(state.state) == 50
state = hass.states.get('input_number.b2')
assert state
assert float(state.state) == 60
开发者ID:EarthlingRich,项目名称:home-assistant,代码行数:30,代码来源:test_input_number.py
示例3: test_initial_state_overrules_restore_state
def test_initial_state_overrules_restore_state(hass):
"""Ensure states are restored on startup."""
mock_restore_cache(hass, (
State('counter.test1', '11'),
State('counter.test2', '-22'),
))
hass.state = CoreState.starting
yield from async_setup_component(hass, DOMAIN, {
DOMAIN: {
'test1': {
CONF_RESTORE: False,
},
'test2': {
CONF_INITIAL: 10,
CONF_RESTORE: False,
},
}})
state = hass.states.get('counter.test1')
assert state
assert int(state.state) == 0
state = hass.states.get('counter.test2')
assert state
assert int(state.state) == 10
开发者ID:ManHammer,项目名称:home-assistant,代码行数:27,代码来源:test_init.py
示例4: _mock_restore_cache
def _mock_restore_cache(self, temperature=20, operation_mode=STATE_OFF):
mock_restore_cache(self.hass, (
State(ENTITY, '0', {
ATTR_TEMPERATURE: str(temperature),
climate.ATTR_OPERATION_MODE: operation_mode,
ATTR_AWAY_MODE: "on"}),
))
开发者ID:DavidMStraub,项目名称:home-assistant,代码行数:7,代码来源:test_generic_thermostat.py
示例5: test_no_restore_state
async def test_no_restore_state(hass):
"""Ensure states are restored on startup if they exist.
Allows for graceful reboot.
"""
mock_restore_cache(hass, (
State('climate.test_thermostat', '0', {ATTR_TEMPERATURE: "20",
ATTR_OPERATION_MODE: "off",
ATTR_AWAY_MODE: "on"}),
))
hass.state = CoreState.starting
await async_setup_component(
hass, DOMAIN, {'climate': {
'platform': 'generic_thermostat',
'name': 'test_thermostat',
'heater': ENT_SWITCH,
'target_sensor': ENT_SENSOR,
'target_temp': 22
}})
state = hass.states.get('climate.test_thermostat')
assert(state.attributes[ATTR_TEMPERATURE] == 22)
assert(state.state == STATE_OFF)
开发者ID:fbradyirl,项目名称:home-assistant,代码行数:25,代码来源:test_climate.py
示例6: test_initial_state_overrules_restore_state
def test_initial_state_overrules_restore_state(hass):
"""Ensure states are restored on startup."""
mock_restore_cache(hass, (
State('input_text.b1', 'testing'),
State('input_text.b2', 'testing too long'),
))
hass.state = CoreState.starting
yield from async_setup_component(hass, DOMAIN, {
DOMAIN: {
'b1': {
'initial': 'test',
'min': 0,
'max': 10,
},
'b2': {
'initial': 'test',
'min': 0,
'max': 10,
},
}})
state = hass.states.get('input_text.b1')
assert state
assert str(state.state) == 'test'
state = hass.states.get('input_text.b2')
assert state
assert str(state.state) == 'test'
开发者ID:EarthlingRich,项目名称:home-assistant,代码行数:30,代码来源:test_input_text.py
示例7: test_async_added_to_hass
def test_async_added_to_hass(hass):
"""Test restoring state."""
attr = {
device_tracker.ATTR_LONGITUDE: 18,
device_tracker.ATTR_LATITUDE: -33,
device_tracker.ATTR_LATITUDE: -33,
device_tracker.ATTR_SOURCE_TYPE: 'gps',
device_tracker.ATTR_GPS_ACCURACY: 2,
device_tracker.ATTR_BATTERY: 100
}
mock_restore_cache(hass, [State('device_tracker.jk', 'home', attr)])
path = hass.config.path(device_tracker.YAML_DEVICES)
files = {
path: 'jk:\n name: JK Phone\n track: True',
}
with patch_yaml_files(files):
yield from device_tracker.async_setup(hass, {})
state = hass.states.get('device_tracker.jk')
assert state
assert state.state == 'home'
for key, val in attr.items():
atr = state.attributes.get(key)
assert atr == val, "{}={} expected: {}".format(key, atr, val)
开发者ID:ManHammer,项目名称:home-assistant,代码行数:27,代码来源:test_init.py
示例8: test_initial_state_overrules_restore_state
def test_initial_state_overrules_restore_state(hass):
"""Ensure states are restored on startup."""
mock_restore_cache(hass, (
State('input_select.s1', 'last option'),
State('input_select.s2', 'bad option'),
))
options = {
'options': [
'first option',
'middle option',
'last option',
],
'initial': 'middle option',
}
yield from async_setup_component(hass, DOMAIN, {
DOMAIN: {
's1': options,
's2': options,
}})
state = hass.states.get('input_select.s1')
assert state
assert state.state == 'middle option'
state = hass.states.get('input_select.s2')
assert state
assert state.state == 'middle option'
开发者ID:tmcarr,项目名称:home-assistant,代码行数:29,代码来源:test_input_select.py
示例9: test_restore_state
async def test_restore_state(hass, monkeypatch):
"""Ensure states are restored on startup."""
config = {
'rflink': {
'port': '/dev/ttyABC0',
},
DOMAIN: {
'platform': 'rflink',
'devices': {
'RTS_12345678_0': {
'name': 'c1',
},
'test_restore_2': {
'name': 'c2',
},
'test_restore_3': {
'name': 'c3',
},
'test_restore_4': {
'name': 'c4',
},
},
},
}
mock_restore_cache(hass, (
State(DOMAIN + '.c1', STATE_OPEN, ),
State(DOMAIN + '.c2', STATE_CLOSED, ),
))
hass.state = CoreState.starting
# setup mocking rflink module
_, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
state = hass.states.get(DOMAIN + '.c1')
assert state
assert state.state == STATE_OPEN
state = hass.states.get(DOMAIN + '.c2')
assert state
assert state.state == STATE_CLOSED
state = hass.states.get(DOMAIN + '.c3')
assert state
assert state.state == STATE_CLOSED
# not cached cover must default values
state = hass.states.get(DOMAIN + '.c4')
assert state
assert state.state == STATE_CLOSED
assert state.attributes['assumed_state']
开发者ID:arsaboo,项目名称:home-assistant,代码行数:52,代码来源:test_rflink.py
示例10: test_automation_restore_state
def test_automation_restore_state(hass):
"""Ensure states are restored on startup."""
time = dt_util.utcnow()
mock_restore_cache(hass, (
State('automation.hello', STATE_ON),
State('automation.bye', STATE_OFF, {'last_triggered': time}),
))
config = {automation.DOMAIN: [{
'alias': 'hello',
'trigger': {
'platform': 'event',
'event_type': 'test_event_hello',
},
'action': {'service': 'test.automation'}
}, {
'alias': 'bye',
'trigger': {
'platform': 'event',
'event_type': 'test_event_bye',
},
'action': {'service': 'test.automation'}
}]}
assert (yield from async_setup_component(hass, automation.DOMAIN, config))
state = hass.states.get('automation.hello')
assert state
assert state.state == STATE_ON
state = hass.states.get('automation.bye')
assert state
assert state.state == STATE_OFF
assert state.attributes.get('last_triggered') == time
calls = async_mock_service(hass, 'test', 'automation')
assert automation.is_on(hass, 'automation.bye') is False
hass.bus.async_fire('test_event_bye')
yield from hass.async_block_till_done()
assert len(calls) == 0
assert automation.is_on(hass, 'automation.hello')
hass.bus.async_fire('test_event_hello')
yield from hass.async_block_till_done()
assert len(calls) == 1
开发者ID:EarthlingRich,项目名称:home-assistant,代码行数:50,代码来源:test_init.py
示例11: test_restore_state
async def test_restore_state(hass, monkeypatch):
"""Ensure states are restored on startup."""
config = {
'rflink': {
'port': '/dev/ttyABC0',
},
DOMAIN: {
'platform': 'rflink',
'devices': {
'test': {
'name': 's1',
'aliases': ['test_alias_0_0'],
},
'switch_test': {
'name': 's2',
},
'switch_s3': {
'name': 's3',
}
}
}
}
mock_restore_cache(hass, (
State(DOMAIN + '.s1', STATE_ON, ),
State(DOMAIN + '.s2', STATE_OFF, ),
))
hass.state = CoreState.starting
# setup mocking rflink module
_, _, _, _ = await mock_rflink(hass, config, DOMAIN, monkeypatch)
state = hass.states.get(DOMAIN + '.s1')
assert state
assert state.state == STATE_ON
state = hass.states.get(DOMAIN + '.s2')
assert state
assert state.state == STATE_OFF
# not cached switch must default values
state = hass.states.get(DOMAIN + '.s3')
assert state
assert state.state == STATE_OFF
assert state.attributes['assumed_state']
开发者ID:Martwall,项目名称:home-assistant,代码行数:46,代码来源:test_rflink.py
示例12: test_restore_state
def test_restore_state(hass):
"""Ensure states are restored on startup."""
mock_restore_cache(hass, (
State('input_datetime.test_time', '19:46:00'),
State('input_datetime.test_date', '2017-09-07'),
State('input_datetime.test_datetime', '2017-09-07 19:46:00'),
State('input_datetime.test_bogus_data', 'this is not a date'),
))
hass.state = CoreState.starting
initial = datetime.datetime(2017, 1, 1, 23, 42)
yield from async_setup_component(hass, DOMAIN, {
DOMAIN: {
'test_time': {
'has_time': True,
'has_date': False
},
'test_date': {
'has_time': False,
'has_date': True
},
'test_datetime': {
'has_time': True,
'has_date': True
},
'test_bogus_data': {
'has_time': True,
'has_date': True,
'initial': str(initial)
},
}})
dt_obj = datetime.datetime(2017, 9, 7, 19, 46)
state_time = hass.states.get('input_datetime.test_time')
assert state_time.state == str(dt_obj.time())
state_date = hass.states.get('input_datetime.test_date')
assert state_date.state == str(dt_obj.date())
state_datetime = hass.states.get('input_datetime.test_datetime')
assert state_datetime.state == str(dt_obj)
state_bogus = hass.states.get('input_datetime.test_bogus_data')
assert state_bogus.state == str(initial)
开发者ID:EarthlingRich,项目名称:home-assistant,代码行数:46,代码来源:test_input_datetime.py
示例13: test_restore_state
def test_restore_state(hass):
"""Ensure states are restored on startup."""
mock_restore_cache(hass, (
State('climate.test_thermostat', '0', {ATTR_TEMPERATURE: "20",
climate.ATTR_OPERATION_MODE: "off"}),
))
hass.state = CoreState.starting
yield from async_setup_component(
hass, climate.DOMAIN, {'climate': {
'platform': 'generic_thermostat',
'name': 'test_thermostat',
'heater': ENT_SWITCH,
'target_sensor': ENT_SENSOR,
}})
state = hass.states.get('climate.test_thermostat')
assert(state.attributes[ATTR_TEMPERATURE] == 20)
assert(state.attributes[climate.ATTR_OPERATION_MODE] == "off")
开发者ID:JiShangShiDai,项目名称:home-assistant,代码行数:20,代码来源:test_generic_thermostat.py
示例14: test_restore_disarmed_state
async def test_restore_disarmed_state(hass):
"""Ensure disarmed state is restored on startup."""
mock_restore_cache(hass, (
State('alarm_control_panel.test', STATE_ALARM_DISARMED),
))
hass.state = CoreState.starting
mock_component(hass, 'recorder')
assert await async_setup_component(hass, alarm_control_panel.DOMAIN, {
'alarm_control_panel': {
'platform': 'manual',
'name': 'test',
'pending_time': 0,
'trigger_time': 0,
'disarm_after_trigger': False
}})
state = hass.states.get('alarm_control_panel.test')
assert state
assert state.state == STATE_ALARM_DISARMED
开发者ID:fbradyirl,项目名称:home-assistant,代码行数:21,代码来源:test_alarm_control_panel.py
示例15: test_initial_state_overrules_restore_state
def test_initial_state_overrules_restore_state(hass):
"""Ensure states are restored on startup."""
mock_restore_cache(hass, (
State('input_boolean.b1', 'on'),
State('input_boolean.b2', 'off'),
))
hass.state = CoreState.starting
yield from async_setup_component(hass, DOMAIN, {
DOMAIN: {
'b1': {CONF_INITIAL: False},
'b2': {CONF_INITIAL: True},
}})
state = hass.states.get('input_boolean.b1')
assert state
assert state.state == 'off'
state = hass.states.get('input_boolean.b2')
assert state
assert state.state == 'on'
开发者ID:EarthlingRich,项目名称:home-assistant,代码行数:22,代码来源:test_input_boolean.py
示例16: test_no_restore_state
def test_no_restore_state(hass):
"""Ensure states are not restored on startup if not needed."""
mock_restore_cache(hass, (
State('climate.test_thermostat', '0', {ATTR_TEMPERATURE: "20",
climate.ATTR_OPERATION_MODE: "off"}),
))
hass.state = CoreState.starting
yield from async_setup_component(
hass, climate.DOMAIN, {'climate': {
'platform': 'generic_thermostat',
'name': 'test_thermostat',
'heater': ENT_SWITCH,
'target_sensor': ENT_SENSOR,
'target_temp': 22,
'initial_operation_mode': 'auto',
}})
state = hass.states.get('climate.test_thermostat')
assert(state.attributes[ATTR_TEMPERATURE] == 22)
assert(state.attributes[climate.ATTR_OPERATION_MODE] != "off")
开发者ID:JiShangShiDai,项目名称:home-assistant,代码行数:22,代码来源:test_generic_thermostat.py
示例17: test_restore_home_state
async def test_restore_home_state(hass, hass_admin_user):
"""Test that the state is restored for a person on startup."""
user_id = hass_admin_user.id
attrs = {
ATTR_ID: '1234', ATTR_LATITUDE: 10.12346, ATTR_LONGITUDE: 11.12346,
ATTR_SOURCE: DEVICE_TRACKER, ATTR_USER_ID: user_id}
state = State('person.tracked_person', 'home', attrs)
mock_restore_cache(hass, (state, ))
hass.state = CoreState.not_running
mock_component(hass, 'recorder')
config = {DOMAIN: {
'id': '1234', 'name': 'tracked person', 'user_id': user_id,
'device_trackers': DEVICE_TRACKER}}
assert await async_setup_component(hass, DOMAIN, config)
state = hass.states.get('person.tracked_person')
assert state.state == 'home'
assert state.attributes.get(ATTR_ID) == '1234'
assert state.attributes.get(ATTR_LATITUDE) == 10.12346
assert state.attributes.get(ATTR_LONGITUDE) == 11.12346
# When restoring state the entity_id of the person will be used as source.
assert state.attributes.get(ATTR_SOURCE) == 'person.tracked_person'
assert state.attributes.get(ATTR_USER_ID) == user_id
开发者ID:arsaboo,项目名称:home-assistant,代码行数:23,代码来源:test_init.py
示例18: test_restore_state
def test_restore_state(hass):
"""Ensure states are restored on startup."""
mock_restore_cache(hass, (
State('input_boolean.b1', 'on'),
State('input_boolean.b2', 'off'),
State('input_boolean.b3', 'on'),
))
hass.state = CoreState.starting
mock_component(hass, 'recorder')
yield from async_setup_component(hass, DOMAIN, {
DOMAIN: {
'b1': None,
'b2': None,
}})
state = hass.states.get('input_boolean.b1')
assert state
assert state.state == 'on'
state = hass.states.get('input_boolean.b2')
assert state
assert state.state == 'off'
开发者ID:EarthlingRich,项目名称:home-assistant,代码行数:24,代码来源:test_input_boolean.py
注:本文中的tests.common.mock_restore_cache函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论