From 4983a8f2187188ef5bd3735ce4c0a4a5736f6aa3 Mon Sep 17 00:00:00 2001 From: Robert Hillis Date: Thu, 16 Dec 2021 08:32:03 -0500 Subject: [PATCH] Use enums in simplisafe (#62037) --- .../components/simplisafe/binary_sensor.py | 28 ++++++++----------- homeassistant/components/simplisafe/sensor.py | 12 +++++--- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/homeassistant/components/simplisafe/binary_sensor.py b/homeassistant/components/simplisafe/binary_sensor.py index 240ff24c6c8..3e4c64e8658 100644 --- a/homeassistant/components/simplisafe/binary_sensor.py +++ b/homeassistant/components/simplisafe/binary_sensor.py @@ -6,18 +6,12 @@ from simplipy.device.sensor.v3 import SensorV3 from simplipy.system.v3 import SystemV3 from homeassistant.components.binary_sensor import ( - DEVICE_CLASS_BATTERY, - DEVICE_CLASS_DOOR, - DEVICE_CLASS_GAS, - DEVICE_CLASS_MOISTURE, - DEVICE_CLASS_MOTION, - DEVICE_CLASS_SAFETY, - DEVICE_CLASS_SMOKE, + BinarySensorDeviceClass, BinarySensorEntity, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ENTITY_CATEGORY_DIAGNOSTIC from homeassistant.core import HomeAssistant, callback +from homeassistant.helpers.entity import EntityCategory from homeassistant.helpers.entity_platform import AddEntitiesCallback from . import SimpliSafe, SimpliSafeEntity @@ -36,13 +30,13 @@ SUPPORTED_BATTERY_SENSOR_TYPES = [ ] TRIGGERED_SENSOR_TYPES = { - DeviceTypes.CARBON_MONOXIDE: DEVICE_CLASS_GAS, - DeviceTypes.ENTRY: DEVICE_CLASS_DOOR, - DeviceTypes.GLASS_BREAK: DEVICE_CLASS_SAFETY, - DeviceTypes.LEAK: DEVICE_CLASS_MOISTURE, - DeviceTypes.MOTION: DEVICE_CLASS_MOTION, - DeviceTypes.SIREN: DEVICE_CLASS_SAFETY, - DeviceTypes.SMOKE: DEVICE_CLASS_SMOKE, + DeviceTypes.CARBON_MONOXIDE: BinarySensorDeviceClass.GAS, + DeviceTypes.ENTRY: BinarySensorDeviceClass.DOOR, + DeviceTypes.GLASS_BREAK: BinarySensorDeviceClass.SAFETY, + DeviceTypes.LEAK: BinarySensorDeviceClass.MOISTURE, + DeviceTypes.MOTION: BinarySensorDeviceClass.MOTION, + DeviceTypes.SIREN: BinarySensorDeviceClass.SAFETY, + DeviceTypes.SMOKE: BinarySensorDeviceClass.SMOKE, } @@ -100,8 +94,8 @@ class TriggeredBinarySensor(SimpliSafeEntity, BinarySensorEntity): class BatteryBinarySensor(SimpliSafeEntity, BinarySensorEntity): """Define a SimpliSafe battery binary sensor entity.""" - _attr_device_class = DEVICE_CLASS_BATTERY - _attr_entity_category = ENTITY_CATEGORY_DIAGNOSTIC + _attr_device_class = BinarySensorDeviceClass.BATTERY + _attr_entity_category = EntityCategory.DIAGNOSTIC def __init__( self, simplisafe: SimpliSafe, system: SystemV3, sensor: SensorV3 diff --git a/homeassistant/components/simplisafe/sensor.py b/homeassistant/components/simplisafe/sensor.py index b2b0a432bd6..39566434f27 100644 --- a/homeassistant/components/simplisafe/sensor.py +++ b/homeassistant/components/simplisafe/sensor.py @@ -5,9 +5,13 @@ from simplipy.device import DeviceTypes from simplipy.device.sensor.v3 import SensorV3 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.const import DEVICE_CLASS_TEMPERATURE, TEMP_FAHRENHEIT +from homeassistant.const import TEMP_FAHRENHEIT from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.entity_platform import AddEntitiesCallback @@ -37,9 +41,9 @@ async def async_setup_entry( class SimplisafeFreezeSensor(SimpliSafeEntity, SensorEntity): """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_state_class = STATE_CLASS_MEASUREMENT + _attr_state_class = SensorStateClass.MEASUREMENT def __init__( self, simplisafe: SimpliSafe, system: SystemV3, sensor: SensorV3