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 12, 2024
1 parent 21bd38a commit aa88006
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions custom_components/sonoff/climate.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
ClimateEntityFeature,
HVACMode,
)
from homeassistant.const import UnitOfTemperature
from homeassistant.const import UnitOfTemperature, MAJOR_VERSION, MINOR_VERSION

from .core.const import DOMAIN
from .core.entity import XEntity
Expand All @@ -29,12 +29,22 @@ class XClimateTH(XEntity, ClimateEntity):
_attr_hvac_modes = [HVACMode.OFF, HVACMode.HEAT, HVACMode.COOL, HVACMode.DRY]
_attr_max_temp = 99
_attr_min_temp = 1
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE_RANGE
_attr_target_temperature_high = None
_attr_target_temperature_low = None
_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_RANGE
| ClimateEntityFeature.TURN_ON
| ClimateEntityFeature.TURN_OFF
)
_enable_turn_on_off_backwards_compatibility = False
else:
_attr_supported_features = ClimateEntityFeature.TARGET_TEMPERATURE_RANGE

heat: bool = None

def set_state(self, params: dict):
Expand Down

0 comments on commit aa88006

Please sign in to comment.