Skip to content

Commit

Permalink
feat: Silence Host is Unreachable
Browse files Browse the repository at this point in the history
  • Loading branch information
davidrapan committed Jul 18, 2024
1 parent 78bf0b6 commit 1f6f612
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
7 changes: 3 additions & 4 deletions custom_components/solarman/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,8 @@ async def _send_receive_v5_frame(self, data_logging_stick_frame):
raise
except OSError as e:
if e.errno == errno.EHOSTUNREACH:
self.log.debug("[%s] EHOSTUNREACH error: %s", self.serial, e)
self.log.debug("[%s] Send/Receive error: %s", self.serial, e)
raise TimeoutError()
raise TimeoutError from e
raise
except Exception as e:
self.log.exception("[%s] Send/Receive error: %s", self.serial, e)
raise
Expand Down Expand Up @@ -194,7 +193,7 @@ async def async_get(self, runtime = 0):
except (V5FrameError, TimeoutError, Exception) as e:
result = 0

if not isinstance(e, TimeoutError) or not attempts_left >= 1 or _LOGGER.isEnabledFor(logging.DEBUG):
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)
Expand Down
8 changes: 4 additions & 4 deletions custom_components/solarman/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@
DEFAULT_BATTERY_NOMINAL_VOLTAGE = 48
DEFAULT_BATTERY_LIFE_CYCLE_RATING = 6000

DEFAULT_DIGITS = 6
DEFAULT_REGISTERS_UPDATE_INTERVAL = 60
DEFAULT_REGISTERS_MIN_SPAN = 25

AUTO_RECONNECT = True

ACTION_RETRY_ATTEMPTS = 5
Expand All @@ -43,13 +47,9 @@
TIMINGS_UPDATE_INTERVAL = td(seconds = TIMINGS_INTERVAL)
TIMINGS_UPDATE_TIMEOUT = TIMINGS_INTERVAL * 6
TIMINGS_SOCKET_TIMEOUT = TIMINGS_INTERVAL * 3
TIMINGS_QUERY_INTERVAL_DEFAULT = 60
TIMINGS_QUERY_EXCEPT_SLEEP = 3
TIMINGS_WRITE_EXCEPT_SLEEP = 1

REGISTERS_MIN_SPAN_DEFAULT = 25
REGISTERS_DIGITS_DEFAULT = 6

REQUEST_CODE = "code"
REQUEST_CODE_ALT = "mb_functioncode"
REQUEST_START = "start"
Expand Down
6 changes: 3 additions & 3 deletions custom_components/solarman/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
class ParameterParser:
def __init__(self, parameter_definition):
self._lookups = parameter_definition
self._update_interval = TIMINGS_QUERY_INTERVAL_DEFAULT
self._min_span = REGISTERS_MIN_SPAN_DEFAULT
self._digits = REGISTERS_DIGITS_DEFAULT
self._update_interval = DEFAULT_REGISTERS_UPDATE_INTERVAL
self._min_span = DEFAULT_REGISTERS_MIN_SPAN
self._digits = DEFAULT_DIGITS
self._result = {}

if "default" in parameter_definition:
Expand Down
2 changes: 1 addition & 1 deletion custom_components/solarman/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def __init__(self, coordinator, sensor, battery_nominal_voltage, battery_life_cy
if "state_class" in sensor and sensor["state_class"]:
self._attr_extra_state_attributes = { "state_class": sensor["state_class"] }

self._digits = sensor["digits"] if "digits" in sensor else REGISTERS_DIGITS_DEFAULT
self._digits = sensor["digits"] if "digits" in sensor else DEFAULT_DIGITS

self._attr_entity_category = (None)

Expand Down

0 comments on commit 1f6f612

Please sign in to comment.