Skip to content

Commit

Permalink
refactor: State machine for query result
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Jul 27, 2024
1 parent e886f81 commit dda2c8b
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions custom_components/solarman/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ async def async_get(self, runtime = 0):
params = ParameterParser(self.parameter_definition)
requests = params.get_requests(runtime)
requests_count = len(requests)
result = 0
result = 1

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

Expand All @@ -222,6 +222,7 @@ async def async_get(self, runtime = 0):
code = get_request_code(request)
start = get_request_start(request)
end = get_request_end(request)
result = 0

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

Expand All @@ -248,7 +249,7 @@ async def async_get(self, runtime = 0):
if result == 0:
break

if result == 1 or len(requests) == 0:
if result == 1:
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 dda2c8b

Please sign in to comment.