mirror of
https://github.com/home-assistant/core.git
synced 2025-07-19 11:17:21 +00:00
Add deprecation warning for alarm_control_panel supported features when using magic numbers (#106619)
This commit is contained in:
parent
2b972f6dba
commit
e6c6327463
@ -233,7 +233,12 @@ class AlarmControlPanelEntity(Entity, cached_properties=CACHED_PROPERTIES_WITH_A
|
|||||||
@cached_property
|
@cached_property
|
||||||
def supported_features(self) -> AlarmControlPanelEntityFeature:
|
def supported_features(self) -> AlarmControlPanelEntityFeature:
|
||||||
"""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 = AlarmControlPanelEntityFeature(features)
|
||||||
|
self._report_deprecated_supported_features_values(new_features)
|
||||||
|
return new_features
|
||||||
|
return features
|
||||||
|
|
||||||
@final
|
@final
|
||||||
@property
|
@property
|
||||||
|
@ -45,3 +45,26 @@ def test_deprecated_support_alarm_constants(
|
|||||||
import_and_test_deprecated_constant_enum(
|
import_and_test_deprecated_constant_enum(
|
||||||
caplog, module, entity_feature, "SUPPORT_ALARM_", "2025.1"
|
caplog, module, entity_feature, "SUPPORT_ALARM_", "2025.1"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
def test_deprecated_supported_features_ints(caplog: pytest.LogCaptureFixture) -> None:
|
||||||
|
"""Test deprecated supported features ints."""
|
||||||
|
|
||||||
|
class MockAlarmControlPanelEntity(alarm_control_panel.AlarmControlPanelEntity):
|
||||||
|
_attr_supported_features = 1
|
||||||
|
|
||||||
|
entity = MockAlarmControlPanelEntity()
|
||||||
|
assert (
|
||||||
|
entity.supported_features
|
||||||
|
is alarm_control_panel.AlarmControlPanelEntityFeature(1)
|
||||||
|
)
|
||||||
|
assert "MockAlarmControlPanelEntity" in caplog.text
|
||||||
|
assert "is using deprecated supported features values" in caplog.text
|
||||||
|
assert "Instead it should use" in caplog.text
|
||||||
|
assert "AlarmControlPanelEntityFeature.ARM_HOME" in caplog.text
|
||||||
|
caplog.clear()
|
||||||
|
assert (
|
||||||
|
entity.supported_features
|
||||||
|
is alarm_control_panel.AlarmControlPanelEntityFeature(1)
|
||||||
|
)
|
||||||
|
assert "is using deprecated supported features values" not in caplog.text
|
||||||
|
Loading…
x
Reference in New Issue
Block a user