1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-25 05:26:47 +00:00
This commit is contained in:
Paulus Schoutsen
2019-07-31 12:25:30 -07:00
parent da05dfe708
commit 4de97abc3a
2676 changed files with 163166 additions and 140084 deletions

View File

@@ -18,39 +18,45 @@ def setup_comp(hass, mqtt_mock):
async def test_ensure_device_tracker_platform_validation(hass):
"""Test if platform validation was done."""
async def mock_setup_scanner(hass, config, see, discovery_info=None):
"""Check that Qos was added by validation."""
assert 'qos' in config
assert "qos" in config
with patch('homeassistant.components.mqtt.device_tracker.'
'async_setup_scanner', autospec=True,
side_effect=mock_setup_scanner) as mock_sp:
with patch(
"homeassistant.components.mqtt.device_tracker." "async_setup_scanner",
autospec=True,
side_effect=mock_setup_scanner,
) as mock_sp:
dev_id = 'paulus'
topic = '/location/paulus'
assert await async_setup_component(hass, device_tracker.DOMAIN, {
device_tracker.DOMAIN: {
CONF_PLATFORM: 'mqtt',
'devices': {dev_id: topic}
}
})
dev_id = "paulus"
topic = "/location/paulus"
assert await async_setup_component(
hass,
device_tracker.DOMAIN,
{
device_tracker.DOMAIN: {
CONF_PLATFORM: "mqtt",
"devices": {dev_id: topic},
}
},
)
assert mock_sp.call_count == 1
async def test_new_message(hass, mock_device_tracker_conf):
"""Test new message."""
dev_id = 'paulus'
dev_id = "paulus"
entity_id = ENTITY_ID_FORMAT.format(dev_id)
topic = '/location/paulus'
location = 'work'
topic = "/location/paulus"
location = "work"
hass.config.components = set(['mqtt', 'zone'])
assert await async_setup_component(hass, device_tracker.DOMAIN, {
device_tracker.DOMAIN: {
CONF_PLATFORM: 'mqtt',
'devices': {dev_id: topic}
}
})
hass.config.components = set(["mqtt", "zone"])
assert await async_setup_component(
hass,
device_tracker.DOMAIN,
{device_tracker.DOMAIN: {CONF_PLATFORM: "mqtt", "devices": {dev_id: topic}}},
)
async_fire_mqtt_message(hass, topic, location)
await hass.async_block_till_done()
assert hass.states.get(entity_id).state == location
@@ -58,19 +64,23 @@ async def test_new_message(hass, mock_device_tracker_conf):
async def test_single_level_wildcard_topic(hass, mock_device_tracker_conf):
"""Test single level wildcard topic."""
dev_id = 'paulus'
dev_id = "paulus"
entity_id = ENTITY_ID_FORMAT.format(dev_id)
subscription = '/location/+/paulus'
topic = '/location/room/paulus'
location = 'work'
subscription = "/location/+/paulus"
topic = "/location/room/paulus"
location = "work"
hass.config.components = set(['mqtt', 'zone'])
assert await async_setup_component(hass, device_tracker.DOMAIN, {
device_tracker.DOMAIN: {
CONF_PLATFORM: 'mqtt',
'devices': {dev_id: subscription}
}
})
hass.config.components = set(["mqtt", "zone"])
assert await async_setup_component(
hass,
device_tracker.DOMAIN,
{
device_tracker.DOMAIN: {
CONF_PLATFORM: "mqtt",
"devices": {dev_id: subscription},
}
},
)
async_fire_mqtt_message(hass, topic, location)
await hass.async_block_till_done()
assert hass.states.get(entity_id).state == location
@@ -78,61 +88,71 @@ async def test_single_level_wildcard_topic(hass, mock_device_tracker_conf):
async def test_multi_level_wildcard_topic(hass, mock_device_tracker_conf):
"""Test multi level wildcard topic."""
dev_id = 'paulus'
dev_id = "paulus"
entity_id = ENTITY_ID_FORMAT.format(dev_id)
subscription = '/location/#'
topic = '/location/room/paulus'
location = 'work'
subscription = "/location/#"
topic = "/location/room/paulus"
location = "work"
hass.config.components = set(['mqtt', 'zone'])
assert await async_setup_component(hass, device_tracker.DOMAIN, {
device_tracker.DOMAIN: {
CONF_PLATFORM: 'mqtt',
'devices': {dev_id: subscription}
}
})
hass.config.components = set(["mqtt", "zone"])
assert await async_setup_component(
hass,
device_tracker.DOMAIN,
{
device_tracker.DOMAIN: {
CONF_PLATFORM: "mqtt",
"devices": {dev_id: subscription},
}
},
)
async_fire_mqtt_message(hass, topic, location)
await hass.async_block_till_done()
assert hass.states.get(entity_id).state == location
async def test_single_level_wildcard_topic_not_matching(
hass, mock_device_tracker_conf):
async def test_single_level_wildcard_topic_not_matching(hass, mock_device_tracker_conf):
"""Test not matching single level wildcard topic."""
dev_id = 'paulus'
dev_id = "paulus"
entity_id = ENTITY_ID_FORMAT.format(dev_id)
subscription = '/location/+/paulus'
topic = '/location/paulus'
location = 'work'
subscription = "/location/+/paulus"
topic = "/location/paulus"
location = "work"
hass.config.components = set(['mqtt', 'zone'])
assert await async_setup_component(hass, device_tracker.DOMAIN, {
device_tracker.DOMAIN: {
CONF_PLATFORM: 'mqtt',
'devices': {dev_id: subscription}
}
})
hass.config.components = set(["mqtt", "zone"])
assert await async_setup_component(
hass,
device_tracker.DOMAIN,
{
device_tracker.DOMAIN: {
CONF_PLATFORM: "mqtt",
"devices": {dev_id: subscription},
}
},
)
async_fire_mqtt_message(hass, topic, location)
await hass.async_block_till_done()
assert hass.states.get(entity_id) is None
async def test_multi_level_wildcard_topic_not_matching(
hass, mock_device_tracker_conf):
async def test_multi_level_wildcard_topic_not_matching(hass, mock_device_tracker_conf):
"""Test not matching multi level wildcard topic."""
dev_id = 'paulus'
dev_id = "paulus"
entity_id = ENTITY_ID_FORMAT.format(dev_id)
subscription = '/location/#'
topic = '/somewhere/room/paulus'
location = 'work'
subscription = "/location/#"
topic = "/somewhere/room/paulus"
location = "work"
hass.config.components = set(['mqtt', 'zone'])
assert await async_setup_component(hass, device_tracker.DOMAIN, {
device_tracker.DOMAIN: {
CONF_PLATFORM: 'mqtt',
'devices': {dev_id: subscription}
}
})
hass.config.components = set(["mqtt", "zone"])
assert await async_setup_component(
hass,
device_tracker.DOMAIN,
{
device_tracker.DOMAIN: {
CONF_PLATFORM: "mqtt",
"devices": {dev_id: subscription},
}
},
)
async_fire_mqtt_message(hass, topic, location)
await hass.async_block_till_done()
assert hass.states.get(entity_id) is None