Skip to content

Commit

Permalink
feat: Experimental partial request fulfillment
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Jul 29, 2024
1 parent 0da625c commit ea282aa
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions custom_components/solarman/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,18 +211,18 @@ async def async_get(self, runtime = 0):
params = ParameterParser(self.parameter_definition)
requests = params.get_requests(runtime)
requests_count = len(requests)
result = 1
results = [0] * requests_count

_LOGGER.debug(f"Scheduling {requests_count} query requests. #{runtime}")

self._is_reading = 1

try:
for request in requests:
for i, request in enumerate(requests):
code = get_request_code(request)
start = get_request_start(request)
end = get_request_end(request)
result = 0
results[i] = 0

_LOGGER.debug(f"Querying ({start} - {end}) ...")

Expand All @@ -232,24 +232,24 @@ async def async_get(self, runtime = 0):

try:
await self.async_read(params, code, start, end)
result = 1
results[i] = 1
except (V5FrameError, TimeoutError, Exception) as e:
result = 0
results[i] = 0

if ((not isinstance(e, TimeoutError) or not attempts_left >= 1) and not (not isinstance(e, TimeoutError) or (e.__cause__ and isinstance(e.__cause__, OSError) and e.__cause__.errno == errno.EHOSTUNREACH))) or _LOGGER.isEnabledFor(logging.DEBUG):
_LOGGER.warning(f"Querying ({start} - {end}) failed. #{runtime} [{format_exception(e)}]")

await asyncio.sleep(TIMINGS_QUERY_EXCEPT_SLEEP)

_LOGGER.debug(f"Querying {'succeeded.' if result == 1 else f'attempts left: {attempts_left}{'' if attempts_left > 0 else ', aborting.'}'}")
_LOGGER.debug(f"Querying {'succeeded.' if results[i] == 1 else f'attempts left: {attempts_left}{'' if attempts_left > 0 else ', aborting.'}'}")

if result == 1:
if results[i] == 1:
break

if result == 0:
if not 1 in results and results[i] == 0:
break

if result == 1:
if 1 in results:
return self.get_result(params)
else:
await self.async_get_failed(f"Querying {self.serial} at {self.address}:{self.port} failed.")
Expand Down

0 comments on commit ea282aa

Please sign in to comment.