55from types import MappingProxyType
66from typing import Any , cast
77
8- import aiohttp
98from opower import (
109 Account ,
1110 AggregateType ,
12- CannotConnect ,
1311 CostRead ,
1412 Forecast ,
15- InvalidAuth ,
1613 MeterType ,
1714 Opower ,
1815 ReadResolution ,
1916)
17+ from opower .exceptions import ApiException , CannotConnect , InvalidAuth
2018
2119from homeassistant .components .recorder import get_instance
2220from homeassistant .components .recorder .models import StatisticData , StatisticMetaData
@@ -89,7 +87,7 @@ async def _async_update_data(
8987 raise UpdateFailed (f"Error during login: { err } " ) from err
9088 try :
9189 forecasts : list [Forecast ] = await self .api .async_get_forecast ()
92- except aiohttp . ClientError as err :
90+ except ApiException as err :
9391 _LOGGER .error ("Error getting forecasts: %s" , err )
9492 raise
9593 _LOGGER .debug ("Updating sensor data with: %s" , forecasts )
@@ -102,7 +100,7 @@ async def _insert_statistics(self) -> None:
102100 """Insert Opower statistics."""
103101 try :
104102 accounts = await self .api .async_get_accounts ()
105- except aiohttp . ClientError as err :
103+ except ApiException as err :
106104 _LOGGER .error ("Error getting accounts: %s" , err )
107105 raise
108106 for account in accounts :
@@ -271,7 +269,7 @@ def _update_with_finer_cost_reads(
271269 cost_reads = await self .api .async_get_cost_reads (
272270 account , AggregateType .BILL , start , end
273271 )
274- except aiohttp . ClientError as err :
272+ except ApiException as err :
275273 _LOGGER .error ("Error getting monthly cost reads: %s" , err )
276274 raise
277275 _LOGGER .debug ("Got %s monthly cost reads" , len (cost_reads ))
@@ -290,7 +288,7 @@ def _update_with_finer_cost_reads(
290288 daily_cost_reads = await self .api .async_get_cost_reads (
291289 account , AggregateType .DAY , start , end
292290 )
293- except aiohttp . ClientError as err :
291+ except ApiException as err :
294292 _LOGGER .error ("Error getting daily cost reads: %s" , err )
295293 raise
296294 _LOGGER .debug ("Got %s daily cost reads" , len (daily_cost_reads ))
@@ -308,7 +306,7 @@ def _update_with_finer_cost_reads(
308306 hourly_cost_reads = await self .api .async_get_cost_reads (
309307 account , AggregateType .HOUR , start , end
310308 )
311- except aiohttp . ClientError as err :
309+ except ApiException as err :
312310 _LOGGER .error ("Error getting hourly cost reads: %s" , err )
313311 raise
314312 _LOGGER .debug ("Got %s hourly cost reads" , len (hourly_cost_reads ))
0 commit comments