mirror of
https://github.com/home-assistant/core.git
synced 2025-07-13 08:17:08 +00:00
Water heater platform back-compat for custom components without WaterHeaterEntityFeature (#106608)
This commit is contained in:
parent
04fe8260ab
commit
6224e630ac
@ -401,6 +401,19 @@ class WaterHeaterEntity(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) -> 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(
|
async def async_service_away_mode(
|
||||||
entity: WaterHeaterEntity, service: ServiceCall
|
entity: WaterHeaterEntity, service: ServiceCall
|
||||||
|
@ -115,3 +115,23 @@ def test_deprecated_constants(
|
|||||||
import_and_test_deprecated_constant_enum(
|
import_and_test_deprecated_constant_enum(
|
||||||
caplog, water_heater, enum, "SUPPORT_", "2025.1"
|
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…
x
Reference in New Issue
Block a user