|
5 | 5 |
|
6 | 6 | from aiorinnai.api import API |
7 | 7 | from aiorinnai.errors import RequestError |
| 8 | +from aiorinnai.api import Unauthenticated |
| 9 | +from homeassistant.exceptions import ConfigEntryAuthFailed |
8 | 10 | from async_timeout import timeout |
9 | 11 |
|
10 | 12 | from homeassistant.core import HomeAssistant |
@@ -54,6 +56,9 @@ async def _async_update_data(self) -> None: |
54 | 56 | await asyncio.gather( |
55 | 57 | self._update_device() |
56 | 58 | ) |
| 59 | + except Unauthenticated as error: |
| 60 | + LOGGER.error("Authentication error: %s", error) |
| 61 | + raise ConfigEntryAuthFailed from error |
57 | 62 | except RequestError as error: |
58 | 63 | raise UpdateFailed(error) from error |
59 | 64 |
|
@@ -193,30 +198,78 @@ def pump_cycles(self) -> Optional[float]: |
193 | 198 | return float(self._device_information["data"]["getDevice"]["info"]["m20_pump_cycles"]) |
194 | 199 |
|
195 | 200 | async def async_set_temperature(self, temperature: int) -> None: |
196 | | - await self.api_client.device.set_temperature(self._device_information["data"]["getDevice"], temperature) |
| 201 | + try: |
| 202 | + await self.api_client.device.set_temperature(self._device_information["data"]["getDevice"], temperature) |
| 203 | + except Unauthenticated as error: |
| 204 | + LOGGER.error("Authentication error: %s", error) |
| 205 | + raise ConfigEntryAuthFailed from error |
| 206 | + except RequestError as error: |
| 207 | + raise UpdateFailed(error) from error |
197 | 208 |
|
198 | 209 | async def async_start_recirculation(self, duration: int) -> None: |
199 | | - await self.api_client.device.start_recirculation(self._device_information["data"]["getDevice"], duration) |
| 210 | + try: |
| 211 | + await self.api_client.device.start_recirculation(self._device_information["data"]["getDevice"], duration) |
| 212 | + except Unauthenticated as error: |
| 213 | + LOGGER.error("Authentication error: %s", error) |
| 214 | + raise ConfigEntryAuthFailed from error |
| 215 | + except RequestError as error: |
| 216 | + raise UpdateFailed(error) from error |
200 | 217 |
|
201 | 218 | async def async_stop_recirculation(self) -> None: |
202 | | - await self.api_client.device.stop_recirculation(self._device_information["data"]["getDevice"]) |
| 219 | + try: |
| 220 | + await self.api_client.device.stop_recirculation(self._device_information["data"]["getDevice"]) |
| 221 | + except Unauthenticated as error: |
| 222 | + LOGGER.error("Authentication error: %s", error) |
| 223 | + raise ConfigEntryAuthFailed from error |
| 224 | + except RequestError as error: |
| 225 | + raise UpdateFailed(error) from error |
203 | 226 |
|
204 | 227 | async def async_enable_vacation_mode(self) -> None: |
205 | | - await self.api_client.device.enable_vacation_mode(self._device_information["data"]["getDevice"]) |
| 228 | + try: |
| 229 | + await self.api_client.device.enable_vacation_mode(self._device_information["data"]["getDevice"]) |
| 230 | + except Unauthenticated as error: |
| 231 | + LOGGER.error("Authentication error: %s", error) |
| 232 | + raise ConfigEntryAuthFailed from error |
| 233 | + except RequestError as error: |
| 234 | + raise UpdateFailed(error) from error |
206 | 235 |
|
207 | 236 | async def async_disable_vacation_mode(self) -> None: |
208 | | - await self.api_client.device.disable_vacation_mode(self._device_information["data"]["getDevice"]) |
| 237 | + try: |
| 238 | + await self.api_client.device.disable_vacation_mode(self._device_information["data"]["getDevice"]) |
| 239 | + except Unauthenticated as error: |
| 240 | + LOGGER.error("Authentication error: %s", error) |
| 241 | + raise ConfigEntryAuthFailed from error |
| 242 | + except RequestError as error: |
| 243 | + raise UpdateFailed(error) from error |
209 | 244 |
|
210 | 245 | async def async_turn_off(self) -> None: |
211 | | - await self.api_client.device.turn_off(self._device_information["data"]["getDevice"]) |
| 246 | + try: |
| 247 | + await self.api_client.device.turn_off(self._device_information["data"]["getDevice"]) |
| 248 | + except Unauthenticated as error: |
| 249 | + LOGGER.error("Authentication error: %s", error) |
| 250 | + raise ConfigEntryAuthFailed from error |
| 251 | + except RequestError as error: |
| 252 | + raise UpdateFailed(error) from error |
212 | 253 |
|
213 | 254 | async def async_turn_on(self) -> None: |
214 | | - await self.api_client.device.turn_on(self._device_information["data"]["getDevice"]) |
| 255 | + try: |
| 256 | + await self.api_client.device.turn_on(self._device_information["data"]["getDevice"]) |
| 257 | + except Unauthenticated as error: |
| 258 | + LOGGER.error("Authentication error: %s", error) |
| 259 | + raise ConfigEntryAuthFailed from error |
| 260 | + except RequestError as error: |
| 261 | + raise UpdateFailed(error) from error |
215 | 262 |
|
216 | 263 | @Throttle(MIN_TIME_BETWEEN_UPDATES) |
217 | 264 | async def async_do_maintenance_retrieval(self) -> None: |
218 | | - await self.api_client.device.do_maintenance_retrieval(self._device_information["data"]["getDevice"]) |
219 | | - LOGGER.debug("Rinnai Maintenance Retrieval Started") |
| 265 | + try: |
| 266 | + await self.api_client.device.do_maintenance_retrieval(self._device_information["data"]["getDevice"]) |
| 267 | + LOGGER.debug("Rinnai Maintenance Retrieval Started") |
| 268 | + except Unauthenticated as error: |
| 269 | + LOGGER.error("Authentication error: %s", error) |
| 270 | + raise ConfigEntryAuthFailed from error |
| 271 | + except RequestError as error: |
| 272 | + raise UpdateFailed(error) from error |
220 | 273 |
|
221 | 274 | async def _update_device(self, *_) -> None: |
222 | 275 | """Update the device information from the API""" |
|
0 commit comments