diff --git a/homeassistant/components/canary/camera.py b/homeassistant/components/canary/camera.py index 5263f852621..bbf1284c602 100644 --- a/homeassistant/components/canary/camera.py +++ b/homeassistant/components/canary/camera.py @@ -24,6 +24,7 @@ from .const import ( DEFAULT_FFMPEG_ARGUMENTS, DEFAULT_TIMEOUT, DOMAIN, + MANUFACTURER, ) _LOGGER = logging.getLogger(__name__) @@ -77,18 +78,31 @@ class CanaryCamera(Camera): self._data = data self._location = location self._device = device + self._device_id = device.device_id + self._device_name = device.name + self._device_type_name = device.device_type["name"] self._timeout = timeout self._live_stream_session = None @property def name(self): """Return the name of this device.""" - return self._device.name + return self._device_name @property def unique_id(self): """Return the unique ID of this camera.""" - return str(self._device.device_id) + return str(self._device_id) + + @property + def device_info(self): + """Return the device_info of the device.""" + return { + "identifiers": {(DOMAIN, str(self._device_id))}, + "name": self._device_name, + "model": self._device_type_name, + "manufacturer": MANUFACTURER, + } @property def is_recording(self): diff --git a/homeassistant/components/canary/const.py b/homeassistant/components/canary/const.py index 4a4da9a3c8d..e6e3dbb73c9 100644 --- a/homeassistant/components/canary/const.py +++ b/homeassistant/components/canary/const.py @@ -2,6 +2,8 @@ DOMAIN = "canary" +MANUFACTURER = "Canary Connect, Inc" + # Configuration CONF_FFMPEG_ARGUMENTS = "ffmpeg_arguments" diff --git a/homeassistant/components/canary/sensor.py b/homeassistant/components/canary/sensor.py index e3e6549e88f..acf44457cbf 100644 --- a/homeassistant/components/canary/sensor.py +++ b/homeassistant/components/canary/sensor.py @@ -16,7 +16,7 @@ from homeassistant.helpers.entity import Entity from homeassistant.helpers.typing import HomeAssistantType from . import CanaryData -from .const import DATA_CANARY, DOMAIN +from .const import DATA_CANARY, DOMAIN, MANUFACTURER SENSOR_VALUE_PRECISION = 2 ATTR_AIR_QUALITY = "air_quality" @@ -73,6 +73,8 @@ class CanarySensor(Entity): self._data = data self._sensor_type = sensor_type self._device_id = device.device_id + self._device_name = device.name + self._device_type_name = device.device_type["name"] self._sensor_value = None sensor_type_name = sensor_type[0].replace("_", " ").title() @@ -93,6 +95,16 @@ class CanarySensor(Entity): """Return the unique ID of this sensor.""" return f"{self._device_id}_{self._sensor_type[0]}" + @property + def device_info(self): + """Return the device_info of the device.""" + return { + "identifiers": {(DOMAIN, str(self._device_id))}, + "name": self._device_name, + "model": self._device_type_name, + "manufacturer": MANUFACTURER, + } + @property def unit_of_measurement(self): """Return the unit of measurement.""" diff --git a/tests/components/canary/test_sensor.py b/tests/components/canary/test_sensor.py index b5c8ecb6837..13b82c9a996 100644 --- a/tests/components/canary/test_sensor.py +++ b/tests/components/canary/test_sensor.py @@ -1,5 +1,5 @@ """The tests for the Canary sensor platform.""" -from homeassistant.components.canary import DOMAIN +from homeassistant.components.canary.const import DOMAIN, MANUFACTURER from homeassistant.components.canary.sensor import ( ATTR_AIR_QUALITY, STATE_AIR_QUALITY_ABNORMAL, @@ -20,7 +20,7 @@ from homeassistant.setup import async_setup_component from . import mock_device, mock_location, mock_reading from tests.async_mock import patch -from tests.common import mock_registry +from tests.common import mock_device_registry, mock_registry async def test_sensors_pro(hass, canary) -> None: @@ -28,6 +28,8 @@ async def test_sensors_pro(hass, canary) -> None: await async_setup_component(hass, "persistent_notification", {}) registry = mock_registry(hass) + device_registry = mock_device_registry(hass) + online_device_at_home = mock_device(20, "Dining Room", True, "Canary Pro") instance = canary.return_value @@ -82,6 +84,12 @@ async def test_sensors_pro(hass, canary) -> None: assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == data[2] assert state.state == data[1] + device = device_registry.async_get_device({(DOMAIN, "20")}, set()) + assert device + assert device.manufacturer == MANUFACTURER + assert device.name == "Dining Room" + assert device.model == "Canary Pro" + async def test_sensors_attributes_pro(hass, canary) -> None: """Test the creation and values of the sensors attributes for Canary Pro.""" @@ -142,6 +150,8 @@ async def test_sensors_flex(hass, canary) -> None: await async_setup_component(hass, "persistent_notification", {}) registry = mock_registry(hass) + device_registry = mock_device_registry(hass) + online_device_at_home = mock_device(20, "Dining Room", True, "Canary Flex") instance = canary.return_value @@ -187,3 +197,9 @@ async def test_sensors_flex(hass, canary) -> None: assert state assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == data[2] assert state.state == data[1] + + device = device_registry.async_get_device({(DOMAIN, "20")}, set()) + assert device + assert device.manufacturer == MANUFACTURER + assert device.name == "Dining Room" + assert device.model == "Canary Flex"