From dfa38a0ddc1ca6025d8903834743c71cb08e2aa1 Mon Sep 17 00:00:00 2001 From: Eric Callahan Date: Sat, 22 Jun 2024 08:08:23 -0400 Subject: [PATCH] power: uhubctl Pi 4 bugfix Default the port option to None if omitted. Signed-off-by: Eric Callahan --- moonraker/components/power.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/moonraker/components/power.py b/moonraker/components/power.py index b55edb0..0ff0119 100644 --- a/moonraker/components/power.py +++ b/moonraker/components/power.py @@ -1475,7 +1475,7 @@ HUB_STATE_PATTERN = r""" (?:Port\s(?P[0-9]+):) (?:\s(?P[0-9a-f]{4})) (?:\s(?Ppower|off)) - (?P(?:\s[0-9a-z]+)+)? + (?P(?:\s[0-9a-z.]+)+)? (?:\s\[(?P.+)\])? """ @@ -1488,7 +1488,7 @@ class UHubCtl(PowerDevice): super().__init__(config) self.scmd: ShellCommand = self.server.load_component(config, "shell_command") self.location = config.get("location") - self.port = config.getint("port") + self.port = config.getint("port", None) ret = shutil.which("uhubctl") if ret is None: raise config.error( @@ -1531,11 +1531,13 @@ class UHubCtl(PowerDevice): self.state = result["state"] async def _run_uhubctl(self, action: str) -> Dict[str, Any]: - cmd = f"uhubctl -l {self.location} -p {self.port}" - search_prefix = "Current status" + cmd = f"uhubctl -l {self.location}" + if self.port is not None: + cmd += f" -p {self.port}" + search_prefix = f"Current status for hub {self.location}" if action in ["on", "off"]: cmd += f" -a {action}" - search_prefix = "New status" + search_prefix = f"New status for hub {self.location}" resp: str = await self.scmd.exec_cmd(cmd, log_complete=False) for line in resp.splitlines(): if search_prefix: @@ -1551,7 +1553,7 @@ class UHubCtl(PowerDevice): status_bits = int(result["bits"], 16) except (TypeError, ValueError): continue - if port != self.port: + if self.port is not None and port != self.port: continue if result["pstate"] is None: continue