Skip to content

Commit

Permalink
Improve detection libgpiod issues (#309)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
tomer-w authored Oct 26, 2024
1 parent f36b427 commit 53611ae
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions custom_components/rpi_gpio/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,11 @@ async def startup(self, _):
return

# 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:
return
Expand Down Expand Up @@ -129,11 +133,11 @@ def update_lines(self) -> None:
self._lines.release()

_LOGGER.debug(f"updating lines: {self._config}")
self._lines = gpiod.request_lines(
self._path,
self._lines = self._chip.request_lines(
consumer = "rpi_gpio",
config = self._config
)
_LOGGER.debug(f"update_lines new lines: {self._lines}")

def handle_events(self):
for event in self._lines.read_edge_events():
Expand All @@ -142,6 +146,10 @@ def handle_events(self):

def add_switch(self, entity, port, active_low, bias, drive_mode, init_output_value = True) -> None:
_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._config[port] = gpiod.LineSettings(
direction = Direction.OUTPUT,
Expand All @@ -163,6 +171,10 @@ def turn_off(self, port) -> None:

def add_sensor(self, entity, port, active_low, bias, debounce) -> None:
_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
line = self._chip.request_lines({ port: {} })
value = True if line.get_value(port) == Value.ACTIVE else False
Expand Down

0 comments on commit 53611ae

Please sign in to comment.