From dda2c8be9bb869cabd609603658dfc9866323a94 Mon Sep 17 00:00:00 2001 From: David Rapan Date: Sat, 27 Jul 2024 11:39:29 +0200 Subject: [PATCH] refactor: State machine for query result --- custom_components/solarman/api.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/custom_components/solarman/api.py b/custom_components/solarman/api.py index 9c173a3..58cc392 100644 --- a/custom_components/solarman/api.py +++ b/custom_components/solarman/api.py @@ -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}") @@ -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}) ...") @@ -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.")