Skip to content

Commit

Permalink
Update pyTibber to 0.27.0 (home-assistant#86940)
Browse files Browse the repository at this point in the history
* Update pyTibber to 0.27.0

* Handle new exceptions
  • Loading branch information
toini authored Mar 2, 2023
1 parent fd4d79d commit f69aa7a
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 15 deletions.
15 changes: 8 additions & 7 deletions homeassistant/components/tibber/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,17 +53,18 @@ async def _close(event: Event) -> None:

try:
await tibber_connection.update_info()
if not tibber_connection.name:
raise ConfigEntryNotReady("Could not fetch Tibber data.")

except asyncio.TimeoutError as err:
raise ConfigEntryNotReady from err
except aiohttp.ClientError as err:
_LOGGER.error("Error connecting to Tibber: %s ", err)
return False
except (
asyncio.TimeoutError,
aiohttp.ClientError,
tibber.RetryableHttpException,
) as err:
raise ConfigEntryNotReady("Unable to connect") from err
except tibber.InvalidLogin as exp:
_LOGGER.error("Failed to login. %s", exp)
return False
except tibber.FatalHttpException:
return False

await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)

Expand Down
8 changes: 6 additions & 2 deletions homeassistant/components/tibber/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,14 @@ async def async_step_user(
await tibber_connection.update_info()
except asyncio.TimeoutError:
errors[CONF_ACCESS_TOKEN] = "timeout"
except aiohttp.ClientError:
errors[CONF_ACCESS_TOKEN] = "cannot_connect"
except tibber.InvalidLogin:
errors[CONF_ACCESS_TOKEN] = "invalid_access_token"
except (
aiohttp.ClientError,
tibber.RetryableHttpException,
tibber.FatalHttpException,
):
errors[CONF_ACCESS_TOKEN] = "cannot_connect"

if errors:
return self.async_show_form(
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/tibber/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
"iot_class": "cloud_polling",
"loggers": ["tibber"],
"quality_scale": "silver",
"requirements": ["pyTibber==0.26.13"]
"requirements": ["pyTibber==0.27.0"]
}
17 changes: 14 additions & 3 deletions homeassistant/components/tibber/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
UpdateFailed,
)
from homeassistant.util import Throttle, dt as dt_util

Expand Down Expand Up @@ -559,6 +560,8 @@ def get_live_measurement(self) -> Any:
class TibberDataCoordinator(DataUpdateCoordinator[None]):
"""Handle Tibber data and insert statistics."""

config_entry: ConfigEntry

def __init__(self, hass: HomeAssistant, tibber_connection: tibber.Tibber) -> None:
"""Initialize the data handler."""
super().__init__(
Expand All @@ -571,9 +574,17 @@ def __init__(self, hass: HomeAssistant, tibber_connection: tibber.Tibber) -> Non

async def _async_update_data(self) -> None:
"""Update data via API."""
await self._tibber_connection.fetch_consumption_data_active_homes()
await self._tibber_connection.fetch_production_data_active_homes()
await self._insert_statistics()
try:
await self._tibber_connection.fetch_consumption_data_active_homes()
await self._tibber_connection.fetch_production_data_active_homes()
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:
"""Insert Tibber statistics."""
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1473,7 +1473,7 @@ pyRFXtrx==0.30.1
pySwitchmate==0.5.1

# homeassistant.components.tibber
pyTibber==0.26.13
pyTibber==0.27.0

# homeassistant.components.dlink
pyW215==0.7.0
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1076,7 +1076,7 @@ pyMetno==0.9.0
pyRFXtrx==0.30.1

# homeassistant.components.tibber
pyTibber==0.26.13
pyTibber==0.27.0

# homeassistant.components.dlink
pyW215==0.7.0
Expand Down

0 comments on commit f69aa7a

Please sign in to comment.