Skip to content

Commit

Permalink
Merge pull request #85 from iprak/handle-missing-devices
Browse files Browse the repository at this point in the history
Handle missing devices wrappers
  • Loading branch information
iprak authored Nov 10, 2024
2 parents 3150404 + f802698 commit 666ce94
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions custom_components/winix/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,9 @@ def __init__(
) -> None:
"""Initialize the manager."""

self._device_wrappers: list[WinixDeviceWrapper] = None
# Always initialize _device_wrappers in case async_prepare_devices_wrappers
# was not invoked.
self._device_wrappers: list[WinixDeviceWrapper] = []
self._auth_response = auth_response

super().__init__(
Expand All @@ -86,20 +88,21 @@ def __init__(
)

async def _async_update_data(self):
"""Fetch the latest data from the source. This overrides the method in DataUpdateCoordinator."""
await self.async_update()

async def async_prepare_devices_wrappers(self) -> bool:
async def async_prepare_devices_wrappers(self) -> None:
"""Prepare device wrappers.
Raises WinixException.
"""

self._device_wrappers = [] # Reset device_stubs

device_stubs = await Helpers.async_get_device_stubs(
self.hass, self._auth_response.access_token
)

self._device_wrappers = [] # initialize even if we have no device_stubs

if device_stubs:
client = aiohttp_client.async_get_clientsession(self.hass)

Expand All @@ -112,10 +115,7 @@ async def async_prepare_devices_wrappers(self) -> bool:
else:
_LOGGER.info("No purifiers found")

return True

async def async_update(self, now=None) -> None:
# pylint: disable=unused-argument
"""Asynchronously update all the devices."""
_LOGGER.info("Updating devices")
for device_wrapper in self._device_wrappers:
Expand Down

0 comments on commit 666ce94

Please sign in to comment.