Improve detection libgpiod issues (#309)

1. Catch unhandled exception from update_lines
2. Add some tracing which will show if the GPIO is used by other consumers. When we have more info we will be able to add specific checks.
This commit is contained in:
Tomer 2024-10-26 07:18:37 +03:00 committed by GitHub
parent f36b427748
commit 53611ae1b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -96,7 +96,11 @@ class Hub:
return return
# setup lines # setup lines
self.update_lines() try:
self.update_lines()
except Exception as e:
_LOGGER.error(f"Failed to update lines: {e}")
return
if not self._edge_events: if not self._edge_events:
return return
@ -129,11 +133,11 @@ class Hub:
self._lines.release() self._lines.release()
_LOGGER.debug(f"updating lines: {self._config}") _LOGGER.debug(f"updating lines: {self._config}")
self._lines = gpiod.request_lines( self._lines = self._chip.request_lines(
self._path,
consumer = "rpi_gpio", consumer = "rpi_gpio",
config = self._config config = self._config
) )
_LOGGER.debug(f"update_lines new lines: {self._lines}")
def handle_events(self): def handle_events(self):
for event in self._lines.read_edge_events(): for event in self._lines.read_edge_events():
@ -142,6 +146,10 @@ class Hub:
def add_switch(self, entity, port, active_low, bias, drive_mode, init_output_value = True) -> None: def add_switch(self, entity, port, active_low, bias, drive_mode, init_output_value = True) -> None:
_LOGGER.debug(f"in add_switch {port}") _LOGGER.debug(f"in add_switch {port}")
info = self._chip.get_line_info(port)
_LOGGER.debug(f"original line info: {info}")
self._entities[port] = entity self._entities[port] = entity
self._config[port] = gpiod.LineSettings( self._config[port] = gpiod.LineSettings(
direction = Direction.OUTPUT, direction = Direction.OUTPUT,
@ -163,6 +171,10 @@ class Hub:
def add_sensor(self, entity, port, active_low, bias, debounce) -> None: def add_sensor(self, entity, port, active_low, bias, debounce) -> None:
_LOGGER.debug(f"in add_sensor {port}") _LOGGER.debug(f"in add_sensor {port}")
info = self._chip.get_line_info(port)
_LOGGER.debug(f"original line info: {info}")
# read current status of the sensor # read current status of the sensor
line = self._chip.request_lines({ port: {} }) line = self._chip.request_lines({ port: {} })
value = True if line.get_value(port) == Value.ACTIVE else False value = True if line.get_value(port) == Value.ACTIVE else False