11import logging
22from homeassistant .components .climate import ClimateEntity
3- from homeassistant .core import HomeAssistant , callback
4- from homeassistant .helpers .event import async_track_state_change
3+ from homeassistant .core import Event , HomeAssistant , callback
4+ from homeassistant .helpers .event import async_track_state_change_event
55from homeassistant .helpers .restore_state import RestoreEntity
66from homeassistant .components .climate .const import (
77 HVACMode ,
3838 HVACMode .OFF : 1 ,
3939 HVACMode .COOL : 2 ,
4040 HVACMode .DRY : 3 ,
41- HVACMode .AUTO : 1 ,
41+ HVACMode .AUTO : 0 ,
4242 HVACMode .FAN_ONLY : 4 ,
4343 HVACMode .HEAT : 5 ,
4444}
@@ -91,8 +91,6 @@ def __init__(self, sb: SupportedRemote, options: dict = {}) -> None:
9191 FAN_HIGH ,
9292 ]
9393
94- self ._supported_features = ClimateEntityFeature .TURN_OFF | ClimateEntityFeature .TURN_ON | ClimateEntityFeature .TARGET_TEMPERATURE | ClimateEntityFeature .FAN_MODE
95-
9694 self ._temperature_sensor = options .get (CONF_TEMPERATURE_SENSOR , None )
9795 self ._humidity_sensor = options .get (CONF_HUMIDITY_SENSOR , None )
9896 self ._current_temperature = None
@@ -102,6 +100,7 @@ def __init__(self, sb: SupportedRemote, options: dict = {}) -> None:
102100 # This line will be removed after deprecation period (until 2025.1)
103101 # https://developers.home-assistant.io/blog/2024/01/24/climate-climateentityfeatures-expanded/
104102 self ._enable_turn_on_off_backwards_compatibility = False
103+ self .set_supported_features ()
105104
106105 @property
107106 def device_info (self ):
@@ -212,6 +211,14 @@ def turn_on(self):
212211 """Turn on."""
213212 self .set_hvac_mode (self ._last_on_operation or HVACMode .COOL )
214213
214+ def set_supported_features (self ):
215+ if self .hvac_mode == HVACMode .DRY or self .hvac_mode == HVACMode .FAN_ONLY :
216+ # switchbot api accept only 25 in DRY Mode
217+ self .set_temperature (temperature = 25 )
218+ self ._supported_features = ClimateEntityFeature .TURN_OFF | ClimateEntityFeature .TURN_ON | ClimateEntityFeature .FAN_MODE
219+ else :
220+ self ._supported_features = ClimateEntityFeature .TURN_OFF | ClimateEntityFeature .TURN_ON | ClimateEntityFeature .TARGET_TEMPERATURE | ClimateEntityFeature .FAN_MODE
221+
215222 def set_temperature (self , ** kwargs ):
216223 self ._target_temperature = kwargs .get ("temperature" )
217224
@@ -234,6 +241,7 @@ def set_fan_mode(self, fan_mode):
234241 self ._update_remote ()
235242
236243 def _update_remote (self ):
244+ self .set_supported_features ()
237245 if (self ._hvac_mode != HVACMode .OFF and self ._override_off_command ):
238246 self .sb .command (
239247 "setAll" ,
@@ -249,8 +257,9 @@ def _async_update_temp(self, state):
249257 except ValueError as ex :
250258 _LOGGER .error ("Unable to update from temperature sensor: %s" , ex )
251259
252- async def _async_temp_sensor_changed (self , entity_id , old_state , new_state ):
260+ async def _async_temp_sensor_changed (self , event ):
253261 """Handle temperature sensor changes."""
262+ new_state = event .data .get ('new_state' )
254263 if new_state is None :
255264 return
256265
@@ -266,8 +275,9 @@ def _async_update_humidity(self, state):
266275 except ValueError as ex :
267276 _LOGGER .error ("Unable to update from humidity sensor: %s" , ex )
268277
269- async def _async_humidity_sensor_changed (self , entity_id , old_state , new_state ):
278+ async def _async_humidity_sensor_changed (self , event ):
270279 """Handle humidity sensor changes."""
280+ new_state = event .data .get ('new_state' )
271281 if new_state is None :
272282 return
273283
@@ -288,8 +298,9 @@ def _async_update_power(self, state):
288298 except ValueError as ex :
289299 _LOGGER .error ("Unable to update from power sensor: %s" , ex )
290300
291- async def _async_power_sensor_changed (self , entity_id , old_state , new_state ):
301+ async def _async_power_sensor_changed (self , event : Event ):
292302 """Handle power sensor changes."""
303+ new_state = event .data .get ('new_state' )
293304 if new_state is None :
294305 return
295306
@@ -311,24 +322,24 @@ async def async_added_to_hass(self):
311322 'last_on_operation' )
312323
313324 if self ._temperature_sensor :
314- async_track_state_change (
315- self .hass , self ._temperature_sensor , self ._async_temp_sensor_changed )
325+ async_track_state_change_event (
326+ self .hass , [ self ._temperature_sensor ] , self ._async_temp_sensor_changed )
316327
317328 temp_sensor_state = self .hass .states .get (self ._temperature_sensor )
318329 if temp_sensor_state and temp_sensor_state .state != STATE_UNKNOWN :
319330 self ._async_update_temp (temp_sensor_state )
320331
321332 if self ._humidity_sensor :
322- async_track_state_change (
323- self .hass , self ._humidity_sensor , self ._async_humidity_sensor_changed )
333+ async_track_state_change_event (
334+ self .hass , [ self ._humidity_sensor ] , self ._async_humidity_sensor_changed )
324335
325336 humidity_sensor_state = self .hass .states .get (self ._humidity_sensor )
326337 if humidity_sensor_state and humidity_sensor_state .state != STATE_UNKNOWN :
327338 self ._async_update_humidity (humidity_sensor_state )
328339
329340 if self ._power_sensor :
330- async_track_state_change (
331- self .hass , self ._power_sensor , self ._async_power_sensor_changed )
341+ async_track_state_change_event (
342+ self .hass , [ self ._power_sensor ] , self ._async_power_sensor_changed )
332343
333344 power_sensor_state = self .hass .states .get (self ._power_sensor )
334345 if power_sensor_state and power_sensor_state .state != STATE_UNKNOWN :
0 commit comments