From 5b2113c43da1d17dc09b47d23d5542d3860884cb Mon Sep 17 00:00:00 2001 From: Mike Degatano Date: Thu, 24 Oct 2024 16:45:35 -0400 Subject: [PATCH] Fix null hass error in supervisor update entities (#129030) * Fix null hass error in supervisor update entities * Share the supervisor client with coordinator * Remove unnecessary patch of helper * Attribute not property --- homeassistant/components/hassio/coordinator.py | 8 ++++---- homeassistant/components/hassio/update.py | 15 +-------------- tests/components/conftest.py | 4 ---- 3 files changed, 5 insertions(+), 22 deletions(-) diff --git a/homeassistant/components/hassio/coordinator.py b/homeassistant/components/hassio/coordinator.py index b3d7b748afcc84..4000bf3783dd68 100644 --- a/homeassistant/components/hassio/coordinator.py +++ b/homeassistant/components/hassio/coordinator.py @@ -318,7 +318,7 @@ def __init__( self._container_updates: defaultdict[str, dict[str, set[str]]] = defaultdict( lambda: defaultdict(set) ) - self._supervisor_client = get_supervisor_client(hass) + self.supervisor_client = get_supervisor_client(hass) async def _async_update_data(self) -> dict[str, Any]: """Update data via library.""" @@ -503,7 +503,7 @@ async def force_data_refresh(self, first_update: bool) -> None: async def _update_addon_stats(self, slug: str) -> tuple[str, dict[str, Any] | None]: """Update single addon stats.""" try: - stats = await self._supervisor_client.addons.addon_stats(slug) + stats = await self.supervisor_client.addons.addon_stats(slug) except SupervisorError as err: _LOGGER.warning("Could not fetch stats for %s: %s", slug, err) return (slug, None) @@ -512,7 +512,7 @@ async def _update_addon_stats(self, slug: str) -> tuple[str, dict[str, Any] | No async def _update_addon_changelog(self, slug: str) -> tuple[str, str | None]: """Return the changelog for an add-on.""" try: - changelog = await self._supervisor_client.store.addon_changelog(slug) + changelog = await self.supervisor_client.store.addon_changelog(slug) except SupervisorError as err: _LOGGER.warning("Could not fetch changelog for %s: %s", slug, err) return (slug, None) @@ -521,7 +521,7 @@ async def _update_addon_changelog(self, slug: str) -> tuple[str, str | None]: async def _update_addon_info(self, slug: str) -> tuple[str, dict[str, Any] | None]: """Return the info for an add-on.""" try: - info = await self._supervisor_client.addons.addon_info(slug) + info = await self.supervisor_client.addons.addon_info(slug) except SupervisorError as err: _LOGGER.warning("Could not fetch info for %s: %s", slug, err) return (slug, None) diff --git a/homeassistant/components/hassio/update.py b/homeassistant/components/hassio/update.py index c32d7d43694a91..60d02a61095d39 100644 --- a/homeassistant/components/hassio/update.py +++ b/homeassistant/components/hassio/update.py @@ -17,7 +17,6 @@ from homeassistant.const import ATTR_ICON, ATTR_NAME from homeassistant.core import HomeAssistant from homeassistant.exceptions import HomeAssistantError -from homeassistant.helpers.entity import EntityDescription from homeassistant.helpers.entity_platform import AddEntitiesCallback from .const import ( @@ -31,7 +30,6 @@ DATA_KEY_OS, DATA_KEY_SUPERVISOR, ) -from .coordinator import HassioDataUpdateCoordinator from .entity import ( HassioAddonEntity, HassioCoreEntity, @@ -43,7 +41,6 @@ async_update_core, async_update_os, async_update_supervisor, - get_supervisor_client, ) ENTITY_DESCRIPTION = UpdateEntityDescription( @@ -100,16 +97,6 @@ class SupervisorAddonUpdateEntity(HassioAddonEntity, UpdateEntity): | UpdateEntityFeature.RELEASE_NOTES ) - def __init__( - self, - coordinator: HassioDataUpdateCoordinator, - entity_description: EntityDescription, - addon: dict[str, Any], - ) -> None: - """Initialize object.""" - super().__init__(coordinator, entity_description, addon) - self._supervisor_client = get_supervisor_client(self.hass) - @property def _addon_data(self) -> dict: """Return the add-on data.""" @@ -179,7 +166,7 @@ async def async_install( ) -> None: """Install an update.""" try: - await self._supervisor_client.store.update_addon( + await self.coordinator.supervisor_client.store.update_addon( self._addon_slug, StoreAddonUpdate(backup=backup) ) except SupervisorError as err: diff --git a/tests/components/conftest.py b/tests/components/conftest.py index 00e440cd0a26e5..84614334eef08c 100644 --- a/tests/components/conftest.py +++ b/tests/components/conftest.py @@ -477,10 +477,6 @@ def supervisor_client() -> Generator[AsyncMock]: "homeassistant.components.hassio.coordinator.get_supervisor_client", return_value=supervisor_client, ), - patch( - "homeassistant.components.hassio.update.get_supervisor_client", - return_value=supervisor_client, - ), patch( "homeassistant.components.hassio.get_supervisor_client", return_value=supervisor_client,