Update pyTibber to 0.27.0#86940
Conversation
|
Hi toini It seems you haven't yet signed a CLA. Please do so here. Once you do that we will be able to review and accept this pull request. Thanks! |
|
Hey there @Danielhiversen, mind taking a look at this pull request as it has been labeled with an integration ( Code owner commandsCode owners of
|
|
Please add a link to a changelog or GitHub commit compare view for the version bump in the PR description. Thanks! |
|
Please sign the CLA. |
|
Thanks There are some breaking changes in the latest version of pyTibber that needs to be addressed: https://github.com/Danielhiversen/pyTibber/releases/tag/0.27.0 You should also fill out the checklist in this pull request. Most important You also need to sign the CLA. Please do so here. |
|
@ztamas83 any chance you would be able to run this locally (I dont have Home Assistant set up myself) so we can tick off |
|
@MartinHjelmare @Danielhiversen CLA signed, change log for pyTibber added and I've requested @ztamas83 to test this locally. TODO: addressing the breaking changes. |
Run in a local dev container, Tibber connected and live data received with my own credentials. 2023-01-30 19:53:57.211 DEBUG (MainThread) [tibber] Using websocket subscription url wss://websocket-api.tibber.com/v1-beta/gql/subscriptions |
|
Updated |
|
@Danielhiversen do you know of any blockers for merge due to the breaking changes listed in pyTibber? |
|
There is a merge conflict, can you please take a look? I've marked this PR in the mean time. Please un-draft it once it is ready for review again by clicking the "Ready for review" button. Thanks! 👍 ../Frenck |
|
Converting to draft until the breaking changes either have been addressed or confirmed not affecting the integration. |
|
The new exceptions should be handled here FatalHttpException -> return False RetryableHttpException -> raise ConfigEntryNotReady Then this is no longer needed: core/homeassistant/components/tibber/__init__.py Lines 56 to 57 in e96210f Same here: FatalHttpException -> cannot_connect error RetryableHttpException -> should probably give a new error message |
|
@Danielhiversen would you be happy to adjust the code accordingly? You do have access. |
|
I don't have time to prioritize it in the short term. |
|
Since your org forbids me to push commits, @toini, add this commit. It's untested. commit b7c1617b418b718f20eb839c9137f8464985ce51
Author: Paulus Schoutsen <balloob@gmail.com>
Date: Wed Mar 1 11:27:54 2023 -0500
Handle new exceptions
diff --git a/homeassistant/components/tibber/__init__.py b/homeassistant/components/tibber/__init__.py
index 4d9c056068..6bd68e17c4 100644
--- a/homeassistant/components/tibber/__init__.py
+++ b/homeassistant/components/tibber/__init__.py
@@ -53,17 +53,18 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
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)
diff --git a/homeassistant/components/tibber/config_flow.py b/homeassistant/components/tibber/config_flow.py
index d0adc0391a..b5cb4486cc 100644
--- a/homeassistant/components/tibber/config_flow.py
+++ b/homeassistant/components/tibber/config_flow.py
@@ -44,10 +44,14 @@ class TibberConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
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(
diff --git a/homeassistant/components/tibber/sensor.py b/homeassistant/components/tibber/sensor.py
index 2fe9e290d0..51bb9cda9a 100644
--- a/homeassistant/components/tibber/sensor.py
+++ b/homeassistant/components/tibber/sensor.py
@@ -44,6 +44,7 @@ from homeassistant.helpers.entity_registry import async_get as async_get_entity_
from homeassistant.helpers.update_coordinator import (
CoordinatorEntity,
DataUpdateCoordinator,
+ UpdateFailed,
)
from homeassistant.util import Throttle, dt as dt_util
@@ -560,6 +561,8 @@ class TibberRtDataCoordinator(DataUpdateCoordinator):
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__(
@@ -572,9 +575,17 @@ class TibberDataCoordinator(DataUpdateCoordinator[None]):
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.""" |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
|
@toini |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
|
|
@balloob tried to patch just now but i got hunk at line 44 did not apply |
|
patch applied, @balloob maybe you can double check? |
|
@Danielhiversen can we merge this first. I guess we are not far away anymore? |
| errors[CONF_ACCESS_TOKEN] = "cannot_connect" | ||
| except tibber.InvalidLogin: | ||
| errors[CONF_ACCESS_TOKEN] = "invalid_access_token" | ||
| except ( |
There was a problem hiding this comment.
We normally require 100% coverage on config flows. Could tests be added?
There was a problem hiding this comment.
I have near to 0 experience on python/unit testing on python and thus i've been strugling with this repo we try to help migrate to the new websocket endpoint. All assistance is welcome! @epenet.
There was a problem hiding this comment.
I will have a look, shall I just create a new PR when done?
There was a problem hiding this comment.
Yes please - and add a comment here with the link to the new PR
There was a problem hiding this comment.
#89088 adds unit tests for the config flow errors
* Update pyTibber to 0.27.0 * Handle new exceptions
Breaking change
Glitre grid prices are removed as sensor attribute
Proposed change
Type of change
Additional information
This PR upgrades pyTibber to a version that dynamically queries web socket server URL effectively switching to new Tibber web socket server. More info at https://developer.tibber.com/.
Change log: Danielhiversen/pyTibber@0.26.8...0.27.0
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.To help with the load of incoming pull requests: