mirror of
https://github.com/home-assistant/core.git
synced 2025-07-08 13:57:10 +00:00
Climate platform back-compat for custom components without ClimateEntityFeature (#106605)
This commit is contained in:
parent
3e7c44c612
commit
552d4e49f0
@ -316,7 +316,7 @@ class ClimateEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
|
|||||||
@property
|
@property
|
||||||
def capability_attributes(self) -> dict[str, Any] | None:
|
def capability_attributes(self) -> dict[str, Any] | None:
|
||||||
"""Return the capability attributes."""
|
"""Return the capability attributes."""
|
||||||
supported_features = self.supported_features
|
supported_features = self.supported_features_compat
|
||||||
temperature_unit = self.temperature_unit
|
temperature_unit = self.temperature_unit
|
||||||
precision = self.precision
|
precision = self.precision
|
||||||
hass = self.hass
|
hass = self.hass
|
||||||
@ -349,7 +349,7 @@ class ClimateEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
|
|||||||
@property
|
@property
|
||||||
def state_attributes(self) -> dict[str, Any]:
|
def state_attributes(self) -> dict[str, Any]:
|
||||||
"""Return the optional state attributes."""
|
"""Return the optional state attributes."""
|
||||||
supported_features = self.supported_features
|
supported_features = self.supported_features_compat
|
||||||
temperature_unit = self.temperature_unit
|
temperature_unit = self.temperature_unit
|
||||||
precision = self.precision
|
precision = self.precision
|
||||||
hass = self.hass
|
hass = self.hass
|
||||||
@ -665,6 +665,19 @@ class ClimateEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
|
|||||||
"""Return the list of supported features."""
|
"""Return the list of supported features."""
|
||||||
return self._attr_supported_features
|
return self._attr_supported_features
|
||||||
|
|
||||||
|
@property
|
||||||
|
def supported_features_compat(self) -> ClimateEntityFeature:
|
||||||
|
"""Return the supported features as ClimateEntityFeature.
|
||||||
|
|
||||||
|
Remove this compatibility shim in 2025.1 or later.
|
||||||
|
"""
|
||||||
|
features = self.supported_features
|
||||||
|
if type(features) is int: # noqa: E721
|
||||||
|
new_features = ClimateEntityFeature(features)
|
||||||
|
self._report_deprecated_supported_features_values(new_features)
|
||||||
|
return new_features
|
||||||
|
return features
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def min_temp(self) -> float:
|
def min_temp(self) -> float:
|
||||||
"""Return the minimum temperature."""
|
"""Return the minimum temperature."""
|
||||||
|
@ -333,3 +333,23 @@ async def test_preset_mode_validation(
|
|||||||
)
|
)
|
||||||
assert str(exc.value) == "The fan_mode invalid is not a valid fan_mode: auto, off"
|
assert str(exc.value) == "The fan_mode invalid is not a valid fan_mode: auto, off"
|
||||||
assert exc.value.translation_key == "not_valid_fan_mode"
|
assert exc.value.translation_key == "not_valid_fan_mode"
|
||||||
|
|
||||||
|
|
||||||
|
def test_deprecated_supported_features_ints(caplog: pytest.LogCaptureFixture) -> None:
|
||||||
|
"""Test deprecated supported features ints."""
|
||||||
|
|
||||||
|
class MockClimateEntity(ClimateEntity):
|
||||||
|
@property
|
||||||
|
def supported_features(self) -> int:
|
||||||
|
"""Return supported features."""
|
||||||
|
return 1
|
||||||
|
|
||||||
|
entity = MockClimateEntity()
|
||||||
|
assert entity.supported_features_compat is ClimateEntityFeature(1)
|
||||||
|
assert "MockClimateEntity" in caplog.text
|
||||||
|
assert "is using deprecated supported features values" in caplog.text
|
||||||
|
assert "Instead it should use" in caplog.text
|
||||||
|
assert "ClimateEntityFeature.TARGET_TEMPERATURE" in caplog.text
|
||||||
|
caplog.clear()
|
||||||
|
assert entity.supported_features_compat is ClimateEntityFeature(1)
|
||||||
|
assert "is using deprecated supported features values" not in caplog.text
|
||||||
|
Loading…
x
Reference in New Issue
Block a user