mirror of
https://github.com/home-assistant/core.git
synced 2025-07-24 13:47:35 +00:00
Add deprecation warning for cover supported features when using magic numbers (#106618)
This commit is contained in:
parent
ee2689de3c
commit
7051f28547
@ -340,8 +340,12 @@ class CoverEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
|
|||||||
@property
|
@property
|
||||||
def supported_features(self) -> CoverEntityFeature:
|
def supported_features(self) -> CoverEntityFeature:
|
||||||
"""Flag supported features."""
|
"""Flag supported features."""
|
||||||
if self._attr_supported_features is not None:
|
if (features := self._attr_supported_features) is not None:
|
||||||
return self._attr_supported_features
|
if type(features) is int: # noqa: E721
|
||||||
|
new_features = CoverEntityFeature(features)
|
||||||
|
self._report_deprecated_supported_features_values(new_features)
|
||||||
|
return new_features
|
||||||
|
return features
|
||||||
|
|
||||||
supported_features = (
|
supported_features = (
|
||||||
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP
|
CoverEntityFeature.OPEN | CoverEntityFeature.CLOSE | CoverEntityFeature.STOP
|
||||||
|
@ -141,3 +141,20 @@ def test_deprecated_constants(
|
|||||||
import_and_test_deprecated_constant_enum(
|
import_and_test_deprecated_constant_enum(
|
||||||
caplog, cover, enum, constant_prefix, "2025.1"
|
caplog, cover, enum, constant_prefix, "2025.1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_deprecated_supported_features_ints(caplog: pytest.LogCaptureFixture) -> None:
|
||||||
|
"""Test deprecated supported features ints."""
|
||||||
|
|
||||||
|
class MockCoverEntity(cover.CoverEntity):
|
||||||
|
_attr_supported_features = 1
|
||||||
|
|
||||||
|
entity = MockCoverEntity()
|
||||||
|
assert entity.supported_features is cover.CoverEntityFeature(1)
|
||||||
|
assert "MockCoverEntity" in caplog.text
|
||||||
|
assert "is using deprecated supported features values" in caplog.text
|
||||||
|
assert "Instead it should use" in caplog.text
|
||||||
|
assert "CoverEntityFeature.OPEN" in caplog.text
|
||||||
|
caplog.clear()
|
||||||
|
assert entity.supported_features is cover.CoverEntityFeature(1)
|
||||||
|
assert "is using deprecated supported features values" not in caplog.text
|
||||||
|
Loading…
x
Reference in New Issue
Block a user