Skip to content

Commit

Permalink
🐛 Process 403 error from server like '401 unauthorized'
Browse files Browse the repository at this point in the history
raising `BadApiTokenAuthError` to signal HA for reauth-config
for both status codes, when API token is enabled
  • Loading branch information
azogue committed Mar 12, 2023
1 parent 7a1911a commit 76ad576
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# Changelog

## [v4.1.0](https://github.com/azogue/aiopvpc/tree/v4.0.1) - Adapt to 403 unauthorized error (2023-03-12)

[Full Changelog](https://github.com/azogue/aiopvpc/compare/v4.1.0...v4.0.1)

- 🐛 Process 403 error from server like '401 unauthorized', raising `BadApiTokenAuthError`
to signal HA for reauth-config for both status codes, when API token is enabled.

## [v4.0.1](https://github.com/azogue/aiopvpc/tree/v4.0.1) - Minor fixes (2023-01-11)

[Full Changelog](https://github.com/azogue/aiopvpc/compare/v4.0.1...v4.0.0)
Expand Down
2 changes: 1 addition & 1 deletion aiopvpc/pvpc_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ async def _api_get_data(self, sensor_key: str, url: str) -> EsiosResponse | None
return extract_esios_data(
data, url, sensor_key, self.tariff, tz=self._local_timezone
)
elif resp.status == 401 and self._data_source == "esios":
elif resp.status in (401, 403) and self._data_source == "esios":
_LOGGER.warning(
"[%s] Unauthorized error with '%s': %s",
sensor_key,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ markers = [

[tool.poetry]
name = "aiopvpc"
version = "4.0.1"
version = "4.1.0"
description = "Retrieval of Spanish Electricity hourly prices (PVPC)"
authors = ["Eugenio Panadero <[email protected]>"]
license = "MIT"
Expand Down
3 changes: 2 additions & 1 deletion tests/test_pvpc.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
(
("esios_public", None, "2032-10-26", 0, 200, None),
("esios_public", None, "2032-10-26", 1, 500, None),
("esios", "bad-token", "2032-10-26", 1, 403, None),
("esios", "bad-token", "2032-10-26", 1, 401, None),
("esios_public", None, "2032-10-26", 1, 200, TimeoutError),
("esios_public", None, "2032-10-26", 1, 200, ClientError),
Expand All @@ -50,7 +51,7 @@ async def test_bad_downloads(
data_source=cast(DataSource, data_source),
api_token=api_token,
)
if status == 401:
if status in (401, 403):
with pytest.raises(BadApiTokenAuthError):
await pvpc_data.async_update_all(None, day)
assert mock_session.call_count == 1
Expand Down

0 comments on commit 76ad576

Please sign in to comment.