mirror of
https://github.com/home-assistant/core.git
synced 2025-07-16 09:47:13 +00:00
Update device registry of MQTT Vacuum (#20500)
This commit is contained in:
parent
1f93984fd5
commit
8804f55fcc
@ -163,17 +163,17 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
|
|||||||
async def async_discover(discovery_payload):
|
async def async_discover(discovery_payload):
|
||||||
"""Discover and add a MQTT vacuum."""
|
"""Discover and add a MQTT vacuum."""
|
||||||
config = PLATFORM_SCHEMA(discovery_payload)
|
config = PLATFORM_SCHEMA(discovery_payload)
|
||||||
await _async_setup_entity(config, async_add_entities,
|
await _async_setup_entity(config, async_add_entities, config_entry,
|
||||||
discovery_payload[ATTR_DISCOVERY_HASH])
|
discovery_payload[ATTR_DISCOVERY_HASH])
|
||||||
|
|
||||||
async_dispatcher_connect(
|
async_dispatcher_connect(
|
||||||
hass, MQTT_DISCOVERY_NEW.format(DOMAIN, 'mqtt'), async_discover)
|
hass, MQTT_DISCOVERY_NEW.format(DOMAIN, 'mqtt'), async_discover)
|
||||||
|
|
||||||
|
|
||||||
async def _async_setup_entity(config, async_add_entities,
|
async def _async_setup_entity(config, async_add_entities, config_entry,
|
||||||
discovery_hash=None):
|
discovery_hash=None):
|
||||||
"""Set up the MQTT vacuum."""
|
"""Set up the MQTT vacuum."""
|
||||||
async_add_entities([MqttVacuum(config, discovery_hash)])
|
async_add_entities([MqttVacuum(config, config_entry, discovery_hash)])
|
||||||
|
|
||||||
|
|
||||||
# pylint: disable=too-many-ancestors
|
# pylint: disable=too-many-ancestors
|
||||||
@ -181,7 +181,7 @@ class MqttVacuum(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
|
|||||||
MqttEntityDeviceInfo, VacuumDevice):
|
MqttEntityDeviceInfo, VacuumDevice):
|
||||||
"""Representation of a MQTT-controlled vacuum."""
|
"""Representation of a MQTT-controlled vacuum."""
|
||||||
|
|
||||||
def __init__(self, config, discovery_info):
|
def __init__(self, config, config_entry, discovery_info):
|
||||||
"""Initialize the vacuum."""
|
"""Initialize the vacuum."""
|
||||||
self._cleaning = False
|
self._cleaning = False
|
||||||
self._charging = False
|
self._charging = False
|
||||||
@ -203,7 +203,7 @@ class MqttVacuum(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
|
|||||||
MqttAvailability.__init__(self, config)
|
MqttAvailability.__init__(self, config)
|
||||||
MqttDiscoveryUpdate.__init__(self, discovery_info,
|
MqttDiscoveryUpdate.__init__(self, discovery_info,
|
||||||
self.discovery_update)
|
self.discovery_update)
|
||||||
MqttEntityDeviceInfo.__init__(self, device_config)
|
MqttEntityDeviceInfo.__init__(self, device_config, config_entry)
|
||||||
|
|
||||||
def _setup_from_config(self, config):
|
def _setup_from_config(self, config):
|
||||||
self._name = config.get(CONF_NAME)
|
self._name = config.get(CONF_NAME)
|
||||||
@ -257,6 +257,7 @@ class MqttVacuum(MqttAttributes, MqttAvailability, MqttDiscoveryUpdate,
|
|||||||
self._setup_from_config(config)
|
self._setup_from_config(config)
|
||||||
await self.attributes_discovery_update(config)
|
await self.attributes_discovery_update(config)
|
||||||
await self.availability_discovery_update(config)
|
await self.availability_discovery_update(config)
|
||||||
|
await self.device_info_discovery_update(config)
|
||||||
await self._subscribe_topics()
|
await self._subscribe_topics()
|
||||||
self.async_schedule_update_ha_state()
|
self.async_schedule_update_ha_state()
|
||||||
|
|
||||||
|
@ -494,3 +494,50 @@ async def test_entity_device_info_with_identifier(hass, mock_publish):
|
|||||||
assert device.name == 'Beer'
|
assert device.name == 'Beer'
|
||||||
assert device.model == 'Glass'
|
assert device.model == 'Glass'
|
||||||
assert device.sw_version == '0.1-beta'
|
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/vacuum/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/vacuum/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'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user