Add full release notes to add-on update entities (#68876)

This commit is contained in:
Joakim Sørensen 2022-03-30 09:52:29 +02:00 committed by GitHub
parent 5cd532b16a
commit 618b16a32b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 129 additions and 8 deletions

View file

@ -88,39 +88,65 @@ async def async_setup_entry(
class SupervisorAddonUpdateEntity(HassioAddonEntity, UpdateEntity):
"""Update entity to handle updates for the Supervisor add-ons."""
_attr_supported_features = UpdateEntityFeature.INSTALL | UpdateEntityFeature.BACKUP
_attr_supported_features = (
UpdateEntityFeature.INSTALL
| UpdateEntityFeature.BACKUP
| UpdateEntityFeature.RELEASE_NOTES
)
@property
def _addon_data(self) -> dict:
"""Return the add-on data."""
return self.coordinator.data[DATA_KEY_ADDONS][self._addon_slug]
@property
def title(self) -> str | None:
"""Return the title of the update."""
return self.coordinator.data[DATA_KEY_ADDONS][self._addon_slug][ATTR_NAME]
return self._addon_data[ATTR_NAME]
@property
def latest_version(self) -> str | None:
"""Latest version available for install."""
return self.coordinator.data[DATA_KEY_ADDONS][self._addon_slug][
ATTR_VERSION_LATEST
]
return self._addon_data[ATTR_VERSION_LATEST]
@property
def current_version(self) -> str | None:
"""Version currently in use."""
return self.coordinator.data[DATA_KEY_ADDONS][self._addon_slug][ATTR_VERSION]
return self._addon_data[ATTR_VERSION]
@property
def release_summary(self) -> str | None:
"""Release summary for the add-on."""
return self.coordinator.data[DATA_KEY_ADDONS][self._addon_slug][ATTR_CHANGELOG]
return self._strip_release_notes()
@property
def entity_picture(self) -> str | None:
"""Return the icon of the add-on if any."""
if not self.available:
return None
if self.coordinator.data[DATA_KEY_ADDONS][self._addon_slug][ATTR_ICON]:
if self._addon_data[ATTR_ICON]:
return f"/api/hassio/addons/{self._addon_slug}/icon"
return None
def _strip_release_notes(self) -> str | None:
"""Strip the release notes to contain the needed sections."""
if (notes := self._addon_data[ATTR_CHANGELOG]) is None:
return None
if f"# {self.latest_version}" in notes and f"# {self.current_version}" in notes:
# Split the release notes to only what is between the versions if we can
new_notes = notes.split(f"# {self.current_version}")[0]
if f"# {self.latest_version}" in new_notes:
# Make sure the latest version is still there.
# This can be False if the order of the release notes are not correct
# In that case we just return the whole release notes
return new_notes
return notes
async def async_release_notes(self) -> str | None:
"""Return the release notes for the update."""
return self._strip_release_notes()
async def async_install(
self,
version: str | None = None,