mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 15:17:35 +00:00
Add device classes to Blink sensors (#35620)
* Add device classes, move battery sensor to binary_sensor * Remove cast to bool
This commit is contained in:
parent
599d3ae930
commit
97a523e854
@ -1,11 +1,16 @@
|
|||||||
"""Support for Blink system camera control."""
|
"""Support for Blink system camera control."""
|
||||||
from homeassistant.components.binary_sensor import BinarySensorEntity
|
from homeassistant.components.binary_sensor import (
|
||||||
|
DEVICE_CLASS_BATTERY,
|
||||||
|
DEVICE_CLASS_MOTION,
|
||||||
|
BinarySensorEntity,
|
||||||
|
)
|
||||||
|
|
||||||
from .const import DOMAIN, TYPE_CAMERA_ARMED, TYPE_MOTION_DETECTED
|
from .const import DOMAIN, TYPE_BATTERY, TYPE_CAMERA_ARMED, TYPE_MOTION_DETECTED
|
||||||
|
|
||||||
BINARY_SENSORS = {
|
BINARY_SENSORS = {
|
||||||
TYPE_CAMERA_ARMED: ["Camera Armed", "mdi:verified"],
|
TYPE_BATTERY: ["Battery", DEVICE_CLASS_BATTERY],
|
||||||
TYPE_MOTION_DETECTED: ["Motion Detected", "mdi:run-fast"],
|
TYPE_CAMERA_ARMED: ["Camera Armed", None],
|
||||||
|
TYPE_MOTION_DETECTED: ["Motion Detected", DEVICE_CLASS_MOTION],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -27,9 +32,9 @@ class BlinkBinarySensor(BinarySensorEntity):
|
|||||||
"""Initialize the sensor."""
|
"""Initialize the sensor."""
|
||||||
self.data = data
|
self.data = data
|
||||||
self._type = sensor_type
|
self._type = sensor_type
|
||||||
name, icon = BINARY_SENSORS[sensor_type]
|
name, device_class = BINARY_SENSORS[sensor_type]
|
||||||
self._name = f"{DOMAIN} {camera} {name}"
|
self._name = f"{DOMAIN} {camera} {name}"
|
||||||
self._icon = icon
|
self._device_class = device_class
|
||||||
self._camera = data.cameras[camera]
|
self._camera = data.cameras[camera]
|
||||||
self._state = None
|
self._state = None
|
||||||
self._unique_id = f"{self._camera.serial}-{self._type}"
|
self._unique_id = f"{self._camera.serial}-{self._type}"
|
||||||
@ -39,6 +44,11 @@ class BlinkBinarySensor(BinarySensorEntity):
|
|||||||
"""Return the name of the blink sensor."""
|
"""Return the name of the blink sensor."""
|
||||||
return self._name
|
return self._name
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self):
|
||||||
|
"""Return the class of this device."""
|
||||||
|
return self._device_class
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def is_on(self):
|
def is_on(self):
|
||||||
"""Return the status of the sensor."""
|
"""Return the status of the sensor."""
|
||||||
@ -47,4 +57,7 @@ class BlinkBinarySensor(BinarySensorEntity):
|
|||||||
def update(self):
|
def update(self):
|
||||||
"""Update sensor state."""
|
"""Update sensor state."""
|
||||||
self.data.refresh()
|
self.data.refresh()
|
||||||
self._state = self._camera.attributes[self._type]
|
state = self._camera.attributes[self._type]
|
||||||
|
if self._type == TYPE_BATTERY:
|
||||||
|
state = state != "ok"
|
||||||
|
self._state = state
|
||||||
|
@ -1,17 +1,20 @@
|
|||||||
"""Support for Blink system camera sensors."""
|
"""Support for Blink system camera sensors."""
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from homeassistant.const import TEMP_FAHRENHEIT
|
from homeassistant.const import (
|
||||||
|
DEVICE_CLASS_SIGNAL_STRENGTH,
|
||||||
|
DEVICE_CLASS_TEMPERATURE,
|
||||||
|
TEMP_FAHRENHEIT,
|
||||||
|
)
|
||||||
from homeassistant.helpers.entity import Entity
|
from homeassistant.helpers.entity import Entity
|
||||||
|
|
||||||
from .const import DOMAIN, TYPE_BATTERY, TYPE_TEMPERATURE, TYPE_WIFI_STRENGTH
|
from .const import DOMAIN, TYPE_TEMPERATURE, TYPE_WIFI_STRENGTH
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
|
|
||||||
SENSORS = {
|
SENSORS = {
|
||||||
TYPE_TEMPERATURE: ["Temperature", TEMP_FAHRENHEIT, "mdi:thermometer"],
|
TYPE_TEMPERATURE: ["Temperature", TEMP_FAHRENHEIT, DEVICE_CLASS_TEMPERATURE],
|
||||||
TYPE_BATTERY: ["Battery", "", "mdi:battery-80"],
|
TYPE_WIFI_STRENGTH: ["Wifi Signal", "dBm", DEVICE_CLASS_SIGNAL_STRENGTH],
|
||||||
TYPE_WIFI_STRENGTH: ["Wifi Signal", "dBm", "mdi:wifi-strength-2"],
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -31,15 +34,15 @@ class BlinkSensor(Entity):
|
|||||||
|
|
||||||
def __init__(self, data, camera, sensor_type):
|
def __init__(self, data, camera, sensor_type):
|
||||||
"""Initialize sensors from Blink camera."""
|
"""Initialize sensors from Blink camera."""
|
||||||
name, units, icon = SENSORS[sensor_type]
|
name, units, device_class = SENSORS[sensor_type]
|
||||||
self._name = f"{DOMAIN} {camera} {name}"
|
self._name = f"{DOMAIN} {camera} {name}"
|
||||||
self._camera_name = name
|
self._camera_name = name
|
||||||
self._type = sensor_type
|
self._type = sensor_type
|
||||||
|
self._device_class = device_class
|
||||||
self.data = data
|
self.data = data
|
||||||
self._camera = data.cameras[camera]
|
self._camera = data.cameras[camera]
|
||||||
self._state = None
|
self._state = None
|
||||||
self._unit_of_measurement = units
|
self._unit_of_measurement = units
|
||||||
self._icon = icon
|
|
||||||
self._unique_id = f"{self._camera.serial}-{self._type}"
|
self._unique_id = f"{self._camera.serial}-{self._type}"
|
||||||
self._sensor_key = self._type
|
self._sensor_key = self._type
|
||||||
if self._type == "temperature":
|
if self._type == "temperature":
|
||||||
@ -55,16 +58,16 @@ class BlinkSensor(Entity):
|
|||||||
"""Return the unique id for the camera sensor."""
|
"""Return the unique id for the camera sensor."""
|
||||||
return self._unique_id
|
return self._unique_id
|
||||||
|
|
||||||
@property
|
|
||||||
def icon(self):
|
|
||||||
"""Return the icon of the sensor."""
|
|
||||||
return self._icon
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def state(self):
|
def state(self):
|
||||||
"""Return the camera's current state."""
|
"""Return the camera's current state."""
|
||||||
return self._state
|
return self._state
|
||||||
|
|
||||||
|
@property
|
||||||
|
def device_class(self):
|
||||||
|
"""Return the device's class."""
|
||||||
|
return self._device_class
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def unit_of_measurement(self):
|
def unit_of_measurement(self):
|
||||||
"""Return the unit of measurement."""
|
"""Return the unit of measurement."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user