Water heater platform back-compat for custom components without WaterHeaterEntityFeature (#106608)
parent
97ee7e2c98
commit
d0e9f2ce0d
|
@ -401,6 +401,19 @@ class WaterHeaterEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
|
|||
"""Return the list of supported features."""
|
||||
return self._attr_supported_features
|
||||
|
||||
@property
|
||||
def supported_features_compat(self) -> WaterHeaterEntityFeature:
|
||||
"""Return the supported features as WaterHeaterEntityFeature.
|
||||
|
||||
Remove this compatibility shim in 2025.1 or later.
|
||||
"""
|
||||
features = self.supported_features
|
||||
if type(features) is int: # noqa: E721
|
||||
new_features = WaterHeaterEntityFeature(features)
|
||||
self._report_deprecated_supported_features_values(new_features)
|
||||
return new_features
|
||||
return features
|
||||
|
||||
|
||||
async def async_service_away_mode(
|
||||
entity: WaterHeaterEntity, service: ServiceCall
|
||||
|
|
|
@ -115,3 +115,23 @@ def test_deprecated_constants(
|
|||
import_and_test_deprecated_constant_enum(
|
||||
caplog, water_heater, enum, "SUPPORT_", "2025.1"
|
||||
)
|
||||
|
||||
|
||||
def test_deprecated_supported_features_ints(caplog: pytest.LogCaptureFixture) -> None:
|
||||
"""Test deprecated supported features ints."""
|
||||
|
||||
class MockWaterHeaterEntity(WaterHeaterEntity):
|
||||
@property
|
||||
def supported_features(self) -> int:
|
||||
"""Return supported features."""
|
||||
return 1
|
||||
|
||||
entity = MockWaterHeaterEntity()
|
||||
assert entity.supported_features_compat is WaterHeaterEntityFeature(1)
|
||||
assert "MockWaterHeaterEntity" in caplog.text
|
||||
assert "is using deprecated supported features values" in caplog.text
|
||||
assert "Instead it should use" in caplog.text
|
||||
assert "WaterHeaterEntityFeature.TARGET_TEMPERATURE" in caplog.text
|
||||
caplog.clear()
|
||||
assert entity.supported_features_compat is WaterHeaterEntityFeature(1)
|
||||
assert "is using deprecated supported features values" not in caplog.text
|
||||
|
|
Loading…
Reference in New Issue