From 1c15e36afcbe5731f89646cd02cead0b6646374a Mon Sep 17 00:00:00 2001 From: Robert Hillis Date: Fri, 17 Dec 2021 06:46:21 -0500 Subject: [PATCH] Use enums in wallbox (#61997) --- homeassistant/components/wallbox/sensor.py | 34 ++++++++++------------ 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/homeassistant/components/wallbox/sensor.py b/homeassistant/components/wallbox/sensor.py index dd45c237c45..89119bbc671 100644 --- a/homeassistant/components/wallbox/sensor.py +++ b/homeassistant/components/wallbox/sensor.py @@ -6,17 +6,13 @@ import logging from typing import cast from homeassistant.components.sensor import ( - STATE_CLASS_MEASUREMENT, - STATE_CLASS_TOTAL_INCREASING, + SensorDeviceClass, SensorEntity, SensorEntityDescription, + SensorStateClass, ) from homeassistant.config_entries import ConfigEntry from homeassistant.const import ( - DEVICE_CLASS_BATTERY, - DEVICE_CLASS_CURRENT, - DEVICE_CLASS_ENERGY, - DEVICE_CLASS_POWER, ELECTRIC_CURRENT_AMPERE, ENERGY_KILO_WATT_HOUR, LENGTH_KILOMETERS, @@ -63,23 +59,23 @@ SENSOR_TYPES: dict[str, WallboxSensorEntityDescription] = { name="Charging Power", precision=2, native_unit_of_measurement=POWER_KILO_WATT, - device_class=DEVICE_CLASS_POWER, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.POWER, + state_class=SensorStateClass.MEASUREMENT, ), CONF_MAX_AVAILABLE_POWER_KEY: WallboxSensorEntityDescription( key=CONF_MAX_AVAILABLE_POWER_KEY, name="Max Available Power", precision=0, native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE, - device_class=DEVICE_CLASS_CURRENT, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.CURRENT, + state_class=SensorStateClass.MEASUREMENT, ), CONF_CHARGING_SPEED_KEY: WallboxSensorEntityDescription( key=CONF_CHARGING_SPEED_KEY, icon="mdi:speedometer", name="Charging Speed", precision=0, - state_class=STATE_CLASS_MEASUREMENT, + state_class=SensorStateClass.MEASUREMENT, ), CONF_ADDED_RANGE_KEY: WallboxSensorEntityDescription( key=CONF_ADDED_RANGE_KEY, @@ -87,28 +83,28 @@ SENSOR_TYPES: dict[str, WallboxSensorEntityDescription] = { name="Added Range", precision=0, native_unit_of_measurement=LENGTH_KILOMETERS, - state_class=STATE_CLASS_TOTAL_INCREASING, + state_class=SensorStateClass.TOTAL_INCREASING, ), CONF_ADDED_ENERGY_KEY: WallboxSensorEntityDescription( key=CONF_ADDED_ENERGY_KEY, name="Added Energy", precision=2, native_unit_of_measurement=ENERGY_KILO_WATT_HOUR, - device_class=DEVICE_CLASS_ENERGY, - state_class=STATE_CLASS_TOTAL_INCREASING, + device_class=SensorDeviceClass.ENERGY, + state_class=SensorStateClass.TOTAL_INCREASING, ), CONF_COST_KEY: WallboxSensorEntityDescription( key=CONF_COST_KEY, icon="mdi:ev-station", name="Cost", - state_class=STATE_CLASS_TOTAL_INCREASING, + state_class=SensorStateClass.TOTAL_INCREASING, ), CONF_STATE_OF_CHARGE_KEY: WallboxSensorEntityDescription( key=CONF_STATE_OF_CHARGE_KEY, name="State of Charge", native_unit_of_measurement=PERCENTAGE, - device_class=DEVICE_CLASS_BATTERY, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.BATTERY, + state_class=SensorStateClass.MEASUREMENT, ), CONF_CURRENT_MODE_KEY: WallboxSensorEntityDescription( key=CONF_CURRENT_MODE_KEY, @@ -130,8 +126,8 @@ SENSOR_TYPES: dict[str, WallboxSensorEntityDescription] = { key=CONF_MAX_CHARGING_CURRENT_KEY, name="Max. Charging Current", native_unit_of_measurement=ELECTRIC_CURRENT_AMPERE, - device_class=DEVICE_CLASS_CURRENT, - state_class=STATE_CLASS_MEASUREMENT, + device_class=SensorDeviceClass.CURRENT, + state_class=SensorStateClass.MEASUREMENT, ), }