Implement base for MQTT device registry integration#16943
Implement base for MQTT device registry integration#16943balloob merged 8 commits intohome-assistant:devfrom
Conversation
tests/components/sensor/test_mqtt.py
Outdated
| assert device.name == 'Beer' | ||
| assert device.model == 'Glass' | ||
| assert device.sw_version == '0.1-beta' | ||
|
|
| vol.Optional(CONF_CONNECTIONS, default=list): | ||
| vol.All(cv.ensure_list, [vol.Schema({ | ||
| vol.Required(CONF_TYPE): vol.Any(*device_registry.CONNECTION_KEYS), | ||
| vol.Required(CONF_IDENTIFIER): cv.string, |
There was a problem hiding this comment.
I don't really like the name of this option (identifier) in this context. Its name (base off of https://developers.home-assistant.io/docs/en/device_registry_index.html) is very close to the identifiers option but it has a totally different format. Should this be renamed to value or should it rather stick to the dev docs' identifier?
There was a problem hiding this comment.
Why is this a dict to begin with?
There was a problem hiding this comment.
Well primarily to make it more consistent with the device registry naming. One option would be:
{
...
"device": {
"connections": {
"mac": "F7:19:18:29:93:1A",
"other": "connection_id"
}
}
}but that would for example not support devices with multiple MAC addresses (probably doesn't come up too often, but I think it's good to support it from the start to prevent breaking changes).
The other option would be:
{
...
"device": {
"connections": [
{"mac": "F7:19:18:29:93:1A"},
{"mac": "E8:2A:29:3A:A4:2B"}
]
}
}or:
{
...
"device": {
"connections": [
["mac", "F7:19:18:29:93:1A"],
["mac", "E8:2A:29:3A:A4:2B"]
]
}
}There was a problem hiding this comment.
I like the last one. That is also how we store it internally.
| from homeassistant.core import Event, ServiceCall, callback | ||
| from homeassistant.exceptions import HomeAssistantError | ||
| from homeassistant.helpers import config_validation as cv | ||
| from homeassistant.helpers import config_validation as cv, device_registry |
There was a problem hiding this comment.
'homeassistant.helpers.device_registry' imported but unused
Description:
Now after #16918, we can start implementing the device registry for MQTT platforms. This PR adds a new parameter to the MQTT config of
sensors:device. With this, MQTT-enabled devices can send along adevice:section in the MQTT discovery payload which uniquely identifies the device.This PR only adds the device registry feature to the
sensor.mqttplatform as a sample implementation, but others will follow once this PR is done.A discovery payload could for example look like this:
{ "name": "...", ... "unique_id": "veryunique", "device": { "identifiers": ["my_identifier"], "connections": [{ "type": "mac", "identifier": "F7:19:18:29:93:1A" }], "manufacturer": "espressif", "model": "ESP32", "name": "Cabinet", "sw_version": "1.8.0" } }Please note that this only works with devices that supply a
unique_idand only through MQTT discovery.Pull request in home-assistant.io with documentation (if applicable): home-assistant/home-assistant.io#6513
Checklist:
tox. Your PR cannot be merged unless tests passIf user exposed functionality or configuration variables are added/changed:
If the code does not interact with devices: