1
0
mirror of https://github.com/home-assistant/core.git synced 2025-12-24 21:06:19 +00:00

Update device registry of MQTT cover (#20443)

* Update device registry of MQTT cover

* Move config_entry to constructor
This commit is contained in:
emontnemery
2019-01-26 19:52:41 +01:00
committed by Paulus Schoutsen
parent 85c72fbca6
commit 60dc337f3f
2 changed files with 62 additions and 5 deletions

View File

@@ -758,6 +758,7 @@ class TestCoverMQTT(unittest.TestCase):
'set_position_topic': None, 'set_position_template': None,
'unique_id': None, 'device_config': None,
},
None,
None)
assert 44 == mqtt_cover.find_percentage_in_range(44)
@@ -788,6 +789,7 @@ class TestCoverMQTT(unittest.TestCase):
'set_position_topic': None, 'set_position_template': None,
'unique_id': None, 'device_config': None,
},
None,
None)
assert 40 == mqtt_cover.find_percentage_in_range(120)
@@ -818,6 +820,7 @@ class TestCoverMQTT(unittest.TestCase):
'set_position_topic': None, 'set_position_template': None,
'unique_id': None, 'device_config': None,
},
None,
None)
assert 56 == mqtt_cover.find_percentage_in_range(44)
@@ -848,6 +851,7 @@ class TestCoverMQTT(unittest.TestCase):
'set_position_topic': None, 'set_position_template': None,
'unique_id': None, 'device_config': None,
},
None,
None)
assert 60 == mqtt_cover.find_percentage_in_range(120)
@@ -878,6 +882,7 @@ class TestCoverMQTT(unittest.TestCase):
'set_position_topic': None, 'set_position_template': None,
'unique_id': None, 'device_config': None,
},
None,
None)
assert 44 == mqtt_cover.find_in_range_from_percent(44)
@@ -908,6 +913,7 @@ class TestCoverMQTT(unittest.TestCase):
'set_position_topic': None, 'set_position_template': None,
'unique_id': None, 'device_config': None,
},
None,
None)
assert 120 == mqtt_cover.find_in_range_from_percent(40)
@@ -938,6 +944,7 @@ class TestCoverMQTT(unittest.TestCase):
'set_position_topic': None, 'set_position_template': None,
'unique_id': None, 'device_config': None,
},
None,
None)
assert 44 == mqtt_cover.find_in_range_from_percent(56)
@@ -968,6 +975,7 @@ class TestCoverMQTT(unittest.TestCase):
'set_position_topic': None, 'set_position_template': None,
'unique_id': None, 'device_config': None,
},
None,
None)
assert 120 == mqtt_cover.find_in_range_from_percent(60)
@@ -1293,6 +1301,53 @@ async def test_entity_device_info_with_identifier(hass, mqtt_mock):
assert device.sw_version == '0.1-beta'
async def test_entity_device_info_update(hass, mqtt_mock):
"""Test device registry update."""
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()
config = {
'platform': 'mqtt',
'name': 'Test 1',
'state_topic': 'test-topic',
'command_topic': 'test-command-topic',
'device': {
'identifiers': ['helloworld'],
'connections': [
["mac", "02:5b:26:a8:dc:12"],
],
'manufacturer': 'Whatever',
'name': 'Beer',
'model': 'Glass',
'sw_version': '0.1-beta',
},
'unique_id': 'veryunique'
}
data = json.dumps(config)
async_fire_mqtt_message(hass, 'homeassistant/cover/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.name == 'Beer'
config['device']['name'] = 'Milk'
data = json.dumps(config)
async_fire_mqtt_message(hass, 'homeassistant/cover/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.name == 'Milk'
async def test_entity_id_update(hass, mqtt_mock):
"""Test MQTT subscriptions are managed when entity_id is updated."""
registry = mock_registry(hass, {})