Skip to content

Commit

Permalink
alfen.py: prevent infinite loop in _get_all_properties_value()
Browse files Browse the repository at this point in the history
  • Loading branch information
ikruglov committed Apr 16, 2024
1 parent 51999a2 commit 37d0514
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions custom_components/alfen_wallbox/alfen.py
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,26 @@ async def _get_all_properties_value(self):
for cat in (CAT_GENERIC, CAT_GENERIC2, CAT_METER1, CAT_STATES, CAT_TEMP, CAT_OCPP, CAT_METER4, CAT_MBUS_TCP, CAT_COMM, CAT_DISPLAY, CAT_METER2):
nextRequest = True
offset = 0
attempt = 0
while (nextRequest):
attempt += 1
cmd = f"{PROP}?{CAT}={cat}&{OFFSET}={offset}"
response = await self._get(url=self.__get_url(cmd))
_LOGGER.debug(f"Status Response {cmd}: {response}")

if response is not None:
attempt = 0
properties += response[PROPERTIES]
nextRequest = response[TOTAL] > (
offset + len(response[PROPERTIES]))
offset += len(response[PROPERTIES])
elif attempt >= 3:
# This only possible in case of series of timeouts or unknown exceptions in self._get()
# It's better to break completely, otherwise we can provide partial data in self.properties.
_LOGGER.debug(f"Returning earlier after {attempt} attempts")
self.properties = []
return

_LOGGER.debug(f"Properties {properties}")
self.properties = properties

Expand Down

0 comments on commit 37d0514

Please sign in to comment.