Migrate binary sensor device classes to StrEnum (#60651)

This commit is contained in:
Franck Nijhof 2021-12-01 08:12:09 +01:00 committed by GitHub
parent 12ff5dee74
commit 2b8f245e27
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 135 additions and 102 deletions

View file

@ -1,7 +1,6 @@
"""Demo platform that has two fake binary sensors."""
from homeassistant.components.binary_sensor import (
DEVICE_CLASS_MOISTURE,
DEVICE_CLASS_MOTION,
BinarySensorDeviceClass,
BinarySensorEntity,
)
from homeassistant.helpers.entity import DeviceInfo
@ -14,10 +13,13 @@ async def async_setup_platform(hass, config, async_add_entities, discovery_info=
async_add_entities(
[
DemoBinarySensor(
"binary_1", "Basement Floor Wet", False, DEVICE_CLASS_MOISTURE
"binary_1",
"Basement Floor Wet",
False,
BinarySensorDeviceClass.MOISTURE,
),
DemoBinarySensor(
"binary_2", "Movement Backyard", True, DEVICE_CLASS_MOTION
"binary_2", "Movement Backyard", True, BinarySensorDeviceClass.MOTION
),
]
)
@ -31,7 +33,13 @@ async def async_setup_entry(hass, config_entry, async_add_entities):
class DemoBinarySensor(BinarySensorEntity):
"""representation of a Demo binary sensor."""
def __init__(self, unique_id, name, state, device_class):
def __init__(
self,
unique_id: str,
name: str,
state: bool,
device_class: BinarySensorDeviceClass,
) -> None:
"""Initialize the demo sensor."""
self._unique_id = unique_id
self._name = name
@ -55,7 +63,7 @@ class DemoBinarySensor(BinarySensorEntity):
return self._unique_id
@property
def device_class(self):
def device_class(self) -> BinarySensorDeviceClass:
"""Return the class of this sensor."""
return self._sensor_type