mirror of
https://github.com/home-assistant/core.git
synced 2025-04-29 03:37:51 +00:00
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:
parent
467a001e1f
commit
0c8b530aa2
@ -24,6 +24,7 @@ from .const import (
|
|||||||
DEFAULT_FFMPEG_ARGUMENTS,
|
DEFAULT_FFMPEG_ARGUMENTS,
|
||||||
DEFAULT_TIMEOUT,
|
DEFAULT_TIMEOUT,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
MANUFACTURER,
|
||||||
)
|
)
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -77,18 +78,31 @@ class CanaryCamera(Camera):
|
|||||||
self._data = data
|
self._data = data
|
||||||
self._location = location
|
self._location = location
|
||||||
self._device = device
|
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._timeout = timeout
|
||||||
self._live_stream_session = None
|
self._live_stream_session = None
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
"""Return the name of this device."""
|
"""Return the name of this device."""
|
||||||
return self._device.name
|
return self._device_name
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unique_id(self):
|
def unique_id(self):
|
||||||
"""Return the unique ID of this camera."""
|
"""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
|
@property
|
||||||
def is_recording(self):
|
def is_recording(self):
|
||||||
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
DOMAIN = "canary"
|
DOMAIN = "canary"
|
||||||
|
|
||||||
|
MANUFACTURER = "Canary Connect, Inc"
|
||||||
|
|
||||||
# Configuration
|
# Configuration
|
||||||
CONF_FFMPEG_ARGUMENTS = "ffmpeg_arguments"
|
CONF_FFMPEG_ARGUMENTS = "ffmpeg_arguments"
|
||||||
|
|
||||||
|
@ -16,7 +16,7 @@ from homeassistant.helpers.entity import Entity
|
|||||||
from homeassistant.helpers.typing import HomeAssistantType
|
from homeassistant.helpers.typing import HomeAssistantType
|
||||||
|
|
||||||
from . import CanaryData
|
from . import CanaryData
|
||||||
from .const import DATA_CANARY, DOMAIN
|
from .const import DATA_CANARY, DOMAIN, MANUFACTURER
|
||||||
|
|
||||||
SENSOR_VALUE_PRECISION = 2
|
SENSOR_VALUE_PRECISION = 2
|
||||||
ATTR_AIR_QUALITY = "air_quality"
|
ATTR_AIR_QUALITY = "air_quality"
|
||||||
@ -73,6 +73,8 @@ class CanarySensor(Entity):
|
|||||||
self._data = data
|
self._data = data
|
||||||
self._sensor_type = sensor_type
|
self._sensor_type = sensor_type
|
||||||
self._device_id = device.device_id
|
self._device_id = device.device_id
|
||||||
|
self._device_name = device.name
|
||||||
|
self._device_type_name = device.device_type["name"]
|
||||||
self._sensor_value = None
|
self._sensor_value = None
|
||||||
|
|
||||||
sensor_type_name = sensor_type[0].replace("_", " ").title()
|
sensor_type_name = sensor_type[0].replace("_", " ").title()
|
||||||
@ -93,6 +95,16 @@ class CanarySensor(Entity):
|
|||||||
"""Return the unique ID of this sensor."""
|
"""Return the unique ID of this sensor."""
|
||||||
return f"{self._device_id}_{self._sensor_type[0]}"
|
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
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Return the unit of measurement."""
|
"""Return the unit of measurement."""
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
"""The tests for the Canary sensor platform."""
|
"""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 (
|
from homeassistant.components.canary.sensor import (
|
||||||
ATTR_AIR_QUALITY,
|
ATTR_AIR_QUALITY,
|
||||||
STATE_AIR_QUALITY_ABNORMAL,
|
STATE_AIR_QUALITY_ABNORMAL,
|
||||||
@ -20,7 +20,7 @@ from homeassistant.setup import async_setup_component
|
|||||||
from . import mock_device, mock_location, mock_reading
|
from . import mock_device, mock_location, mock_reading
|
||||||
|
|
||||||
from tests.async_mock import patch
|
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:
|
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", {})
|
await async_setup_component(hass, "persistent_notification", {})
|
||||||
|
|
||||||
registry = mock_registry(hass)
|
registry = mock_registry(hass)
|
||||||
|
device_registry = mock_device_registry(hass)
|
||||||
|
|
||||||
online_device_at_home = mock_device(20, "Dining Room", True, "Canary Pro")
|
online_device_at_home = mock_device(20, "Dining Room", True, "Canary Pro")
|
||||||
|
|
||||||
instance = canary.return_value
|
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.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == data[2]
|
||||||
assert state.state == data[1]
|
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:
|
async def test_sensors_attributes_pro(hass, canary) -> None:
|
||||||
"""Test the creation and values of the sensors attributes for Canary Pro."""
|
"""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", {})
|
await async_setup_component(hass, "persistent_notification", {})
|
||||||
|
|
||||||
registry = mock_registry(hass)
|
registry = mock_registry(hass)
|
||||||
|
device_registry = mock_device_registry(hass)
|
||||||
|
|
||||||
online_device_at_home = mock_device(20, "Dining Room", True, "Canary Flex")
|
online_device_at_home = mock_device(20, "Dining Room", True, "Canary Flex")
|
||||||
|
|
||||||
instance = canary.return_value
|
instance = canary.return_value
|
||||||
@ -187,3 +197,9 @@ async def test_sensors_flex(hass, canary) -> None:
|
|||||||
assert state
|
assert state
|
||||||
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == data[2]
|
assert state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) == data[2]
|
||||||
assert state.state == data[1]
|
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"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user