From 27dda72399debfafe1562ca7360208bbc41b0296 Mon Sep 17 00:00:00 2001 From: Malene Trab Date: Mon, 5 Feb 2024 08:45:03 +0000 Subject: [PATCH] Update deprecated constants --- custom_components/danfoss_ally/climate.py | 36 +++++++++++------------ custom_components/danfoss_ally/const.py | 12 +++----- custom_components/danfoss_ally/sensor.py | 8 ++--- 3 files changed, 25 insertions(+), 31 deletions(-) diff --git a/custom_components/danfoss_ally/climate.py b/custom_components/danfoss_ally/climate.py index 73b09fe..42e983b 100644 --- a/custom_components/danfoss_ally/climate.py +++ b/custom_components/danfoss_ally/climate.py @@ -8,16 +8,14 @@ from homeassistant.components.climate.const import ( # SUPPORT_PRESET_MODE,; SUPPORT_TARGET_TEMPERATURE, ATTR_HVAC_MODE, ATTR_PRESET_MODE, - CURRENT_HVAC_HEAT, - CURRENT_HVAC_IDLE, - HVAC_MODE_AUTO, - HVAC_MODE_HEAT, + HVACAction, PRESET_AWAY, PRESET_HOME, + HVACMode, ClimateEntityFeature, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import ATTR_TEMPERATURE, TEMP_CELSIUS +from homeassistant.const import ATTR_TEMPERATURE, UnitOfTemperature from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import config_validation as cv from homeassistant.helpers import entity_platform @@ -170,13 +168,13 @@ def hvac_mode(self): or self._device["mode"] == "leaving_home" or self._device["mode"] == "holiday_sat" ): - return HVAC_MODE_AUTO + return HVACMode.AUTO elif ( self._device["mode"] == "manual" or self._device["mode"] == "pause" or self._device["mode"] == "holiday" ): - return HVAC_MODE_HEAT + return HVACMode.HEAT @property def preset_mode(self): @@ -237,18 +235,18 @@ def set_preset_mode(self, preset_mode): @property def hvac_action(self): """Return the current running hvac operation if supported. - Need to be one of CURRENT_HVAC_*. + Need to be one of HVACAction.* """ if "work_state" in self._device: if self._device["work_state"] == "Heat": - return CURRENT_HVAC_HEAT + return HVACAction.HEATING elif self._device["work_state"] == "NoHeat": - return CURRENT_HVAC_IDLE + return HVACAction.IDLE @property def temperature_unit(self): """Return the unit of measurement used by the platform.""" - return TEMP_CELSIUS + return UnitOfTemperature.CELSIUS @property def target_temperature_step(self): @@ -274,9 +272,9 @@ def set_temperature(self, **kwargs): ) # Preset_mode sent from action elif ATTR_HVAC_MODE in kwargs: value = kwargs.get(ATTR_HVAC_MODE) # HVAC_mode sent from action - if value == HVAC_MODE_AUTO: + if value == HVACMode.AUTO: setpoint_code = self.get_setpoint_code_for_mode("at_home") - if value == HVAC_MODE_HEAT: + if value == HVACMode.HEAT: setpoint_code = self.get_setpoint_code_for_mode("manual") else: setpoint_code = self.get_setpoint_code_for_mode( @@ -410,9 +408,9 @@ def set_hvac_mode(self, hvac_mode): _LOGGER.debug("Setting hvac mode to %s", hvac_mode) - if hvac_mode == HVAC_MODE_AUTO: + if hvac_mode == HVACMode.AUTO: mode = "at_home" # We have to choose either at_home or leaving_home - elif hvac_mode == HVAC_MODE_HEAT: + elif hvac_mode == HVACMode.HEAT: mode = "manual" if mode is None: @@ -492,13 +490,13 @@ def __init__( @property def hvac_action(self): """Return the current running hvac operation if supported. - Need to be one of CURRENT_HVAC_*. + Need to be one of HVACAction.* """ if "work_state" in self._device: if self._device["work_state"] == "heat_active": - return CURRENT_HVAC_HEAT + return HVACAction.HEATING elif self._device["work_state"] == "Heat": - return CURRENT_HVAC_IDLE + return HVACAction.IDLE async def async_setup_entry( @@ -562,7 +560,7 @@ def create_climate_entity(ally, name: str, device_id: str, model: str) -> AllyCl support_flags = ( ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE ) - supported_hvac_modes = [HVAC_MODE_AUTO, HVAC_MODE_HEAT] + supported_hvac_modes = [HVACMode.AUTO, HVACMode.HEAT] heat_min_temp = 4.5 heat_max_temp = 35.0 heat_step = 0.5 diff --git a/custom_components/danfoss_ally/const.py b/custom_components/danfoss_ally/const.py index 803bcda..ccd23f0 100644 --- a/custom_components/danfoss_ally/const.py +++ b/custom_components/danfoss_ally/const.py @@ -1,9 +1,5 @@ """Danfoss_ally consts.""" -from homeassistant.components.climate.const import ( - HVAC_MODE_AUTO, - HVAC_MODE_HEAT, - HVAC_MODE_OFF, -) +from homeassistant.components.climate.const import HVACMode THERMOSTAT_MODE_AUTO = "hot" THERMOSTAT_MODE_MANUAL = "manual" @@ -17,9 +13,9 @@ PRESET_HOLIDAY_HOME = "Holiday (Home)" HA_TO_DANFOSS_HVAC_MODE_MAP = { - HVAC_MODE_OFF: THERMOSTAT_MODE_OFF, - HVAC_MODE_HEAT: THERMOSTAT_MODE_MANUAL, - HVAC_MODE_AUTO: THERMOSTAT_MODE_AUTO, + HVACMode.OFF: THERMOSTAT_MODE_OFF, + HVACMode.HEAT: THERMOSTAT_MODE_MANUAL, + HVACMode.AUTO: THERMOSTAT_MODE_AUTO, } DANFOSS_TO_HA_HVAC_MODE_MAP = { diff --git a/custom_components/danfoss_ally/sensor.py b/custom_components/danfoss_ally/sensor.py index cfa8c22..a865a6d 100644 --- a/custom_components/danfoss_ally/sensor.py +++ b/custom_components/danfoss_ally/sensor.py @@ -11,7 +11,7 @@ SensorStateClass, ) from homeassistant.config_entries import ConfigEntry -from homeassistant.const import PERCENTAGE, TEMP_CELSIUS +from homeassistant.const import PERCENTAGE, UnitOfTemperature from homeassistant.core import HomeAssistant, callback from homeassistant.helpers.dispatcher import async_dispatcher_connect from homeassistant.helpers.entity import EntityCategory @@ -41,7 +41,7 @@ class AllySensorType(IntEnum): key=AllySensorType.TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE, entity_category=None, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, state_class=SensorStateClass.MEASUREMENT, name="{} temperature", ), @@ -65,7 +65,7 @@ class AllySensorType(IntEnum): key=AllySensorType.FLOOR_TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE, entity_category=None, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, state_class=SensorStateClass.MEASUREMENT, name="{} floor temperature", ), @@ -96,7 +96,7 @@ class AllySensorType(IntEnum): key=AllySensorType.EXTERNAL_SENSOR_TEMPERATURE, device_class=SensorDeviceClass.TEMPERATURE, entity_category=None, - native_unit_of_measurement=TEMP_CELSIUS, + native_unit_of_measurement=UnitOfTemperature.CELSIUS, state_class=SensorStateClass.MEASUREMENT, name="{} external sensor temperature", entity_registry_enabled_default=False,