From 619529b40c0c843cf069314b7ba77445697956a2 Mon Sep 17 00:00:00 2001 From: Robert Hillis Date: Thu, 16 Dec 2021 12:38:56 -0500 Subject: [PATCH] Use enums in Powerwall (#62072) --- .../components/powerwall/binary_sensor.py | 14 +++++------ homeassistant/components/powerwall/sensor.py | 23 +++++++------------ 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/homeassistant/components/powerwall/binary_sensor.py b/homeassistant/components/powerwall/binary_sensor.py index b4104b70f39..9f444d9ab7d 100644 --- a/homeassistant/components/powerwall/binary_sensor.py +++ b/homeassistant/components/powerwall/binary_sensor.py @@ -2,11 +2,9 @@ from tesla_powerwall import GridStatus, MeterType from homeassistant.components.binary_sensor import ( - DEVICE_CLASS_BATTERY_CHARGING, - DEVICE_CLASS_CONNECTIVITY, + BinarySensorDeviceClass, BinarySensorEntity, ) -from homeassistant.const import DEVICE_CLASS_POWER from .const import ( DOMAIN, @@ -61,7 +59,7 @@ class PowerWallRunningSensor(PowerWallEntity, BinarySensorEntity): @property def device_class(self): """Device Class.""" - return DEVICE_CLASS_POWER + return BinarySensorDeviceClass.POWER @property def unique_id(self): @@ -85,7 +83,7 @@ class PowerWallConnectedSensor(PowerWallEntity, BinarySensorEntity): @property def device_class(self): """Device Class.""" - return DEVICE_CLASS_CONNECTIVITY + return BinarySensorDeviceClass.CONNECTIVITY @property def unique_id(self): @@ -109,7 +107,7 @@ class PowerWallGridServicesActiveSensor(PowerWallEntity, BinarySensorEntity): @property def device_class(self): """Device Class.""" - return DEVICE_CLASS_POWER + return BinarySensorDeviceClass.POWER @property def unique_id(self): @@ -133,7 +131,7 @@ class PowerWallGridStatusSensor(PowerWallEntity, BinarySensorEntity): @property def device_class(self): """Device Class.""" - return DEVICE_CLASS_POWER + return BinarySensorDeviceClass.POWER @property def unique_id(self): @@ -157,7 +155,7 @@ class PowerWallChargingStatusSensor(PowerWallEntity, BinarySensorEntity): @property def device_class(self): """Device Class.""" - return DEVICE_CLASS_BATTERY_CHARGING + return BinarySensorDeviceClass.BATTERY_CHARGING @property def unique_id(self): diff --git a/homeassistant/components/powerwall/sensor.py b/homeassistant/components/powerwall/sensor.py index 8c45a142206..556159fa893 100644 --- a/homeassistant/components/powerwall/sensor.py +++ b/homeassistant/components/powerwall/sensor.py @@ -4,18 +4,11 @@ import logging from tesla_powerwall import MeterType from homeassistant.components.sensor import ( - STATE_CLASS_MEASUREMENT, - STATE_CLASS_TOTAL_INCREASING, + SensorDeviceClass, SensorEntity, + SensorStateClass, ) -from homeassistant.const import ( - DEVICE_CLASS_BATTERY, - DEVICE_CLASS_ENERGY, - DEVICE_CLASS_POWER, - ENERGY_KILO_WATT_HOUR, - PERCENTAGE, - POWER_KILO_WATT, -) +from homeassistant.const import ENERGY_KILO_WATT_HOUR, PERCENTAGE, POWER_KILO_WATT from .const import ( ATTR_FREQUENCY, @@ -92,7 +85,7 @@ class PowerWallChargeSensor(PowerWallEntity, SensorEntity): _attr_name = "Powerwall Charge" _attr_native_unit_of_measurement = PERCENTAGE - _attr_device_class = DEVICE_CLASS_BATTERY + _attr_device_class = SensorDeviceClass.BATTERY @property def unique_id(self): @@ -108,9 +101,9 @@ class PowerWallChargeSensor(PowerWallEntity, SensorEntity): class PowerWallEnergySensor(PowerWallEntity, SensorEntity): """Representation of an Powerwall Energy sensor.""" - _attr_state_class = STATE_CLASS_MEASUREMENT + _attr_state_class = SensorStateClass.MEASUREMENT _attr_native_unit_of_measurement = POWER_KILO_WATT - _attr_device_class = DEVICE_CLASS_POWER + _attr_device_class = SensorDeviceClass.POWER def __init__( self, @@ -155,9 +148,9 @@ class PowerWallEnergySensor(PowerWallEntity, SensorEntity): class PowerWallEnergyDirectionSensor(PowerWallEntity, SensorEntity): """Representation of an Powerwall Direction Energy sensor.""" - _attr_state_class = STATE_CLASS_TOTAL_INCREASING + _attr_state_class = SensorStateClass.TOTAL_INCREASING _attr_native_unit_of_measurement = ENERGY_KILO_WATT_HOUR - _attr_device_class = DEVICE_CLASS_ENERGY + _attr_device_class = SensorDeviceClass.ENERGY def __init__( self,