Use new DeviceClass and EntityCategory enums in august (#61288)

Co-authored-by: epenet <epenet@users.noreply.github.com>
pull/61231/head
epenet 2021-12-08 22:15:15 +01:00 committed by GitHub
parent b2ae018837
commit 7c09cff3ad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 20 deletions

View File

@ -19,15 +19,12 @@ from yalexs.util import update_lock_detail_from_activity
from homeassistant.components.august import AugustData
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_CONNECTIVITY,
DEVICE_CLASS_DOOR,
DEVICE_CLASS_MOTION,
DEVICE_CLASS_OCCUPANCY,
BinarySensorDeviceClass,
BinarySensorEntity,
BinarySensorEntityDescription,
)
from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC
from homeassistant.core import callback
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.event import async_call_later
from .const import ACTIVITY_UPDATE_INTERVAL, DATA_AUGUST, DOMAIN
@ -115,22 +112,22 @@ SENSOR_TYPES_DOORBELL: tuple[AugustBinarySensorEntityDescription, ...] = (
AugustBinarySensorEntityDescription(
key="doorbell_ding",
name="Ding",
device_class=DEVICE_CLASS_OCCUPANCY,
device_class=BinarySensorDeviceClass.OCCUPANCY,
value_fn=_retrieve_ding_state,
is_time_based=True,
),
AugustBinarySensorEntityDescription(
key="doorbell_motion",
name="Motion",
device_class=DEVICE_CLASS_MOTION,
device_class=BinarySensorDeviceClass.MOTION,
value_fn=_retrieve_motion_state,
is_time_based=True,
),
AugustBinarySensorEntityDescription(
key="doorbell_online",
name="Online",
device_class=DEVICE_CLASS_CONNECTIVITY,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
device_class=BinarySensorDeviceClass.CONNECTIVITY,
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=_retrieve_online_state,
is_time_based=False,
),
@ -169,7 +166,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
class AugustDoorBinarySensor(AugustEntityMixin, BinarySensorEntity):
"""Representation of an August Door binary sensor."""
_attr_device_class = DEVICE_CLASS_DOOR
_attr_device_class = BinarySensorDeviceClass.DOOR
def __init__(self, data, device, description: BinarySensorEntityDescription):
"""Initialize the sensor."""

View File

@ -12,17 +12,13 @@ from yalexs.lock import LockDetail
from homeassistant.components.august import AugustData
from homeassistant.components.sensor import (
DEVICE_CLASS_BATTERY,
SensorDeviceClass,
SensorEntity,
SensorEntityDescription,
)
from homeassistant.const import (
ATTR_ENTITY_PICTURE,
ENTITY_CATEGORY_DIAGNOSTIC,
PERCENTAGE,
STATE_UNAVAILABLE,
)
from homeassistant.const import ATTR_ENTITY_PICTURE, PERCENTAGE, STATE_UNAVAILABLE
from homeassistant.core import callback
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_registry import async_get_registry
from homeassistant.helpers.restore_state import RestoreEntity
@ -73,14 +69,14 @@ class AugustSensorEntityDescription(
SENSOR_TYPE_DEVICE_BATTERY = AugustSensorEntityDescription[LockDetail](
key="device_battery",
name="Battery",
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=_retrieve_device_battery_state,
)
SENSOR_TYPE_KEYPAD_BATTERY = AugustSensorEntityDescription[KeypadDetail](
key="linked_keypad_battery",
name="Battery",
entity_category=ENTITY_CATEGORY_DIAGNOSTIC,
entity_category=EntityCategory.DIAGNOSTIC,
value_fn=_retrieve_linked_keypad_battery_state,
)
@ -254,7 +250,7 @@ class AugustBatterySensor(AugustEntityMixin, SensorEntity, Generic[T]):
"""Representation of an August sensor."""
entity_description: AugustSensorEntityDescription[T]
_attr_device_class = DEVICE_CLASS_BATTERY
_attr_device_class = SensorDeviceClass.BATTERY
_attr_native_unit_of_measurement = PERCENTAGE
def __init__(