From a6a3ee6c87cceeff40cd3007941907f0ad3e4abc Mon Sep 17 00:00:00 2001 From: Vassilis Panos <4130346+vassilis-panos@users.noreply.github.com> Date: Mon, 30 Dec 2024 00:42:42 +0200 Subject: [PATCH] ClimateEntityFeature enum compatibility --- custom_components/smartir/__init__.py | 2 +- custom_components/smartir/climate.py | 39 ++++++++++++------------- custom_components/smartir/manifest.json | 8 ++--- 3 files changed, 24 insertions(+), 25 deletions(-) diff --git a/custom_components/smartir/__init__.py b/custom_components/smartir/__init__.py index 278b202b..e6499753 100644 --- a/custom_components/smartir/__init__.py +++ b/custom_components/smartir/__init__.py @@ -19,7 +19,7 @@ _LOGGER = logging.getLogger(__name__) DOMAIN = 'smartir' -VERSION = '1.17.9' +VERSION = '1.17.10' MANIFEST_URL = ( "https://raw.githubusercontent.com/" "smartHomeHub/SmartIR/{}/" diff --git a/custom_components/smartir/climate.py b/custom_components/smartir/climate.py index 0c21ea2a..87b9e2dc 100644 --- a/custom_components/smartir/climate.py +++ b/custom_components/smartir/climate.py @@ -7,10 +7,7 @@ from homeassistant.components.climate import ClimateEntity, PLATFORM_SCHEMA from homeassistant.components.climate.const import ( - HVAC_MODE_OFF, HVAC_MODE_HEAT, HVAC_MODE_COOL, - HVAC_MODE_DRY, HVAC_MODE_FAN_ONLY, HVAC_MODE_AUTO, - SUPPORT_TARGET_TEMPERATURE, SUPPORT_FAN_MODE, - SUPPORT_SWING_MODE, HVAC_MODES, ATTR_HVAC_MODE) + ClimateEntityFeature, HVACMode, HVAC_MODES, ATTR_HVAC_MODE) from homeassistant.const import ( CONF_NAME, STATE_ON, STATE_OFF, STATE_UNKNOWN, STATE_UNAVAILABLE, ATTR_TEMPERATURE, PRECISION_TENTHS, PRECISION_HALVES, PRECISION_WHOLE) @@ -36,8 +33,10 @@ CONF_POWER_SENSOR_RESTORE_STATE = 'power_sensor_restore_state' SUPPORT_FLAGS = ( - SUPPORT_TARGET_TEMPERATURE | - SUPPORT_FAN_MODE + ClimateEntityFeature.TURN_OFF | + ClimateEntityFeature.TURN_ON | + ClimateEntityFeature.TARGET_TEMPERATURE | + ClimateEntityFeature.FAN_MODE ) PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend({ @@ -119,13 +118,13 @@ def __init__(self, hass, config, device_data): valid_hvac_modes = [x for x in device_data['operationModes'] if x in HVAC_MODES] - self._operation_modes = [HVAC_MODE_OFF] + valid_hvac_modes + self._operation_modes = [HVACMode.OFF] + valid_hvac_modes self._fan_modes = device_data['fanModes'] self._swing_modes = device_data.get('swingModes') self._commands = device_data['commands'] self._target_temperature = self._min_temperature - self._hvac_mode = HVAC_MODE_OFF + self._hvac_mode = HVACMode.OFF self._current_fan_mode = self._fan_modes[0] self._current_swing_mode = None self._last_on_operation = None @@ -140,7 +139,7 @@ def __init__(self, hass, config, device_data): self._support_swing = False if self._swing_modes: - self._support_flags = self._support_flags | SUPPORT_SWING_MODE + self._support_flags = self._support_flags | ClimateEntityFeature.SWING_MODE self._current_swing_mode = self._swing_modes[0] self._support_swing = True @@ -204,9 +203,9 @@ def name(self): @property def state(self): """Return the current state.""" - if self.hvac_mode != HVAC_MODE_OFF: + if self.hvac_mode != HVACMode.OFF: return self.hvac_mode - return HVAC_MODE_OFF + return HVACMode.OFF @property def temperature_unit(self): @@ -316,7 +315,7 @@ async def async_set_temperature(self, **kwargs): await self.async_set_hvac_mode(hvac_mode) return - if not self._hvac_mode.lower() == HVAC_MODE_OFF: + if not self._hvac_mode.lower() == HVACMode.OFF: await self.send_command() self.async_write_ha_state() @@ -325,7 +324,7 @@ async def async_set_hvac_mode(self, hvac_mode): """Set operation mode.""" self._hvac_mode = hvac_mode - if not hvac_mode == HVAC_MODE_OFF: + if not hvac_mode == HVACMode.OFF: self._last_on_operation = hvac_mode await self.send_command() @@ -335,7 +334,7 @@ async def async_set_fan_mode(self, fan_mode): """Set fan mode.""" self._current_fan_mode = fan_mode - if not self._hvac_mode.lower() == HVAC_MODE_OFF: + if not self._hvac_mode.lower() == HVACMode.OFF: await self.send_command() self.async_write_ha_state() @@ -343,13 +342,13 @@ async def async_set_swing_mode(self, swing_mode): """Set swing mode.""" self._current_swing_mode = swing_mode - if not self._hvac_mode.lower() == HVAC_MODE_OFF: + if not self._hvac_mode.lower() == HVACMode.OFF: await self.send_command() self.async_write_ha_state() async def async_turn_off(self): """Turn off.""" - await self.async_set_hvac_mode(HVAC_MODE_OFF) + await self.async_set_hvac_mode(HVACMode.OFF) async def async_turn_on(self): """Turn on.""" @@ -367,7 +366,7 @@ async def send_command(self): swing_mode = self._current_swing_mode target_temperature = '{0:g}'.format(self._target_temperature) - if operation_mode.lower() == HVAC_MODE_OFF: + if operation_mode.lower() == HVACMode.OFF: await self._controller.send(self._commands['off']) return @@ -409,7 +408,7 @@ async def _async_power_sensor_changed(self, entity_id, old_state, new_state): if old_state is not None and new_state.state == old_state.state: return - if new_state.state == STATE_ON and self._hvac_mode == HVAC_MODE_OFF: + if new_state.state == STATE_ON and self._hvac_mode == HVACMode.OFF: self._on_by_remote = True if self._power_sensor_restore_state == True and self._last_on_operation is not None: self._hvac_mode = self._last_on_operation @@ -420,8 +419,8 @@ async def _async_power_sensor_changed(self, entity_id, old_state, new_state): if new_state.state == STATE_OFF: self._on_by_remote = False - if self._hvac_mode != HVAC_MODE_OFF: - self._hvac_mode = HVAC_MODE_OFF + if self._hvac_mode != HVACMode.OFF: + self._hvac_mode = HVACMode.OFF self.async_write_ha_state() @callback diff --git a/custom_components/smartir/manifest.json b/custom_components/smartir/manifest.json index 23c31f58..5e6e17e9 100644 --- a/custom_components/smartir/manifest.json +++ b/custom_components/smartir/manifest.json @@ -5,11 +5,11 @@ "dependencies": [], "codeowners": ["@smartHomeHub"], "requirements": ["aiofiles>=0.6.0"], - "homeassistant": "2023.12.0", - "version": "1.17.9", + "homeassistant": "2024.10.0", + "version": "1.17.10", "updater": { - "version": "1.17.9", - "releaseNotes": "-- Fix Fan.async_turn_on() #1170", + "version": "1.17.10", + "releaseNotes": "-- ClimateEntityFeature enum compatibility", "files": [ "__init__.py", "climate.py",