Use new DeviceClass enums in ezviz (#61383)

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
epenet 2021-12-10 09:54:58 +01:00 committed by GitHub
parent dd6b179549
commit 412e531096
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 14 deletions

View File

@ -2,8 +2,7 @@
from __future__ import annotations from __future__ import annotations
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import (
DEVICE_CLASS_MOTION, BinarySensorDeviceClass,
DEVICE_CLASS_UPDATE,
BinarySensorEntity, BinarySensorEntity,
BinarySensorEntityDescription, BinarySensorEntityDescription,
) )
@ -20,7 +19,7 @@ PARALLEL_UPDATES = 1
BINARY_SENSOR_TYPES: dict[str, BinarySensorEntityDescription] = { BINARY_SENSOR_TYPES: dict[str, BinarySensorEntityDescription] = {
"Motion_Trigger": BinarySensorEntityDescription( "Motion_Trigger": BinarySensorEntityDescription(
key="Motion_Trigger", key="Motion_Trigger",
device_class=DEVICE_CLASS_MOTION, device_class=BinarySensorDeviceClass.MOTION,
), ),
"alarm_schedules_enabled": BinarySensorEntityDescription( "alarm_schedules_enabled": BinarySensorEntityDescription(
key="alarm_schedules_enabled" key="alarm_schedules_enabled"
@ -28,7 +27,7 @@ BINARY_SENSOR_TYPES: dict[str, BinarySensorEntityDescription] = {
"encrypted": BinarySensorEntityDescription(key="encrypted"), "encrypted": BinarySensorEntityDescription(key="encrypted"),
"upgrade_available": BinarySensorEntityDescription( "upgrade_available": BinarySensorEntityDescription(
key="upgrade_available", key="upgrade_available",
device_class=DEVICE_CLASS_UPDATE, device_class=BinarySensorDeviceClass.UPDATE,
), ),
} }

View File

@ -1,10 +1,13 @@
"""Support for Ezviz sensors.""" """Support for Ezviz sensors."""
from __future__ import annotations from __future__ import annotations
from homeassistant.components.binary_sensor import DEVICE_CLASS_MOTION from homeassistant.components.sensor import (
from homeassistant.components.sensor import SensorEntity, SensorEntityDescription SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
)
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DEVICE_CLASS_BATTERY, PERCENTAGE from homeassistant.const import PERCENTAGE
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -19,7 +22,7 @@ SENSOR_TYPES: dict[str, SensorEntityDescription] = {
"battery_level": SensorEntityDescription( "battery_level": SensorEntityDescription(
key="battery_level", key="battery_level",
native_unit_of_measurement=PERCENTAGE, native_unit_of_measurement=PERCENTAGE,
device_class=DEVICE_CLASS_BATTERY, device_class=SensorDeviceClass.BATTERY,
), ),
"alarm_sound_mod": SensorEntityDescription(key="alarm_sound_mod"), "alarm_sound_mod": SensorEntityDescription(key="alarm_sound_mod"),
"detection_sensibility": SensorEntityDescription(key="detection_sensibility"), "detection_sensibility": SensorEntityDescription(key="detection_sensibility"),
@ -32,10 +35,7 @@ SENSOR_TYPES: dict[str, SensorEntityDescription] = {
"supported_channels": SensorEntityDescription(key="supported_channels"), "supported_channels": SensorEntityDescription(key="supported_channels"),
"local_ip": SensorEntityDescription(key="local_ip"), "local_ip": SensorEntityDescription(key="local_ip"),
"wan_ip": SensorEntityDescription(key="wan_ip"), "wan_ip": SensorEntityDescription(key="wan_ip"),
"PIR_Status": SensorEntityDescription( "PIR_Status": SensorEntityDescription(key="PIR_Status"),
key="PIR_Status",
device_class=DEVICE_CLASS_MOTION,
),
"last_alarm_type_code": SensorEntityDescription(key="last_alarm_type_code"), "last_alarm_type_code": SensorEntityDescription(key="last_alarm_type_code"),
"last_alarm_type_name": SensorEntityDescription(key="last_alarm_type_name"), "last_alarm_type_name": SensorEntityDescription(key="last_alarm_type_name"),
} }

View File

@ -6,7 +6,7 @@ from typing import Any
from pyezviz.constants import DeviceSwitchType from pyezviz.constants import DeviceSwitchType
from pyezviz.exceptions import HTTPError, PyEzvizError from pyezviz.exceptions import HTTPError, PyEzvizError
from homeassistant.components.switch import DEVICE_CLASS_SWITCH, SwitchEntity from homeassistant.components.switch import SwitchDeviceClass, SwitchEntity
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -40,7 +40,7 @@ class EzvizSwitch(EzvizEntity, SwitchEntity):
"""Representation of a Ezviz sensor.""" """Representation of a Ezviz sensor."""
coordinator: EzvizDataUpdateCoordinator coordinator: EzvizDataUpdateCoordinator
ATTR_DEVICE_CLASS = DEVICE_CLASS_SWITCH _attr_device_class = SwitchDeviceClass.SWITCH
def __init__( def __init__(
self, coordinator: EzvizDataUpdateCoordinator, serial: str, switch: str self, coordinator: EzvizDataUpdateCoordinator, serial: str, switch: str