Skip to content

Commit

Permalink
Merge pull request #591 from MTrab:Fix-error-checking-for-tariff-status
Browse files Browse the repository at this point in the history
Fix error when tariff API is not responding
  • Loading branch information
MTrab authored Sep 12, 2024
2 parents 0acce50 + f585978 commit c4d8b13
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
8 changes: 4 additions & 4 deletions config/configuration.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
default_config:

#logger:
# default: warning
# logs:
# custom_components.energidataservice: debug
logger:
default: warning
logs:
custom_components.energidataservice: debug

# If you need to debug uncomment the line below (doc: https://www.home-assistant.io/integrations/debugpy/)
# debugpy:
8 changes: 5 additions & 3 deletions custom_components/energidataservice/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,6 @@ async def update_carnot(self, dt=None) -> None: # type: ignore pylint: disable=
async def async_get_tariffs(self) -> None:
"""Get tariff data."""

if self.api.status != 200:
retry_update(self, self.async_get_tariffs)

if self.tariff:
tariff_endpoint = await self.tariffs.get_endpoint(self._region.region)
tariff_module = await self.hass.async_add_executor_job(
Expand All @@ -306,8 +303,13 @@ async def async_get_tariffs(self) -> None:
)

self.tariff_connector = tariff

self.tariff_data = await tariff.async_get_tariffs()

if self.tariff_data["status"] != 200:
retry_update(self, self.async_get_tariffs)


@property
def tomorrow_valid(self) -> bool:
"""Is tomorrows prices valid?."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ def __init__(
self._additional_tariff = {}
self._all_tariffs = {}
self._all_additional_tariffs = {}
self.status = 418

@property
def tariffs(self):
Expand All @@ -44,6 +45,7 @@ def tariffs(self):
tariffs = {
"additional_tariffs": self._additional_tariff,
"tariffs": self._tariffs,
"status": self.status,
}

return tariffs
Expand Down Expand Up @@ -191,6 +193,7 @@ async def async_call_api(self, query: str) -> dict:
try:
headers = self._header()
resp = await self.client.get(f"{BASE_URL}?{query}", headers=headers)
self.status = resp.status
resp.raise_for_status()

if resp.status == 400:
Expand Down

0 comments on commit c4d8b13

Please sign in to comment.