Update platform back-compat for custom components without UpdateEntityFeature (#106528)

This commit is contained in:
J. Nick Koston 2023-12-28 14:10:26 -10:00 committed by Franck Nijhof
parent 2b7d37cbc2
commit d407b9fca8
No known key found for this signature in database
GPG key ID: D62583BA8AB11CA3
2 changed files with 37 additions and 4 deletions

View file

@ -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,