Skip to content

Commit

Permalink
2.1.0 limit the number of short term retries if any failure would occur
Browse files Browse the repository at this point in the history
  • Loading branch information
myTselection committed Oct 5, 2023
1 parent 34bb7c8 commit 4018943
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion custom_components/myenergy/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
"iot_class": "cloud_polling",
"issue_tracker": "https://github.com/myTselection/MyEnergy/issues",
"requirements": ["bs4","requests"],
"version": "2.0.0"
"version": "2.1.0"
}
5 changes: 4 additions & 1 deletion custom_components/myenergy/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ def __init__(self, config, hass):
self._details = {}
self._last_update = None
self._refresh_required = True
self._refresh_retry = 0

@property
def unique_id(self):
Expand All @@ -158,6 +159,7 @@ def name(self) -> str:
# same as update, but without throttle to make sure init is always executed
async def _forced_update(self):
_LOGGER.info("Fetching init stuff for " + NAME)
self._refresh_retry += 1
if not(self._session):
self._session = ComponentSession()

Expand All @@ -167,6 +169,7 @@ async def _forced_update(self):
_LOGGER.debug("Getting data for " + NAME)
try:
self._details[contract_type.code] = await self._hass.async_add_executor_job(lambda: self._session.get_data(self._config, contract_type))
self._refresh_retry = 0
self._refresh_required = False
except Exception as e:
# Log the exception details
Expand All @@ -182,7 +185,7 @@ async def _update(self):

async def update(self):
# force update if (some) values are still unknown
if self._details is None or self._details is {} or self._refresh_required:
if (self._details is None or self._details is {} or self._refresh_required) and self._refresh_retry < 5:
await self._forced_update()
else:
await self._update()
Expand Down

0 comments on commit 4018943

Please sign in to comment.