Skip to content

Commit

Permalink
Fix Hass 2024.2 climate entity deprecation #1341
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Feb 13, 2024
1 parent ba2ebc7 commit 1c85d28
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions custom_components/sonoff/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,10 +153,20 @@ class XClimateNS(XEntity, ClimateEntity):
_attr_hvac_modes = [HVACMode.OFF, HVACMode.HEAT_COOL, HVACMode.AUTO]
_attr_max_temp = 31
_attr_min_temp = 16
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE
_attr_temperature_unit = UnitOfTemperature.CELSIUS
_attr_target_temperature_step = 1

# https://developers.home-assistant.io/blog/2024/01/24/climate-climateentityfeatures-expanded
if (MAJOR_VERSION, MINOR_VERSION) >= (2024, 2):
_attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.TURN_ON
| ClimateEntityFeature.TURN_OFF
)
_enable_turn_on_off_backwards_compatibility = False
else:
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE

def set_state(self, params: dict):
cache = self.device["params"]
if cache != params:
Expand Down Expand Up @@ -240,10 +250,23 @@ class XThermostat(XEntity, ClimateEntity):
_attr_max_temp = 45
_attr_min_temp = 5
_attr_preset_modes = ["manual", "programmed", "economical"]
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
_attr_temperature_unit = UnitOfTemperature.CELSIUS
_attr_target_temperature_step = 0.5

# https://developers.home-assistant.io/blog/2024/01/24/climate-climateentityfeatures-expanded
if (MAJOR_VERSION, MINOR_VERSION) >= (2024, 2):
_attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE
| ClimateEntityFeature.PRESET_MODE
| ClimateEntityFeature.TURN_ON
| ClimateEntityFeature.TURN_OFF
)
_enable_turn_on_off_backwards_compatibility = False
else:
_attr_supported_features = (
ClimateEntityFeature.TARGET_TEMPERATURE | ClimateEntityFeature.PRESET_MODE
)

def set_state(self, params: dict):
cache = self.device["params"]
if cache != params:
Expand Down

0 comments on commit 1c85d28

Please sign in to comment.