本文整理汇总了Python中tests.common.mock_mqtt_component函数的典型用法代码示例。如果您正苦于以下问题:Python mock_mqtt_component函数的具体用法?Python mock_mqtt_component怎么用?Python mock_mqtt_component使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了mock_mqtt_component函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: setup_method
def setup_method(self, method):
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass)
self.assertTrue(
setup_component(
self.hass,
device_tracker.DOMAIN,
{
device_tracker.DOMAIN: {
CONF_PLATFORM: "owntracks",
CONF_MAX_GPS_ACCURACY: 200,
CONF_WAYPOINT_IMPORT: True,
CONF_WAYPOINT_WHITELIST: ["jon", "greg"],
}
},
)
)
self.hass.states.set("zone.inner", "zoning", {"name": "zone", "latitude": 2.1, "longitude": 1.1, "radius": 10})
self.hass.states.set(
"zone.inner_2", "zoning", {"name": "zone", "latitude": 2.1, "longitude": 1.1, "radius": 10}
)
self.hass.states.set(
"zone.outer", "zoning", {"name": "zone", "latitude": 2.0, "longitude": 1.0, "radius": 100000}
)
# Clear state between teste
self.hass.states.set(DEVICE_TRACKER_STATE, None)
owntracks.REGIONS_ENTERED = defaultdict(list)
owntracks.MOBILE_BEACONS_ACTIVE = defaultdict(list)
示例2: setUp
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
mock_mqtt_component(self.hass)
self.calls = []
def record_call(service):
self.calls.append(service)
self.hass.services.register("test", "automation", record_call)
示例3: setUp
def setUp(self): # pylint: disable=invalid-name
self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass)
self.calls = []
def record_call(service):
self.calls.append(service)
self.hass.services.register('test', 'automation', record_call)
示例4: setUp
def setUp(self): # pylint: disable=invalid-name
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.hass.config.components.append('group')
mock_mqtt_component(self.hass)
self.calls = []
def record_call(service):
self.calls.append(service)
self.hass.services.register('test', 'automation', record_call)
示例5: setUp
def setUp(self):
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.hass.config.components.append('group')
mock_mqtt_component(self.hass)
self.calls = []
@callback
def record_call(service):
"""Helper to record calls."""
self.calls.append(service)
self.hass.services.register('test', 'automation', record_call)
示例6: setup_method
def setup_method(self, method):
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass)
self.assertTrue(device_tracker.setup(self.hass, {
device_tracker.DOMAIN: {
CONF_PLATFORM: 'owntracks',
CONF_MAX_GPS_ACCURACY: 200
}}))
self.hass.states.set(
'zone.inner', 'zoning',
{
'name': 'zone',
'latitude': 2.1,
'longitude': 1.1,
'radius': 10
})
self.hass.states.set(
'zone.inner_2', 'zoning',
{
'name': 'zone',
'latitude': 2.1,
'longitude': 1.1,
'radius': 10
})
self.hass.states.set(
'zone.outer', 'zoning',
{
'name': 'zone',
'latitude': 2.0,
'longitude': 1.0,
'radius': 100000
})
self.hass.states.set(
'zone.passive', 'zoning',
{
'name': 'zone',
'latitude': 3.0,
'longitude': 1.0,
'radius': 10,
'passive': True
})
# Clear state between teste
self.hass.states.set(DEVICE_TRACKER_STATE, None)
owntracks.REGIONS_ENTERED = defaultdict(list)
owntracks.MOBILE_BEACONS_ACTIVE = defaultdict(list)
示例7: setUp
def setUp(self): # pylint: disable=invalid-name
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.mock_publish = mock_mqtt_component(self.hass)
self.default_config = {
CONF_PLATFORM: 'mqtt',
CONF_NAME: 'mqtttest',
CONF_COMMAND_TOPIC: 'vacuum/command',
mqtt.CONF_SEND_COMMAND_TOPIC: 'vacuum/send_command',
mqtt.CONF_BATTERY_LEVEL_TOPIC: 'vacuum/state',
mqtt.CONF_BATTERY_LEVEL_TEMPLATE:
'{{ value_json.battery_level }}',
mqtt.CONF_CHARGING_TOPIC: 'vacuum/state',
mqtt.CONF_CHARGING_TEMPLATE: '{{ value_json.charging }}',
mqtt.CONF_CLEANING_TOPIC: 'vacuum/state',
mqtt.CONF_CLEANING_TEMPLATE: '{{ value_json.cleaning }}',
mqtt.CONF_DOCKED_TOPIC: 'vacuum/state',
mqtt.CONF_DOCKED_TEMPLATE: '{{ value_json.docked }}',
mqtt.CONF_STATE_TOPIC: 'vacuum/state',
mqtt.CONF_STATE_TEMPLATE: '{{ value_json.state }}',
mqtt.CONF_FAN_SPEED_TOPIC: 'vacuum/state',
mqtt.CONF_FAN_SPEED_TEMPLATE: '{{ value_json.fan_speed }}',
mqtt.CONF_SET_FAN_SPEED_TOPIC: 'vacuum/set_fan_speed',
mqtt.CONF_FAN_SPEED_LIST: ['min', 'medium', 'high', 'max'],
}
示例8: setup_method
def setup_method(self, method):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass)
self.assertTrue(setup_component(self.hass, sensor.DOMAIN, {
sensor.DOMAIN: {
CONF_PLATFORM: 'mqtt_room',
CONF_NAME: NAME,
CONF_DEVICE_ID: DEVICE_ID,
CONF_STATE_TOPIC: 'room_presence',
CONF_QOS: DEFAULT_QOS,
CONF_TIMEOUT: 5
}}))
# Clear state between tests
self.hass.states.set(SENSOR_STATE, None)
示例9: setup_method
def setup_method(self, _):
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass)
mock_component(self.hass, 'group')
mock_component(self.hass, 'zone')
patcher = patch('homeassistant.components.device_tracker.'
'DeviceTracker.async_update_config')
patcher.start()
self.addCleanup(patcher.stop)
orig_context = owntracks.OwnTracksContext
def store_context(*args):
self.context = orig_context(*args)
return self.context
with patch('homeassistant.components.device_tracker.async_load_config',
return_value=mock_coro([])), \
patch('homeassistant.components.device_tracker.'
'load_yaml_config_file', return_value=mock_coro({})), \
patch.object(owntracks, 'OwnTracksContext', store_context), \
assert_setup_component(1, device_tracker.DOMAIN):
assert setup_component(self.hass, device_tracker.DOMAIN, {
device_tracker.DOMAIN: {
CONF_PLATFORM: 'owntracks',
CONF_MAX_GPS_ACCURACY: 200,
CONF_WAYPOINT_IMPORT: True,
CONF_WAYPOINT_WHITELIST: ['jon', 'greg']
}})
self.hass.states.set(
'zone.inner', 'zoning', INNER_ZONE)
self.hass.states.set(
'zone.inner_2', 'zoning', INNER_ZONE)
self.hass.states.set(
'zone.outer', 'zoning', OUTER_ZONE)
# Clear state between tests
# NB: state "None" is not a state that is created by Device
# so when we compare state to None in the tests this
# is really checking that it is still in its original
# test case state. See Device.async_update.
self.hass.states.set(DEVICE_TRACKER_STATE, None)
示例10: setup_method
def setup_method(self, method):
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass)
mock_component(self.hass, 'group')
mock_component(self.hass, 'zone')
patch_load = patch(
'homeassistant.components.device_tracker.async_load_config',
return_value=mock_coro([]))
patch_load.start()
self.addCleanup(patch_load.stop)
patch_save = patch('homeassistant.components.device_tracker.'
'DeviceTracker.async_update_config')
patch_save.start()
self.addCleanup(patch_save.stop)
示例11: setup_method
def setup_method(self, _):
"""Setup things to be run when tests are started."""
self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass)
with assert_setup_component(1, device_tracker.DOMAIN):
assert setup_component(self.hass, device_tracker.DOMAIN, {
device_tracker.DOMAIN: {
CONF_PLATFORM: 'owntracks',
CONF_MAX_GPS_ACCURACY: 200,
CONF_WAYPOINT_IMPORT: True,
CONF_WAYPOINT_WHITELIST: ['jon', 'greg']
}})
self.hass.states.set(
'zone.inner', 'zoning',
{
'name': 'zone',
'latitude': 2.1,
'longitude': 1.1,
'radius': 10
})
self.hass.states.set(
'zone.inner_2', 'zoning',
{
'name': 'zone',
'latitude': 2.1,
'longitude': 1.1,
'radius': 10
})
self.hass.states.set(
'zone.outer', 'zoning',
{
'name': 'zone',
'latitude': 2.0,
'longitude': 1.0,
'radius': 100000
})
# Clear state between teste
self.hass.states.set(DEVICE_TRACKER_STATE, None)
owntracks.REGIONS_ENTERED = defaultdict(list)
owntracks.MOBILE_BEACONS_ACTIVE = defaultdict(list)
示例12: setup_method
def setup_method(self, method):
""" Init needed objects. """
self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass)
self.assertTrue(device_tracker.setup(self.hass, {
device_tracker.DOMAIN: {
CONF_PLATFORM: 'owntracks'
}}))
self.hass.states.set(
'zone.inner', 'zoning',
{
'name': 'zone',
'latitude': 2.1,
'longitude': 1.1,
'radius': 10
})
self.hass.states.set(
'zone.inner_2', 'zoning',
{
'name': 'zone',
'latitude': 2.1,
'longitude': 1.1,
'radius': 10
})
self.hass.states.set(
'zone.outer', 'zoning',
{
'name': 'zone',
'latitude': 2.0,
'longitude': 1.0,
'radius': 100000
})
# Clear state between teste
self.hass.states.set(DEVICE_TRACKER_STATE, None)
owntracks.REGIONS_ENTERED = defaultdict(list)
owntracks.MOBILE_BEACONS_ACTIVE = defaultdict(list)
示例13: setup_method
def setup_method(self, method):
""" Init needed objects. """
self.hass = get_test_home_assistant()
mock_mqtt_component(self.hass)
self.assertTrue(device_tracker.setup(self.hass, {device_tracker.DOMAIN: {CONF_PLATFORM: "owntracks"}}))
self.hass.states.set("zone.inner", "zoning", {"name": "zone", "latitude": 2.1, "longitude": 1.1, "radius": 10})
self.hass.states.set(
"zone.inner_2", "zoning", {"name": "zone", "latitude": 2.1, "longitude": 1.1, "radius": 10}
)
self.hass.states.set(
"zone.outer", "zoning", {"name": "zone", "latitude": 2.0, "longitude": 1.0, "radius": 100000}
)
self.hass.states.set(
"zone.passive", "zoning", {"name": "zone", "latitude": 3.0, "longitude": 1.0, "radius": 10, "passive": True}
)
# Clear state between teste
self.hass.states.set(DEVICE_TRACKER_STATE, None)
owntracks.REGIONS_ENTERED = defaultdict(list)
owntracks.MOBILE_BEACONS_ACTIVE = defaultdict(list)
示例14: setUp
def setUp(self): # pylint: disable=invalid-name
self.hass = ha.HomeAssistant()
self.mock_publish = mock_mqtt_component(self.hass)
示例15: setUp
def setUp(self):
"""Set up things to be run when tests are started."""
self.hass = get_test_home_assistant()
self.mock_publish = mock_mqtt_component(self.hass)