Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple improvments #313

Merged
merged 2 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 18 additions & 12 deletions custom_components/rpi_gpio/hub.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,12 +89,24 @@ def verify_gpiochip(self, path):
_LOGGER.debug(f"verify_gpiochip gpiodevice: {path} has pinctrl")
return True

def verify_port_ready(self, port: int):
info = self._chip.get_line_info(port)
_LOGGER.debug(f"original port info: {info}")
if info.used and info.consumer != DOMAIN:
_LOGGER.error(f"Port {port} already in use by {info.consumer}")
raise HomeAssistantError(f"Port {port} already in use by {info.consumer}")


async def startup(self, _):
"""Stuff to do after starting."""
_LOGGER.debug(f"startup {DOMAIN} hub")
if not self._online:
_LOGGER.debug(f"integration is not online")
return

if not self._config:
_LOGGER.debug(f"gpiod config is empty")
return

# setup lines
try:
self.update_lines()
Expand Down Expand Up @@ -125,16 +137,12 @@ def hub_id(self) -> str:
return self._id

def update_lines(self) -> None:
if not self._online:
_LOGGER.debug(f"gpiod hub not online {self._path}")
if not self._config:
_LOGGER.debug(f"gpiod config is empty")
if self._lines:
self._lines.release()

_LOGGER.debug(f"updating lines: {self._config}")
self._lines = self._chip.request_lines(
consumer = "rpi_gpio",
consumer = DOMAIN,
config = self._config
)
_LOGGER.debug(f"update_lines new lines: {self._lines}")
Expand All @@ -146,9 +154,8 @@ 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.verify_online()
self.verify_port_ready(port)

self._entities[port] = entity
self._config[port] = gpiod.LineSettings(
Expand All @@ -171,9 +178,8 @@ 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}")
self.verify_online()
self.verify_port_ready(port)

# read current status of the sensor
line = self._chip.request_lines({ port: {} })
Expand Down
2 changes: 1 addition & 1 deletion custom_components/rpi_gpio/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
"integration_type": "hub",
"iot_class": "local_push",
"issue_tracker": "https://github.com/thecode/ha-rpi_gpio/issues",
"requirements": [ "gpiod>=2.0.2" ],
"requirements": [ "gpiod>=2.2.1" ],
"version": "2024.10.2"
}