Update platform back-compat for custom components without UpdateEntityFeature (#106528)
parent
2b7d37cbc2
commit
d407b9fca8
|
@ -263,7 +263,7 @@ class UpdateEntity(
|
|||
return self._attr_entity_category
|
||||
if hasattr(self, "entity_description"):
|
||||
return self.entity_description.entity_category
|
||||
if UpdateEntityFeature.INSTALL in self.supported_features:
|
||||
if UpdateEntityFeature.INSTALL in self.supported_features_compat:
|
||||
return EntityCategory.CONFIG
|
||||
return EntityCategory.DIAGNOSTIC
|
||||
|
||||
|
@ -322,6 +322,19 @@ class UpdateEntity(
|
|||
"""
|
||||
return self._attr_title
|
||||
|
||||
@property
|
||||
def supported_features_compat(self) -> UpdateEntityFeature:
|
||||
"""Return the supported features as UpdateEntityFeature.
|
||||
|
||||
Remove this compatibility shim in 2025.1 or later.
|
||||
"""
|
||||
features = self.supported_features
|
||||
if type(features) is int: # noqa: E721
|
||||
new_features = UpdateEntityFeature(features)
|
||||
self._report_deprecated_supported_features_values(new_features)
|
||||
return new_features
|
||||
return features
|
||||
|
||||
@final
|
||||
async def async_skip(self) -> None:
|
||||
"""Skip the current offered version to update."""
|
||||
|
@ -408,7 +421,7 @@ class UpdateEntity(
|
|||
|
||||
# If entity supports progress, return the in_progress value.
|
||||
# Otherwise, we use the internal progress value.
|
||||
if UpdateEntityFeature.PROGRESS in self.supported_features:
|
||||
if UpdateEntityFeature.PROGRESS in self.supported_features_compat:
|
||||
in_progress = self.in_progress
|
||||
else:
|
||||
in_progress = self.__in_progress
|
||||
|
@ -444,7 +457,7 @@ class UpdateEntity(
|
|||
Handles setting the in_progress state in case the entity doesn't
|
||||
support it natively.
|
||||
"""
|
||||
if UpdateEntityFeature.PROGRESS not in self.supported_features:
|
||||
if UpdateEntityFeature.PROGRESS not in self.supported_features_compat:
|
||||
self.__in_progress = True
|
||||
self.async_write_ha_state()
|
||||
|
||||
|
@ -490,7 +503,7 @@ async def websocket_release_notes(
|
|||
)
|
||||
return
|
||||
|
||||
if UpdateEntityFeature.RELEASE_NOTES not in entity.supported_features:
|
||||
if UpdateEntityFeature.RELEASE_NOTES not in entity.supported_features_compat:
|
||||
connection.send_error(
|
||||
msg["id"],
|
||||
websocket_api.const.ERR_NOT_SUPPORTED,
|
||||
|
|
|
@ -865,3 +865,23 @@ async def test_name(hass: HomeAssistant) -> None:
|
|||
state = hass.states.get(entity4.entity_id)
|
||||
assert state
|
||||
assert expected.items() <= state.attributes.items()
|
||||
|
||||
|
||||
def test_deprecated_supported_features_ints(caplog: pytest.LogCaptureFixture) -> None:
|
||||
"""Test deprecated supported features ints."""
|
||||
|
||||
class MockUpdateEntity(UpdateEntity):
|
||||
@property
|
||||
def supported_features(self) -> int:
|
||||
"""Return supported features."""
|
||||
return 1
|
||||
|
||||
entity = MockUpdateEntity()
|
||||
assert entity.supported_features_compat is UpdateEntityFeature(1)
|
||||
assert "MockUpdateEntity" in caplog.text
|
||||
assert "is using deprecated supported features values" in caplog.text
|
||||
assert "Instead it should use" in caplog.text
|
||||
assert "UpdateEntityFeature.INSTALL" in caplog.text
|
||||
caplog.clear()
|
||||
assert entity.supported_features_compat is UpdateEntityFeature(1)
|
||||
assert "is using deprecated supported features values" not in caplog.text
|
||||
|
|
Loading…
Reference in New Issue