From c4d57e69d169947fbaca89e91fe9a3f334c83926 Mon Sep 17 00:00:00 2001 From: jheling Date: Thu, 28 Mar 2024 19:04:46 +0100 Subject: [PATCH] fix deprecated constants --- custom_components/freeathome/climate.py | 26 ++++++++++++------------- custom_components/freeathome/cover.py | 17 +++++++--------- custom_components/freeathome/light.py | 17 +++++++++++----- custom_components/freeathome/sensor.py | 10 +++++----- 4 files changed, 36 insertions(+), 34 deletions(-) diff --git a/custom_components/freeathome/climate.py b/custom_components/freeathome/climate.py index b83f5c0..b66c7e1 100644 --- a/custom_components/freeathome/climate.py +++ b/custom_components/freeathome/climate.py @@ -4,10 +4,8 @@ import voluptuous as vol from homeassistant.components.climate import ClimateEntity -from homeassistant.components.climate.const import (HVAC_MODE_HEAT_COOL, HVAC_MODE_OFF, - SUPPORT_PRESET_MODE, - SUPPORT_TARGET_TEMPERATURE) -from homeassistant.const import (ATTR_TEMPERATURE, TEMP_CELSIUS) +from homeassistant.components.climate.const import (HVACMode, ClimateEntityFeature) +from homeassistant.const import (ATTR_TEMPERATURE, UnitOfTemperature) from homeassistant.helpers import config_validation as cv, entity_platform, service from .const import DOMAIN @@ -123,14 +121,14 @@ def current_actuator(self): @property def target_temperature(self): """Return the temperature we try to reach.""" - if self.hvac_mode == HVAC_MODE_OFF: + if self.hvac_mode == HVACMode.OFF: return None return float(self.thermostat_device.target_temperature) @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): @@ -139,19 +137,19 @@ def target_temperature_step(self): @property def supported_features(self): """Return the list of supported features.""" - return SUPPORT_TARGET_TEMPERATURE | SUPPORT_PRESET_MODE + return ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE @property def hvac_mode(self): if not self.thermostat_device.state: - return HVAC_MODE_OFF + return HVACMode.OFF else: - return HVAC_MODE_HEAT_COOL + return HVACMode.HEAT_COOL @property def hvac_modes(self): """Return the list of available hvac operation modes.""" - return [HVAC_MODE_HEAT_COOL, HVAC_MODE_OFF] + return [HVACMode.HEAT_COOL, HVACMode.OFF] @property def preset_modes(self): @@ -168,9 +166,9 @@ def preset_mode(self): def state(self): """Return current operation ie. heat, cool, idle.""" if not self.thermostat_device.state: - return HVAC_MODE_OFF + return HVACMode.OFF else: - return HVAC_MODE_HEAT_COOL + return HVACMode.HEAT_COOL @property def icon(self): @@ -187,10 +185,10 @@ async def after_update_callback(device): async def async_set_hvac_mode(self, hvac_mode): """Set new target operation mode.""" - if hvac_mode == HVAC_MODE_HEAT_COOL: + if hvac_mode == HVACMode.HEAT_COOL: await self.thermostat_device.turn_on() - if hvac_mode == HVAC_MODE_OFF: + if hvac_mode == HVACMode.OFF: await self.thermostat_device.turn_off() async def async_set_preset_mode(self, preset_mode): diff --git a/custom_components/freeathome/cover.py b/custom_components/freeathome/cover.py index 3cad346..1c0df21 100644 --- a/custom_components/freeathome/cover.py +++ b/custom_components/freeathome/cover.py @@ -3,13 +3,9 @@ import voluptuous as vol from homeassistant.components.cover import ( CoverEntity, + CoverEntityFeature, ATTR_POSITION, ATTR_TILT_POSITION, - SUPPORT_CLOSE, - SUPPORT_OPEN, - SUPPORT_SET_POSITION, - SUPPORT_SET_TILT_POSITION, - SUPPORT_STOP ) from homeassistant.helpers import config_validation as cv, entity_platform, service @@ -52,18 +48,19 @@ def __init__(self, device): self._state = self.cover_device.state @property - def supported_features(self): + def supported_features(self) -> CoverEntityFeature: """Flag supported features (open and close are always supported)""" - supported_features = SUPPORT_OPEN | SUPPORT_CLOSE + supported_features = CoverEntityFeature(0) + supported_features = (CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE) if self.cover_device.supports_stop(): - supported_features |= SUPPORT_STOP + supported_features |= CoverEntityFeature.STOP if self.cover_device.supports_position(): - supported_features |= SUPPORT_SET_POSITION + supported_features |= CoverEntityFeature.SET_POSITION if self.cover_device.supports_tilt_position(): - supported_features |= SUPPORT_SET_TILT_POSITION + supported_features |= CoverEntityFeature.SET_TILT_POSITION return supported_features diff --git a/custom_components/freeathome/light.py b/custom_components/freeathome/light.py index 963e674..6c75107 100644 --- a/custom_components/freeathome/light.py +++ b/custom_components/freeathome/light.py @@ -1,7 +1,7 @@ """ Support for Free@Home lights dimmers """ import logging from homeassistant.components.light import ( - ATTR_BRIGHTNESS, SUPPORT_BRIGHTNESS, LightEntity) + ATTR_BRIGHTNESS, ColorMode, LightEntity) from .const import DOMAIN @@ -62,11 +62,18 @@ def should_poll(self): return False @property - def supported_features(self): - """Flag supported features.""" + def color_mode(self) -> str | None: + """Return the color mode of the light.""" if self._is_dimmer: - return SUPPORT_BRIGHTNESS - return 0 + return ColorMode.BRIGHTNESS + return ColorMode.ONOFF + + @property + def supported_color_modes(self) -> set[str] | None: + """Flag supported color modes.""" + if self._is_dimmer: + return {ColorMode.BRIGHTNESS} + return {ColorMode.ONOFF} @property def is_on(self): diff --git a/custom_components/freeathome/sensor.py b/custom_components/freeathome/sensor.py index 8c4c8d5..7b2712c 100644 --- a/custom_components/freeathome/sensor.py +++ b/custom_components/freeathome/sensor.py @@ -3,8 +3,8 @@ from homeassistant.components.sensor import SensorDeviceClass from homeassistant.const import ( - SPEED_KILOMETERS_PER_HOUR, - TEMP_CELSIUS, + UnitOfSpeed, + UnitOfTemperature, PERCENTAGE, CONCENTRATION_PARTS_PER_MILLION, CONCENTRATION_MICROGRAMS_PER_CUBIC_METER @@ -18,13 +18,13 @@ SENSOR_TYPES = { "temperature": [ "Temperature", - TEMP_CELSIUS, + UnitOfTemperature.CELSIUS, "mdi:thermometer", SensorDeviceClass.TEMPERATURE, ], "windstrength": [ "Wind Strength", - SPEED_KILOMETERS_PER_HOUR, + UnitOfSpeed.KILOMETERS_PER_HOUR, "mdi:weather-windy", None, ], @@ -141,7 +141,7 @@ def __init__(self, device: FahDevice): @property def state(self): """Return the state of the device.""" - if self._unit_of_measurement == SPEED_KILOMETERS_PER_HOUR: + if self._unit_of_measurement == UnitOfSpeed.KILOMETERS_PER_HOUR: return ("%.2f" % (float(self._state) * 3.6)) else: return self._state