|
8 | 8 | DataUpdateCoordinator,
|
9 | 9 | UpdateFailed,
|
10 | 10 | )
|
11 |
| -from .exceptions import WemPortalError |
| 11 | +from .exceptions import ServerError, WemPortalError |
12 | 12 | from .const import _LOGGER, DEFAULT_TIMEOUT
|
13 | 13 | from homeassistant.const import CONF_PASSWORD, CONF_USERNAME
|
14 | 14 | from .wemportalapi import WemPortalApi
|
@@ -41,16 +41,26 @@ async def _async_update_data(self):
|
41 | 41 | try:
|
42 | 42 | return await self.hass.async_add_executor_job(self.api.fetch_data)
|
43 | 43 | except WemPortalError as exc:
|
44 |
| - _LOGGER.error("Error fetching data from wemportal", exc_info=exc) |
45 |
| - _LOGGER.error("Creating new wemportal api instance") |
46 |
| - # TODO: This is a temporary solution and should be removed when api cause from #28 is resolved |
47 |
| - try: |
48 |
| - new_api = WemPortalApi( |
49 |
| - self.config_entry.data.get(CONF_USERNAME), |
50 |
| - self.config_entry.data.get(CONF_PASSWORD), |
51 |
| - self.config_entry.options, |
52 |
| - ) |
53 |
| - self.api = new_api |
54 |
| - except Exception: |
55 |
| - pass |
56 |
| - raise UpdateFailed from exc |
| 44 | + |
| 45 | + if isinstance(exc.__cause__, ServerError): |
| 46 | + _LOGGER.error("Creating new wemportal api instance") |
| 47 | + # TODO: This is a temporary solution and should be removed when api cause from #28 is resolved |
| 48 | + try: |
| 49 | + new_api = WemPortalApi( |
| 50 | + self.config_entry.data.get(CONF_USERNAME), |
| 51 | + self.config_entry.data.get(CONF_PASSWORD), |
| 52 | + self.config_entry.options, |
| 53 | + ) |
| 54 | + self.api = new_api |
| 55 | + except Exception as exc2: |
| 56 | + raise UpdateFailed from exc2 |
| 57 | + try: |
| 58 | + return await self.hass.async_add_executor_job(self.api.fetch_data) |
| 59 | + except WemPortalError as exc2: |
| 60 | + _LOGGER.error("Error fetching data from wemportal", exc_info=exc) |
| 61 | + raise UpdateFailed from exc2 |
| 62 | + else: |
| 63 | + _LOGGER.error("Error fetching data from wemportal", exc_info=exc) |
| 64 | + raise UpdateFailed from exc |
| 65 | + |
| 66 | + |
0 commit comments