Add deprecation warning for lock supported features when using magic numbers (#106620)
This commit is contained in:
parent
024d689b94
commit
af9f6a2b12
2 changed files with 23 additions and 1 deletions
|
@ -278,7 +278,12 @@ class LockEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_ATTR_):
|
||||||
@cached_property
|
@cached_property
|
||||||
def supported_features(self) -> LockEntityFeature:
|
def supported_features(self) -> LockEntityFeature:
|
||||||
"""Return the list of supported features."""
|
"""Return the list of supported features."""
|
||||||
return self._attr_supported_features
|
features = self._attr_supported_features
|
||||||
|
if type(features) is int: # noqa: E721
|
||||||
|
new_features = LockEntityFeature(features)
|
||||||
|
self._report_deprecated_supported_features_values(new_features)
|
||||||
|
return new_features
|
||||||
|
return features
|
||||||
|
|
||||||
async def async_internal_added_to_hass(self) -> None:
|
async def async_internal_added_to_hass(self) -> None:
|
||||||
"""Call when the sensor entity is added to hass."""
|
"""Call when the sensor entity is added to hass."""
|
||||||
|
|
|
@ -378,3 +378,20 @@ def test_deprecated_constants(
|
||||||
) -> None:
|
) -> None:
|
||||||
"""Test deprecated constants."""
|
"""Test deprecated constants."""
|
||||||
import_and_test_deprecated_constant_enum(caplog, lock, enum, "SUPPORT_", "2025.1")
|
import_and_test_deprecated_constant_enum(caplog, lock, enum, "SUPPORT_", "2025.1")
|
||||||
|
|
||||||
|
|
||||||
|
def test_deprecated_supported_features_ints(caplog: pytest.LogCaptureFixture) -> None:
|
||||||
|
"""Test deprecated supported features ints."""
|
||||||
|
|
||||||
|
class MockLockEntity(lock.LockEntity):
|
||||||
|
_attr_supported_features = 1
|
||||||
|
|
||||||
|
entity = MockLockEntity()
|
||||||
|
assert entity.supported_features is lock.LockEntityFeature(1)
|
||||||
|
assert "MockLockEntity" in caplog.text
|
||||||
|
assert "is using deprecated supported features values" in caplog.text
|
||||||
|
assert "Instead it should use" in caplog.text
|
||||||
|
assert "LockEntityFeature.OPEN" in caplog.text
|
||||||
|
caplog.clear()
|
||||||
|
assert entity.supported_features is lock.LockEntityFeature(1)
|
||||||
|
assert "is using deprecated supported features values" not in caplog.text
|
||||||
|
|
Loading…
Add table
Reference in a new issue