Update pyTibber to 0.27.0 (#86940)

* Update pyTibber to 0.27.0

* Handle new exceptions
This commit is contained in:
Toni Juvani 2023-03-02 17:11:34 +02:00 committed by GitHub
parent fd4d79d24c
commit f69aa7ad9d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 31 additions and 15 deletions

View file

@ -53,17 +53,18 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
try: try:
await tibber_connection.update_info() await tibber_connection.update_info()
if not tibber_connection.name:
raise ConfigEntryNotReady("Could not fetch Tibber data.")
except asyncio.TimeoutError as err: except (
raise ConfigEntryNotReady from err asyncio.TimeoutError,
except aiohttp.ClientError as err: aiohttp.ClientError,
_LOGGER.error("Error connecting to Tibber: %s ", err) tibber.RetryableHttpException,
return False ) as err:
raise ConfigEntryNotReady("Unable to connect") from err
except tibber.InvalidLogin as exp: except tibber.InvalidLogin as exp:
_LOGGER.error("Failed to login. %s", exp) _LOGGER.error("Failed to login. %s", exp)
return False return False
except tibber.FatalHttpException:
return False
await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS) await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

View file

@ -44,10 +44,14 @@ class TibberConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
await tibber_connection.update_info() await tibber_connection.update_info()
except asyncio.TimeoutError: except asyncio.TimeoutError:
errors[CONF_ACCESS_TOKEN] = "timeout" errors[CONF_ACCESS_TOKEN] = "timeout"
except aiohttp.ClientError:
errors[CONF_ACCESS_TOKEN] = "cannot_connect"
except tibber.InvalidLogin: except tibber.InvalidLogin:
errors[CONF_ACCESS_TOKEN] = "invalid_access_token" errors[CONF_ACCESS_TOKEN] = "invalid_access_token"
except (
aiohttp.ClientError,
tibber.RetryableHttpException,
tibber.FatalHttpException,
):
errors[CONF_ACCESS_TOKEN] = "cannot_connect"
if errors: if errors:
return self.async_show_form( return self.async_show_form(

View file

@ -8,5 +8,5 @@
"iot_class": "cloud_polling", "iot_class": "cloud_polling",
"loggers": ["tibber"], "loggers": ["tibber"],
"quality_scale": "silver", "quality_scale": "silver",
"requirements": ["pyTibber==0.26.13"] "requirements": ["pyTibber==0.27.0"]
} }

View file

@ -44,6 +44,7 @@ from homeassistant.helpers.entity_registry import async_get as async_get_entity_
from homeassistant.helpers.update_coordinator import ( from homeassistant.helpers.update_coordinator import (
CoordinatorEntity, CoordinatorEntity,
DataUpdateCoordinator, DataUpdateCoordinator,
UpdateFailed,
) )
from homeassistant.util import Throttle, dt as dt_util from homeassistant.util import Throttle, dt as dt_util
@ -559,6 +560,8 @@ class TibberRtDataCoordinator(DataUpdateCoordinator):
class TibberDataCoordinator(DataUpdateCoordinator[None]): class TibberDataCoordinator(DataUpdateCoordinator[None]):
"""Handle Tibber data and insert statistics.""" """Handle Tibber data and insert statistics."""
config_entry: ConfigEntry
def __init__(self, hass: HomeAssistant, tibber_connection: tibber.Tibber) -> None: def __init__(self, hass: HomeAssistant, tibber_connection: tibber.Tibber) -> None:
"""Initialize the data handler.""" """Initialize the data handler."""
super().__init__( super().__init__(
@ -571,9 +574,17 @@ class TibberDataCoordinator(DataUpdateCoordinator[None]):
async def _async_update_data(self) -> None: async def _async_update_data(self) -> None:
"""Update data via API.""" """Update data via API."""
try:
await self._tibber_connection.fetch_consumption_data_active_homes() await self._tibber_connection.fetch_consumption_data_active_homes()
await self._tibber_connection.fetch_production_data_active_homes() await self._tibber_connection.fetch_production_data_active_homes()
await self._insert_statistics() await self._insert_statistics()
except tibber.RetryableHttpException as err:
raise UpdateFailed(f"Error communicating with API ({err.status})") from err
except tibber.FatalHttpException:
# Fatal error. Reload config entry to show correct error.
self.hass.async_create_task(
self.hass.config_entries.async_reload(self.config_entry.entry_id)
)
async def _insert_statistics(self) -> None: async def _insert_statistics(self) -> None:
"""Insert Tibber statistics.""" """Insert Tibber statistics."""

View file

@ -1473,7 +1473,7 @@ pyRFXtrx==0.30.1
pySwitchmate==0.5.1 pySwitchmate==0.5.1
# homeassistant.components.tibber # homeassistant.components.tibber
pyTibber==0.26.13 pyTibber==0.27.0
# homeassistant.components.dlink # homeassistant.components.dlink
pyW215==0.7.0 pyW215==0.7.0

View file

@ -1076,7 +1076,7 @@ pyMetno==0.9.0
pyRFXtrx==0.30.1 pyRFXtrx==0.30.1
# homeassistant.components.tibber # homeassistant.components.tibber
pyTibber==0.26.13 pyTibber==0.27.0
# homeassistant.components.dlink # homeassistant.components.dlink
pyW215==0.7.0 pyW215==0.7.0