Skip to content

Commit

Permalink
refactor: Remove incremental wait
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Jan 1, 2025
1 parent 804f657 commit b15213b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions custom_components/solarman/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ async def read_write(self, code, start, arg):
case _:
raise Exception(f"[{self.serial}] Used incorrect modbus function code {code}")

async def try_read_write(self, code, start, arg, message: str, incremental_wait: bool = True):
async def try_read_write(self, code, start, arg, message: str):
_LOGGER.debug(f"[{self.config.serial}] {message} ...")

response = None
Expand All @@ -114,15 +114,15 @@ async def try_read_write(self, code, start, arg, message: str, incremental_wait:
if not attempts_left > 0:
raise

await asyncio.sleep(((ACTION_ATTEMPTS - attempts_left) * TIMINGS_WAIT_SLEEP) if incremental_wait else TIMINGS_WAIT_SLEEP)
await asyncio.sleep(TIMINGS_WAIT_SLEEP)

return response

async def get(self, runtime = 0, requests = None):
scheduled, scount = ensure_list_safe_len(self.profile.parser.schedule_requests(runtime) if requests is None else requests)
responses, result = {}, {}

_LOGGER.debug(f"[{self.config.serial}] Scheduling {scount} query request{'s' if scount > 1 else ''}. ^{runtime}")
_LOGGER.debug(f"[{self.config.serial}] Scheduling {scount} query request{'s' if scount != 1 else ''}. ^{runtime}")

if scount == 0:
return result
Expand All @@ -133,7 +133,7 @@ async def get(self, runtime = 0, requests = None):
for request in scheduled:
code, start, end = get_request_code(request), get_request_start(request), get_request_end(request)
quantity = end - start + 1
responses[(code, start)] = await self.try_read_write(code, start, quantity, f"Querying {code:02} | 0x{code:02X} ~ {start:04} - {end:04} | 0x{start:04X} - 0x{end:04X} #{quantity:03}")
responses[(code, start)] = await self.try_read_write(code, start, quantity, f"Querying {code:02} 0x{code:02X} ~ {start:04} - {end:04} 0x{start:04X} - 0x{end:04X} #{quantity:03}")

result = self.profile.parser.process(responses) if requests is None else responses

Expand All @@ -154,4 +154,4 @@ async def call(self, code, start, arg):

async with asyncio.timeout(TIMINGS_UPDATE_TIMEOUT):
async with self._semaphore:
return await self.try_read_write(code, start, arg, f"Call {code:02} | 0x{code:02X} ~ {start} | 0x{start:04X}: {arg}", False)
return await self.try_read_write(code, start, arg, f"Call {code:02} 0x{code:02X} ~ {start} 0x{start:04X}: {arg}", False)
2 changes: 1 addition & 1 deletion custom_components/solarman/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@
TIMINGS_UPDATE_INTERVAL = td(seconds = TIMINGS_INTERVAL * TIMINGS_INTERVAL_SCALE)
TIMINGS_UPDATE_TIMEOUT = TIMINGS_INTERVAL * 6
TIMINGS_SOCKET_TIMEOUT = TIMINGS_INTERVAL * 3 - 1
TIMINGS_WAIT_SLEEP = 0.2
TIMINGS_WAIT_SLEEP = 0.1

# Constants also tied to TIMINGS_INTERVAL to ensure maximum synergy
ACTION_ATTEMPTS = 5
Expand Down

0 comments on commit b15213b

Please sign in to comment.