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

Co-authored-by: epenet <epenet@users.noreply.github.com>
This commit is contained in:
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.august import AugustData
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import (
DEVICE_CLASS_CONNECTIVITY, BinarySensorDeviceClass,
DEVICE_CLASS_DOOR,
DEVICE_CLASS_MOTION,
DEVICE_CLASS_OCCUPANCY,
BinarySensorEntity, BinarySensorEntity,
BinarySensorEntityDescription, BinarySensorEntityDescription,
) )
from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC
from homeassistant.core import callback from homeassistant.core import callback
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.event import async_call_later from homeassistant.helpers.event import async_call_later
from .const import ACTIVITY_UPDATE_INTERVAL, DATA_AUGUST, DOMAIN from .const import ACTIVITY_UPDATE_INTERVAL, DATA_AUGUST, DOMAIN
@ -115,22 +112,22 @@ SENSOR_TYPES_DOORBELL: tuple[AugustBinarySensorEntityDescription, ...] = (
AugustBinarySensorEntityDescription( AugustBinarySensorEntityDescription(
key="doorbell_ding", key="doorbell_ding",
name="Ding", name="Ding",
device_class=DEVICE_CLASS_OCCUPANCY, device_class=BinarySensorDeviceClass.OCCUPANCY,
value_fn=_retrieve_ding_state, value_fn=_retrieve_ding_state,
is_time_based=True, is_time_based=True,
), ),
AugustBinarySensorEntityDescription( AugustBinarySensorEntityDescription(
key="doorbell_motion", key="doorbell_motion",
name="Motion", name="Motion",
device_class=DEVICE_CLASS_MOTION, device_class=BinarySensorDeviceClass.MOTION,
value_fn=_retrieve_motion_state, value_fn=_retrieve_motion_state,
is_time_based=True, is_time_based=True,
), ),
AugustBinarySensorEntityDescription( AugustBinarySensorEntityDescription(
key="doorbell_online", key="doorbell_online",
name="Online", name="Online",
device_class=DEVICE_CLASS_CONNECTIVITY, device_class=BinarySensorDeviceClass.CONNECTIVITY,
entity_category=ENTITY_CATEGORY_DIAGNOSTIC, entity_category=EntityCategory.DIAGNOSTIC,
value_fn=_retrieve_online_state, value_fn=_retrieve_online_state,
is_time_based=False, is_time_based=False,
), ),
@ -169,7 +166,7 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
class AugustDoorBinarySensor(AugustEntityMixin, BinarySensorEntity): class AugustDoorBinarySensor(AugustEntityMixin, BinarySensorEntity):
"""Representation of an August Door binary sensor.""" """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): def __init__(self, data, device, description: BinarySensorEntityDescription):
"""Initialize the sensor.""" """Initialize the sensor."""

View file

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