Add device registry to MQTT cover (#17245)
* Add device registry to MQTT cover * Fix tests
This commit is contained in:
1 parent
b637b48bd8
commit
dd55ff87c8
2 files changed
+57
-12
No files matched your search
@@ -1,4 +1,5 @@
|
||||
"""The tests for the MQTT cover platform."""
|
||||
import json
|
||||
import unittest
|
||||
|
||||
from homeassistant.components import cover, mqtt
|
||||
@@ -615,7 +616,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||
'tilt-command-topic', 'tilt-status-topic', 0, False,
|
||||
'OPEN', 'CLOSE', 'OPEN', 'CLOSE', 'STOP', None, None,
|
||||
False, None, 100, 0, 0, 100, False, False, None, None, None,
|
||||
None)
|
||||
None, None)
|
||||
|
||||
self.assertEqual(44, mqtt_cover.find_percentage_in_range(44))
|
||||
|
||||
@@ -626,7 +627,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||
'tilt-command-topic', 'tilt-status-topic', 0, False,
|
||||
'OPEN', 'CLOSE', 'OPEN', 'CLOSE', 'STOP', None, None,
|
||||
False, None, 180, 80, 80, 180, False, False, None, None, None,
|
||||
None)
|
||||
None, None)
|
||||
|
||||
self.assertEqual(40, mqtt_cover.find_percentage_in_range(120))
|
||||
|
||||
@@ -637,7 +638,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||
'tilt-command-topic', 'tilt-status-topic', 0, False,
|
||||
'OPEN', 'CLOSE', 'OPEN', 'CLOSE', 'STOP', None, None,
|
||||
False, None, 100, 0, 0, 100, False, True, None, None, None,
|
||||
None)
|
||||
None, None)
|
||||
|
||||
self.assertEqual(56, mqtt_cover.find_percentage_in_range(44))
|
||||
|
||||
@@ -648,7 +649,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||
'tilt-command-topic', 'tilt-status-topic', 0, False,
|
||||
'OPEN', 'CLOSE', 'OPEN', 'CLOSE', 'STOP', None, None,
|
||||
False, None, 180, 80, 80, 180, False, True, None, None, None,
|
||||
None)
|
||||
None, None)
|
||||
|
||||
self.assertEqual(60, mqtt_cover.find_percentage_in_range(120))
|
||||
|
||||
@@ -659,7 +660,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||
'tilt-command-topic', 'tilt-status-topic', 0, False,
|
||||
'OPEN', 'CLOSE', 'OPEN', 'CLOSE', 'STOP', None, None,
|
||||
False, None, 100, 0, 0, 100, False, False, None, None, None,
|
||||
None)
|
||||
None, None)
|
||||
|
||||
self.assertEqual(44, mqtt_cover.find_in_range_from_percent(44))
|
||||
|
||||
@@ -670,7 +671,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||
'tilt-command-topic', 'tilt-status-topic', 0, False,
|
||||
'OPEN', 'CLOSE', 'OPEN', 'CLOSE', 'STOP', None, None,
|
||||
False, None, 180, 80, 80, 180, False, False, None, None, None,
|
||||
None)
|
||||
None, None)
|
||||
|
||||
self.assertEqual(120, mqtt_cover.find_in_range_from_percent(40))
|
||||
|
||||
@@ -681,7 +682,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||
'tilt-command-topic', 'tilt-status-topic', 0, False,
|
||||
'OPEN', 'CLOSE', 'OPEN', 'CLOSE', 'STOP', None, None,
|
||||
False, None, 100, 0, 0, 100, False, True, None, None, None,
|
||||
None)
|
||||
None, None)
|
||||
|
||||
self.assertEqual(44, mqtt_cover.find_in_range_from_percent(56))
|
||||
|
||||
@@ -692,7 +693,7 @@ class TestCoverMQTT(unittest.TestCase):
|
||||
'tilt-command-topic', 'tilt-status-topic', 0, False,
|
||||
'OPEN', 'CLOSE', 'OPEN', 'CLOSE', 'STOP', None, None,
|
||||
False, None, 180, 80, 80, 180, False, True, None, None, None,
|
||||
None)
|
||||
None, None)
|
||||
|
||||
self.assertEqual(120, mqtt_cover.find_in_range_from_percent(60))
|
||||
|
||||
@@ -810,3 +811,42 @@ async def test_unique_id(hass):
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_entity_ids(cover.DOMAIN)) == 1
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(hass, mqtt_mock):
|
||||
"""Test MQTT cover 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()
|
||||
|
||||
data = json.dumps({
|
||||
'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'
|
||||
})
|
||||
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.identifiers == {('mqtt', 'helloworld')}
|
||||
assert device.connections == {('mac', "02:5b:26:a8:dc:12")}
|
||||
assert device.manufacturer == 'Whatever'
|
||||
assert device.name == 'Beer'
|
||||
assert device.model == 'Glass'
|
||||
assert device.sw_version == '0.1-beta'
|
||||
Reference in new issue
Block a user