Add Reolink battery entities (#117506)
* add battery sensors * Disable Battery Temperature and State by default * fix mypy * Use device class for icon
This commit is contained in:
parent
68b7302cdc
commit
f788f88052
3 changed files with 59 additions and 3 deletions
|
@ -203,6 +203,12 @@
|
||||||
"ptz_pan_position": {
|
"ptz_pan_position": {
|
||||||
"default": "mdi:pan"
|
"default": "mdi:pan"
|
||||||
},
|
},
|
||||||
|
"battery_temperature": {
|
||||||
|
"default": "mdi:thermometer"
|
||||||
|
},
|
||||||
|
"battery_state": {
|
||||||
|
"default": "mdi:battery-charging"
|
||||||
|
},
|
||||||
"wifi_signal": {
|
"wifi_signal": {
|
||||||
"default": "mdi:wifi"
|
"default": "mdi:wifi"
|
||||||
},
|
},
|
||||||
|
|
|
@ -8,14 +8,16 @@ from datetime import date, datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
from reolink_aio.api import Host
|
from reolink_aio.api import Host
|
||||||
|
from reolink_aio.enums import BatteryEnum
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import (
|
||||||
|
SensorDeviceClass,
|
||||||
SensorEntity,
|
SensorEntity,
|
||||||
SensorEntityDescription,
|
SensorEntityDescription,
|
||||||
SensorStateClass,
|
SensorStateClass,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import ConfigEntry
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.const import PERCENTAGE, EntityCategory
|
from homeassistant.const import PERCENTAGE, EntityCategory, UnitOfTemperature
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.typing import StateType
|
from homeassistant.helpers.typing import StateType
|
||||||
|
@ -37,7 +39,7 @@ class ReolinkSensorEntityDescription(
|
||||||
):
|
):
|
||||||
"""A class that describes sensor entities for a camera channel."""
|
"""A class that describes sensor entities for a camera channel."""
|
||||||
|
|
||||||
value: Callable[[Host, int], int | float]
|
value: Callable[[Host, int], StateType]
|
||||||
|
|
||||||
|
|
||||||
@dataclass(frozen=True, kw_only=True)
|
@dataclass(frozen=True, kw_only=True)
|
||||||
|
@ -47,7 +49,7 @@ class ReolinkHostSensorEntityDescription(
|
||||||
):
|
):
|
||||||
"""A class that describes host sensor entities."""
|
"""A class that describes host sensor entities."""
|
||||||
|
|
||||||
value: Callable[[Host], int | None]
|
value: Callable[[Host], StateType]
|
||||||
|
|
||||||
|
|
||||||
SENSORS = (
|
SENSORS = (
|
||||||
|
@ -60,6 +62,40 @@ SENSORS = (
|
||||||
value=lambda api, ch: api.ptz_pan_position(ch),
|
value=lambda api, ch: api.ptz_pan_position(ch),
|
||||||
supported=lambda api, ch: api.supported(ch, "ptz_position"),
|
supported=lambda api, ch: api.supported(ch, "ptz_position"),
|
||||||
),
|
),
|
||||||
|
ReolinkSensorEntityDescription(
|
||||||
|
key="battery_percent",
|
||||||
|
cmd_key="GetBatteryInfo",
|
||||||
|
translation_key="battery_percent",
|
||||||
|
native_unit_of_measurement=PERCENTAGE,
|
||||||
|
device_class=SensorDeviceClass.BATTERY,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
value=lambda api, ch: api.battery_percentage(ch),
|
||||||
|
supported=lambda api, ch: api.supported(ch, "battery"),
|
||||||
|
),
|
||||||
|
ReolinkSensorEntityDescription(
|
||||||
|
key="battery_temperature",
|
||||||
|
cmd_key="GetBatteryInfo",
|
||||||
|
translation_key="battery_temperature",
|
||||||
|
native_unit_of_measurement=UnitOfTemperature.CELSIUS,
|
||||||
|
device_class=SensorDeviceClass.TEMPERATURE,
|
||||||
|
state_class=SensorStateClass.MEASUREMENT,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
value=lambda api, ch: api.battery_temperature(ch),
|
||||||
|
supported=lambda api, ch: api.supported(ch, "battery"),
|
||||||
|
),
|
||||||
|
ReolinkSensorEntityDescription(
|
||||||
|
key="battery_state",
|
||||||
|
cmd_key="GetBatteryInfo",
|
||||||
|
translation_key="battery_state",
|
||||||
|
device_class=SensorDeviceClass.ENUM,
|
||||||
|
entity_category=EntityCategory.DIAGNOSTIC,
|
||||||
|
entity_registry_enabled_default=False,
|
||||||
|
options=[state.name for state in BatteryEnum],
|
||||||
|
value=lambda api, ch: BatteryEnum(api.battery_status(ch)).name,
|
||||||
|
supported=lambda api, ch: api.supported(ch, "battery"),
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
HOST_SENSORS = (
|
HOST_SENSORS = (
|
||||||
|
|
|
@ -400,6 +400,20 @@
|
||||||
"ptz_pan_position": {
|
"ptz_pan_position": {
|
||||||
"name": "PTZ pan position"
|
"name": "PTZ pan position"
|
||||||
},
|
},
|
||||||
|
"battery_percent": {
|
||||||
|
"name": "Battery percentage"
|
||||||
|
},
|
||||||
|
"battery_temperature": {
|
||||||
|
"name": "Battery temperature"
|
||||||
|
},
|
||||||
|
"battery_state": {
|
||||||
|
"name": "Battery state",
|
||||||
|
"state": {
|
||||||
|
"discharging": "Discharging",
|
||||||
|
"charging": "Charging",
|
||||||
|
"chargecomplete": "Charge complete"
|
||||||
|
}
|
||||||
|
},
|
||||||
"hdd_storage": {
|
"hdd_storage": {
|
||||||
"name": "HDD {hdd_index} storage"
|
"name": "HDD {hdd_index} storage"
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue