diff --git a/custom_components/winix/manager.py b/custom_components/winix/manager.py index f41c778..90fd9b7 100644 --- a/custom_components/winix/manager.py +++ b/custom_components/winix/manager.py @@ -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__( @@ -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) @@ -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: