Remove deprecated supported features warning in Vacuum (#132670)
parent
31150bf897
commit
57d5d7d2f2
|
@ -312,7 +312,7 @@ class StateVacuumEntity(
|
|||
@property
|
||||
def capability_attributes(self) -> dict[str, Any] | None:
|
||||
"""Return capability attributes."""
|
||||
if VacuumEntityFeature.FAN_SPEED in self.supported_features_compat:
|
||||
if VacuumEntityFeature.FAN_SPEED in self.supported_features:
|
||||
return {ATTR_FAN_SPEED_LIST: self.fan_speed_list}
|
||||
return None
|
||||
|
||||
|
@ -330,7 +330,7 @@ class StateVacuumEntity(
|
|||
def state_attributes(self) -> dict[str, Any]:
|
||||
"""Return the state attributes of the vacuum cleaner."""
|
||||
data: dict[str, Any] = {}
|
||||
supported_features = self.supported_features_compat
|
||||
supported_features = self.supported_features
|
||||
|
||||
if VacuumEntityFeature.BATTERY in supported_features:
|
||||
data[ATTR_BATTERY_LEVEL] = self.battery_level
|
||||
|
@ -369,19 +369,6 @@ class StateVacuumEntity(
|
|||
"""Flag vacuum cleaner features that are supported."""
|
||||
return self._attr_supported_features
|
||||
|
||||
@property
|
||||
def supported_features_compat(self) -> VacuumEntityFeature:
|
||||
"""Return the supported features as VacuumEntityFeature.
|
||||
|
||||
Remove this compatibility shim in 2025.1 or later.
|
||||
"""
|
||||
features = self.supported_features
|
||||
if type(features) is int: # noqa: E721
|
||||
new_features = VacuumEntityFeature(features)
|
||||
self._report_deprecated_supported_features_values(new_features)
|
||||
return new_features
|
||||
return features
|
||||
|
||||
def stop(self, **kwargs: Any) -> None:
|
||||
"""Stop the vacuum cleaner."""
|
||||
raise NotImplementedError
|
||||
|
|
|
@ -272,42 +272,6 @@ async def test_send_command(hass: HomeAssistant, config_flow_fixture: None) -> N
|
|||
assert "test" in strings
|
||||
|
||||
|
||||
async def test_supported_features_compat(hass: HomeAssistant) -> None:
|
||||
"""Test StateVacuumEntity using deprecated feature constants features."""
|
||||
|
||||
features = (
|
||||
VacuumEntityFeature.BATTERY
|
||||
| VacuumEntityFeature.FAN_SPEED
|
||||
| VacuumEntityFeature.START
|
||||
| VacuumEntityFeature.STOP
|
||||
| VacuumEntityFeature.PAUSE
|
||||
)
|
||||
|
||||
class _LegacyConstantsStateVacuum(StateVacuumEntity):
|
||||
_attr_supported_features = int(features)
|
||||
_attr_fan_speed_list = ["silent", "normal", "pet hair"]
|
||||
|
||||
entity = _LegacyConstantsStateVacuum()
|
||||
assert isinstance(entity.supported_features, int)
|
||||
assert entity.supported_features == int(features)
|
||||
assert entity.supported_features_compat is (
|
||||
VacuumEntityFeature.BATTERY
|
||||
| VacuumEntityFeature.FAN_SPEED
|
||||
| VacuumEntityFeature.START
|
||||
| VacuumEntityFeature.STOP
|
||||
| VacuumEntityFeature.PAUSE
|
||||
)
|
||||
assert entity.state_attributes == {
|
||||
"battery_level": None,
|
||||
"battery_icon": "mdi:battery-unknown",
|
||||
"fan_speed": None,
|
||||
}
|
||||
assert entity.capability_attributes == {
|
||||
"fan_speed_list": ["silent", "normal", "pet hair"]
|
||||
}
|
||||
assert entity._deprecated_supported_features_reported
|
||||
|
||||
|
||||
async def test_vacuum_not_log_deprecated_state_warning(
|
||||
hass: HomeAssistant,
|
||||
mock_vacuum_entity: MockVacuum,
|
||||
|
|
Loading…
Reference in New Issue