From 888371ce03ded9cab155b7159b2a24ae109b5c26 Mon Sep 17 00:00:00 2001 From: Erik Kastelec Date: Tue, 3 Jan 2023 18:07:23 +0100 Subject: [PATCH] Replaced deprecated DEVICE_CLASS_* constants. Closes #49 --- custom_components/wemportal/manifest.json | 2 +- custom_components/wemportal/sensor.py | 32 +++++++++++------------ 2 files changed, 17 insertions(+), 17 deletions(-) diff --git a/custom_components/wemportal/manifest.json b/custom_components/wemportal/manifest.json index 1bc559c..74c97b6 100644 --- a/custom_components/wemportal/manifest.json +++ b/custom_components/wemportal/manifest.json @@ -4,7 +4,7 @@ "documentation": "https://github.com/erikkastelec/hass-WEM-Portal", "issue_tracker": "https://github.com/erikkastelec/hass-WEM-Portal/issues", "dependencies": [], - "version": "1.4.1", + "version": "1.4.2", "codeowners": [ "@erikkastelec" ], diff --git a/custom_components/wemportal/sensor.py b/custom_components/wemportal/sensor.py index 3c9e5ba..549913c 100644 --- a/custom_components/wemportal/sensor.py +++ b/custom_components/wemportal/sensor.py @@ -2,13 +2,13 @@ Sensor platform for wemportal component """ -from homeassistant.components.sensor import (STATE_CLASS_MEASUREMENT, - STATE_CLASS_TOTAL_INCREASING, - SensorEntity) +from homeassistant.components.sensor import ( + SensorEntity, + SensorDeviceClass, + SensorStateClass, +) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import (DEVICE_CLASS_ENERGY, DEVICE_CLASS_POWER, - DEVICE_CLASS_POWER_FACTOR, - DEVICE_CLASS_TEMPERATURE) + from homeassistant.core import HomeAssistant from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.update_coordinator import CoordinatorEntity @@ -17,10 +17,10 @@ async def async_setup_platform( - hass: HomeAssistant, - config_entry: ConfigEntry, - async_add_entities: AddEntitiesCallback, - discovery_info=None, + hass: HomeAssistant, + config_entry: ConfigEntry, + async_add_entities: AddEntitiesCallback, + discovery_info=None, ): """Setup the Wem Portal sensors.""" @@ -103,13 +103,13 @@ def unit_of_measurement(self): def device_class(self): """Return the device_class of this entity.""" if self._unit == "°C": - return DEVICE_CLASS_TEMPERATURE + return SensorDeviceClass.TEMPERATURE elif self._unit in ("kWh", "Wh"): - return DEVICE_CLASS_ENERGY + return SensorDeviceClass.ENERGY elif self._unit in ("kW", "W"): - return DEVICE_CLASS_POWER + return SensorDeviceClass.POWER elif self._unit == "%": - return DEVICE_CLASS_POWER_FACTOR + return SensorDeviceClass.POWER_FACTOR else: return None @@ -117,9 +117,9 @@ def device_class(self): def state_class(self): """Return the state class of this entity, if any.""" if self._unit in ("°C", "kW", "W", "%"): - return STATE_CLASS_MEASUREMENT + return SensorStateClass.MEASUREMENT elif self._unit in ("kWh", "Wh"): - return STATE_CLASS_TOTAL_INCREASING + return SensorStateClass.TOTAL_INCREASING else: return None