Add device info to canary camera and sensors (#40053)

* add device info to canary sensors

* Update test_sensor.py

* Update sensor.py

* Update sensor.py

* Update test_sensor.py

* Create const.py

* Update sensor.py

* Update test_sensor.py

* Update sensor.py

* Update test_sensor.py

* Update camera.py

* Update camera.py

* Update sensor.py

* Update camera.py

* Update camera.py
This commit is contained in:
Chris Talkington 2020-09-19 10:09:40 -05:00 committed by GitHub
parent 467a001e1f
commit 0c8b530aa2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 49 additions and 5 deletions

View file

@ -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):

View file

@ -2,6 +2,8 @@
DOMAIN = "canary"
MANUFACTURER = "Canary Connect, Inc"
# Configuration
CONF_FFMPEG_ARGUMENTS = "ffmpeg_arguments"

View file

@ -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."""

View file

@ -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"