Add support for 'via_hub' for device_info (#19454)

* Add support for 'via_hub'

* Update config schema

* add domain to via_hub

* add tests for via_hub
This commit is contained in:
Fredrik Erlandsson authored and Paulus Schoutsen committed 2019-01-11 13:11:13 -08:00
1 parent 199db7219e
commit b9a488912a
3 files changed
+51

No files matched your search

+33
View File
@@ -610,3 +610,36 @@ async def test_entity_id_update(hass, mqtt_mock):
assert mock_mqtt.async_subscribe.call_count == 2
mock_mqtt.async_subscribe.assert_any_call('test-topic', ANY, 0, 'utf-8')
mock_mqtt.async_subscribe.assert_any_call('avty-topic', ANY, 0, 'utf-8')
async def test_entity_device_info_with_hub(hass, mqtt_mock):
"""Test MQTT sensor device registry integration."""
entry = MockConfigEntry(domain=mqtt.DOMAIN)
entry.add_to_hass(hass)
await async_start(hass, 'homeassistant', {}, entry)
registry = await hass.helpers.device_registry.async_get_registry()
hub = registry.async_get_or_create(
config_entry_id='123',
connections=set(),
identifiers={('mqtt', 'hub-id')},
manufacturer='manufacturer', model='hub'
)
data = json.dumps({
'platform': 'mqtt',
'name': 'Test 1',
'state_topic': 'test-topic',
'device': {
'identifiers': ['helloworld'],
'via_hub': 'hub-id',
},
'unique_id': 'veryunique'
})
async_fire_mqtt_message(hass, 'homeassistant/sensor/bla/config', data)
await hass.async_block_till_done()
await hass.async_block_till_done()
device = registry.async_get_device({('mqtt', 'helloworld')}, set())
assert device is not None
assert device.hub_device_id == hub.id