Add device registry information to Blink entities (#62449)

This commit is contained in:
Jonathan Keslin 2021-12-21 03:06:08 -08:00 committed by GitHub
parent ed9e17aeec
commit eb897c6f48
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 37 additions and 3 deletions

View File

@ -8,8 +8,9 @@ from homeassistant.const import (
STATE_ALARM_ARMED_AWAY, STATE_ALARM_ARMED_AWAY,
STATE_ALARM_DISARMED, STATE_ALARM_DISARMED,
) )
from homeassistant.helpers.entity import DeviceInfo
from .const import DEFAULT_ATTRIBUTION, DOMAIN from .const import DEFAULT_ATTRIBUTION, DEFAULT_BRAND, DOMAIN
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -39,6 +40,9 @@ class BlinkSyncModule(AlarmControlPanelEntity):
self._name = name self._name = name
self._attr_unique_id = sync.serial self._attr_unique_id = sync.serial
self._attr_name = f"{DOMAIN} {name}" self._attr_name = f"{DOMAIN} {name}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, sync.serial)}, name=name, manufacturer=DEFAULT_BRAND
)
def update(self): def update(self):
"""Update the state of the device.""" """Update the state of the device."""

View File

@ -6,14 +6,22 @@ from homeassistant.components.binary_sensor import (
BinarySensorEntity, BinarySensorEntity,
BinarySensorEntityDescription, BinarySensorEntityDescription,
) )
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
from .const import DOMAIN, TYPE_BATTERY, TYPE_CAMERA_ARMED, TYPE_MOTION_DETECTED from .const import (
DEFAULT_BRAND,
DOMAIN,
TYPE_BATTERY,
TYPE_CAMERA_ARMED,
TYPE_MOTION_DETECTED,
)
BINARY_SENSORS_TYPES: tuple[BinarySensorEntityDescription, ...] = ( BINARY_SENSORS_TYPES: tuple[BinarySensorEntityDescription, ...] = (
BinarySensorEntityDescription( BinarySensorEntityDescription(
key=TYPE_BATTERY, key=TYPE_BATTERY,
name="Battery", name="Battery",
device_class=BinarySensorDeviceClass.BATTERY, device_class=BinarySensorDeviceClass.BATTERY,
entity_category=EntityCategory.DIAGNOSTIC,
), ),
BinarySensorEntityDescription( BinarySensorEntityDescription(
key=TYPE_CAMERA_ARMED, key=TYPE_CAMERA_ARMED,
@ -49,6 +57,12 @@ class BlinkBinarySensor(BinarySensorEntity):
self._attr_name = f"{DOMAIN} {camera} {description.name}" self._attr_name = f"{DOMAIN} {camera} {description.name}"
self._camera = data.cameras[camera] self._camera = data.cameras[camera]
self._attr_unique_id = f"{self._camera.serial}-{description.key}" self._attr_unique_id = f"{self._camera.serial}-{description.key}"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self._camera.serial)},
name=camera,
manufacturer=DEFAULT_BRAND,
model=self._camera.camera_type,
)
def update(self): def update(self):
"""Update sensor state.""" """Update sensor state."""

View File

@ -5,6 +5,7 @@ import logging
from homeassistant.components.camera import Camera from homeassistant.components.camera import Camera
from homeassistant.helpers import entity_platform from homeassistant.helpers import entity_platform
from homeassistant.helpers.entity import DeviceInfo
from .const import DEFAULT_BRAND, DOMAIN, SERVICE_TRIGGER from .const import DEFAULT_BRAND, DOMAIN, SERVICE_TRIGGER
@ -37,6 +38,12 @@ class BlinkCamera(Camera):
self._attr_name = f"{DOMAIN} {name}" self._attr_name = f"{DOMAIN} {name}"
self._camera = camera self._camera = camera
self._attr_unique_id = f"{camera.serial}-camera" self._attr_unique_id = f"{camera.serial}-camera"
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, camera.serial)},
name=name,
manufacturer=DEFAULT_BRAND,
model=camera.camera_type,
)
_LOGGER.debug("Initialized blink camera %s", self.name) _LOGGER.debug("Initialized blink camera %s", self.name)
@property @property

View File

@ -9,8 +9,9 @@ from homeassistant.components.sensor import (
SensorEntityDescription, SensorEntityDescription,
) )
from homeassistant.const import SIGNAL_STRENGTH_DECIBELS_MILLIWATT, TEMP_FAHRENHEIT from homeassistant.const import SIGNAL_STRENGTH_DECIBELS_MILLIWATT, TEMP_FAHRENHEIT
from homeassistant.helpers.entity import DeviceInfo, EntityCategory
from .const import DOMAIN, TYPE_TEMPERATURE, TYPE_WIFI_STRENGTH from .const import DEFAULT_BRAND, DOMAIN, TYPE_TEMPERATURE, TYPE_WIFI_STRENGTH
_LOGGER = logging.getLogger(__name__) _LOGGER = logging.getLogger(__name__)
@ -20,12 +21,14 @@ SENSOR_TYPES: tuple[SensorEntityDescription, ...] = (
name="Temperature", name="Temperature",
native_unit_of_measurement=TEMP_FAHRENHEIT, native_unit_of_measurement=TEMP_FAHRENHEIT,
device_class=SensorDeviceClass.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE,
entity_category=EntityCategory.DIAGNOSTIC,
), ),
SensorEntityDescription( SensorEntityDescription(
key=TYPE_WIFI_STRENGTH, key=TYPE_WIFI_STRENGTH,
name="Wifi Signal", name="Wifi Signal",
native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT, native_unit_of_measurement=SIGNAL_STRENGTH_DECIBELS_MILLIWATT,
device_class=SensorDeviceClass.SIGNAL_STRENGTH, device_class=SensorDeviceClass.SIGNAL_STRENGTH,
entity_category=EntityCategory.DIAGNOSTIC,
), ),
) )
@ -57,6 +60,12 @@ class BlinkSensor(SensorEntity):
if description.key == "temperature" if description.key == "temperature"
else description.key else description.key
) )
self._attr_device_info = DeviceInfo(
identifiers={(DOMAIN, self._camera.serial)},
name=camera,
manufacturer=DEFAULT_BRAND,
model=self._camera.camera_type,
)
def update(self): def update(self):
"""Retrieve sensor data from the camera.""" """Retrieve sensor data from the camera."""