Use enums in simplisafe (#62037)

pull/62067/head
Robert Hillis 2021-12-16 08:32:03 -05:00 committed by GitHub
parent 9ddf2035d0
commit 4983a8f218
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 21 deletions

View File

@ -6,18 +6,12 @@ from simplipy.device.sensor.v3 import SensorV3
from simplipy.system.v3 import SystemV3 from simplipy.system.v3 import SystemV3
from homeassistant.components.binary_sensor import ( from homeassistant.components.binary_sensor import (
DEVICE_CLASS_BATTERY, BinarySensorDeviceClass,
DEVICE_CLASS_DOOR,
DEVICE_CLASS_GAS,
DEVICE_CLASS_MOISTURE,
DEVICE_CLASS_MOTION,
DEVICE_CLASS_SAFETY,
DEVICE_CLASS_SMOKE,
BinarySensorEntity, BinarySensorEntity,
) )
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity import EntityCategory
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
from . import SimpliSafe, SimpliSafeEntity from . import SimpliSafe, SimpliSafeEntity
@ -36,13 +30,13 @@ SUPPORTED_BATTERY_SENSOR_TYPES = [
] ]
TRIGGERED_SENSOR_TYPES = { TRIGGERED_SENSOR_TYPES = {
DeviceTypes.CARBON_MONOXIDE: DEVICE_CLASS_GAS, DeviceTypes.CARBON_MONOXIDE: BinarySensorDeviceClass.GAS,
DeviceTypes.ENTRY: DEVICE_CLASS_DOOR, DeviceTypes.ENTRY: BinarySensorDeviceClass.DOOR,
DeviceTypes.GLASS_BREAK: DEVICE_CLASS_SAFETY, DeviceTypes.GLASS_BREAK: BinarySensorDeviceClass.SAFETY,
DeviceTypes.LEAK: DEVICE_CLASS_MOISTURE, DeviceTypes.LEAK: BinarySensorDeviceClass.MOISTURE,
DeviceTypes.MOTION: DEVICE_CLASS_MOTION, DeviceTypes.MOTION: BinarySensorDeviceClass.MOTION,
DeviceTypes.SIREN: DEVICE_CLASS_SAFETY, DeviceTypes.SIREN: BinarySensorDeviceClass.SAFETY,
DeviceTypes.SMOKE: DEVICE_CLASS_SMOKE, DeviceTypes.SMOKE: BinarySensorDeviceClass.SMOKE,
} }
@ -100,8 +94,8 @@ class TriggeredBinarySensor(SimpliSafeEntity, BinarySensorEntity):
class BatteryBinarySensor(SimpliSafeEntity, BinarySensorEntity): class BatteryBinarySensor(SimpliSafeEntity, BinarySensorEntity):
"""Define a SimpliSafe battery binary sensor entity.""" """Define a SimpliSafe battery binary sensor entity."""
_attr_device_class = DEVICE_CLASS_BATTERY _attr_device_class = BinarySensorDeviceClass.BATTERY
_attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC _attr_entity_category = EntityCategory.DIAGNOSTIC
def __init__( def __init__(
self, simplisafe: SimpliSafe, system: SystemV3, sensor: SensorV3 self, simplisafe: SimpliSafe, system: SystemV3, sensor: SensorV3

View File

@ -5,9 +5,13 @@ from simplipy.device import DeviceTypes
from simplipy.device.sensor.v3 import SensorV3 from simplipy.device.sensor.v3 import SensorV3
from simplipy.system.v3 import SystemV3 from simplipy.system.v3 import SystemV3
from homeassistant.components.sensor import STATE_CLASS_MEASUREMENT, SensorEntity from homeassistant.components.sensor import (
SensorDeviceClass,
SensorEntity,
SensorStateClass,
)
from homeassistant.config_entries import ConfigEntry from homeassistant.config_entries import ConfigEntry
from homeassistant.const import DEVICE_CLASS_TEMPERATURE, TEMP_FAHRENHEIT from homeassistant.const import TEMP_FAHRENHEIT
from homeassistant.core import HomeAssistant, callback from homeassistant.core import HomeAssistant, callback
from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.entity_platform import AddEntitiesCallback
@ -37,9 +41,9 @@ async def async_setup_entry(
class SimplisafeFreezeSensor(SimpliSafeEntity, SensorEntity): class SimplisafeFreezeSensor(SimpliSafeEntity, SensorEntity):
"""Define a SimpliSafe freeze sensor entity.""" """Define a SimpliSafe freeze sensor entity."""
_attr_device_class = DEVICE_CLASS_TEMPERATURE _attr_device_class = SensorDeviceClass.TEMPERATURE
_attr_native_unit_of_measurement = TEMP_FAHRENHEIT _attr_native_unit_of_measurement = TEMP_FAHRENHEIT
_attr_state_class = STATE_CLASS_MEASUREMENT _attr_state_class = SensorStateClass.MEASUREMENT
def __init__( def __init__(
self, simplisafe: SimpliSafe, system: SystemV3, sensor: SensorV3 self, simplisafe: SimpliSafe, system: SystemV3, sensor: SensorV3