Remote platform back-compat for custom components without RemoteEntityFeature (#106609)
This commit is contained in:
parent
a46fe94216
commit
97ee7e2c98
2 changed files with 34 additions and 1 deletions
|
@ -200,6 +200,19 @@ class RemoteEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_)
|
|||
"""Flag supported features."""
|
||||
return self._attr_supported_features
|
||||
|
||||
@property
|
||||
def supported_features_compat(self) -> RemoteEntityFeature:
|
||||
"""Return the supported features as RemoteEntityFeature.
|
||||
|
||||
Remove this compatibility shim in 2025.1 or later.
|
||||
"""
|
||||
features = self.supported_features
|
||||
if type(features) is int: # noqa: E721
|
||||
new_features = RemoteEntityFeature(features)
|
||||
self._report_deprecated_supported_features_values(new_features)
|
||||
return new_features
|
||||
return features
|
||||
|
||||
@cached_property
|
||||
def current_activity(self) -> str | None:
|
||||
"""Active activity."""
|
||||
|
@ -214,7 +227,7 @@ class RemoteEntity(ToggleEntity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_)
|
|||
@property
|
||||
def state_attributes(self) -> dict[str, Any] | None:
|
||||
"""Return optional state attributes."""
|
||||
if RemoteEntityFeature.ACTIVITY not in self.supported_features:
|
||||
if RemoteEntityFeature.ACTIVITY not in self.supported_features_compat:
|
||||
return None
|
||||
|
||||
return {
|
||||
|
|
|
@ -150,3 +150,23 @@ def test_deprecated_constants(
|
|||
) -> None:
|
||||
"""Test deprecated constants."""
|
||||
import_and_test_deprecated_constant_enum(caplog, remote, enum, "SUPPORT_", "2025.1")
|
||||
|
||||
|
||||
def test_deprecated_supported_features_ints(caplog: pytest.LogCaptureFixture) -> None:
|
||||
"""Test deprecated supported features ints."""
|
||||
|
||||
class MockRemote(remote.RemoteEntity):
|
||||
@property
|
||||
def supported_features(self) -> int:
|
||||
"""Return supported features."""
|
||||
return 1
|
||||
|
||||
entity = MockRemote()
|
||||
assert entity.supported_features_compat is remote.RemoteEntityFeature(1)
|
||||
assert "MockRemote" in caplog.text
|
||||
assert "is using deprecated supported features values" in caplog.text
|
||||
assert "Instead it should use" in caplog.text
|
||||
assert "RemoteEntityFeature.LEARN_COMMAND" in caplog.text
|
||||
caplog.clear()
|
||||
assert entity.supported_features_compat is remote.RemoteEntityFeature(1)
|
||||
assert "is using deprecated supported features values" not in caplog.text
|
||||
|
|
Loading…
Add table
Reference in a new issue