Skip to content

Commit

Permalink
refactor: Removed reduntant constant for sleep
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Jul 30, 2024
1 parent 096c9cc commit fab7130
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 5 deletions.
6 changes: 3 additions & 3 deletions custom_components/solarman/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ async def async_get(self, runtime = 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)
await asyncio.sleep(TIMINGS_WAIT_SLEEP)

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

Expand Down Expand Up @@ -323,7 +323,7 @@ async def service_write_holding_register(self, register, value, wait_for_attempt
if not attempts_left > 0:
raise

await asyncio.sleep(TIMINGS_WRITE_EXCEPT_SLEEP)
await asyncio.sleep(TIMINGS_WRITE_SLEEP)

async def service_write_multiple_holding_registers(self, register, values, wait_for_attempts = ACTION_ATTEMPTS) -> bool:
_LOGGER.debug(f"service_write_multiple_holding_registers: {register}, values: {values}")
Expand All @@ -348,4 +348,4 @@ async def service_write_multiple_holding_registers(self, register, values, wait_
if not attempts_left > 0:
raise

await asyncio.sleep(TIMINGS_WRITE_EXCEPT_SLEEP)
await asyncio.sleep(TIMINGS_WRITE_SLEEP)
3 changes: 1 addition & 2 deletions custom_components/solarman/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,7 @@
TIMINGS_UPDATE_TIMEOUT = TIMINGS_INTERVAL * 6
TIMINGS_SOCKET_TIMEOUT = TIMINGS_INTERVAL * 4 - 1
TIMINGS_WAIT_SLEEP = 1
TIMINGS_QUERY_EXCEPT_SLEEP = 1
TIMINGS_WRITE_EXCEPT_SLEEP = 0.2
TIMINGS_WRITE_SLEEP = 0.2

ATTR_FRIENDLY_NAME = "friendly_name"

Expand Down

0 comments on commit fab7130

Please sign in to comment.