mirror of
https://github.com/home-assistant/core.git
synced 2025-12-24 12:59:34 +00:00
Add device to mqtt camera (#26238)
* Add device to mqtt camera * Support discovery device info update and add tests
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
"""The tests for mqtt camera component."""
|
||||
from unittest.mock import ANY
|
||||
import json
|
||||
|
||||
from homeassistant.components import camera, mqtt
|
||||
from homeassistant.components.mqtt.discovery import async_start
|
||||
@@ -167,3 +168,79 @@ async def test_entity_id_update(hass, mqtt_mock):
|
||||
assert state is not None
|
||||
assert mock_mqtt.async_subscribe.call_count == 1
|
||||
mock_mqtt.async_subscribe.assert_any_call("test-topic", ANY, 0, None)
|
||||
|
||||
|
||||
async def test_entity_device_info_with_identifier(hass, mqtt_mock):
|
||||
"""Test MQTT camera 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",
|
||||
"topic": "test-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/camera/bla/config", data)
|
||||
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"
|
||||
|
||||
|
||||
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",
|
||||
"topic": "test-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/camera/bla/config", data)
|
||||
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/camera/bla/config", data)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
device = registry.async_get_device({("mqtt", "helloworld")}, set())
|
||||
assert device is not None
|
||||
assert device.name == "Milk"
|
||||
|
||||
Reference in New Issue
Block a user