power: uhubctl Pi 4 bugfix

Default the port option to None if omitted.

Signed-off-by: Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2024-06-22 08:08:23 -04:00
parent 2dbea4f4cd
commit dfa38a0ddc
1 changed files with 8 additions and 6 deletions

View File

@ -1475,7 +1475,7 @@ HUB_STATE_PATTERN = r"""
(?:Port\s(?P<port>[0-9]+):) (?:Port\s(?P<port>[0-9]+):)
(?:\s(?P<bits>[0-9a-f]{4})) (?:\s(?P<bits>[0-9a-f]{4}))
(?:\s(?P<pstate>power|off)) (?:\s(?P<pstate>power|off))
(?P<flags>(?:\s[0-9a-z]+)+)? (?P<flags>(?:\s[0-9a-z.]+)+)?
(?:\s\[(?P<desc>.+)\])? (?:\s\[(?P<desc>.+)\])?
""" """
@ -1488,7 +1488,7 @@ class UHubCtl(PowerDevice):
super().__init__(config) super().__init__(config)
self.scmd: ShellCommand = self.server.load_component(config, "shell_command") self.scmd: ShellCommand = self.server.load_component(config, "shell_command")
self.location = config.get("location") self.location = config.get("location")
self.port = config.getint("port") self.port = config.getint("port", None)
ret = shutil.which("uhubctl") ret = shutil.which("uhubctl")
if ret is None: if ret is None:
raise config.error( raise config.error(
@ -1531,11 +1531,13 @@ class UHubCtl(PowerDevice):
self.state = result["state"] self.state = result["state"]
async def _run_uhubctl(self, action: str) -> Dict[str, Any]: async def _run_uhubctl(self, action: str) -> Dict[str, Any]:
cmd = f"uhubctl -l {self.location} -p {self.port}" cmd = f"uhubctl -l {self.location}"
search_prefix = "Current status" 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"]: if action in ["on", "off"]:
cmd += f" -a {action}" 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) resp: str = await self.scmd.exec_cmd(cmd, log_complete=False)
for line in resp.splitlines(): for line in resp.splitlines():
if search_prefix: if search_prefix:
@ -1551,7 +1553,7 @@ class UHubCtl(PowerDevice):
status_bits = int(result["bits"], 16) status_bits = int(result["bits"], 16)
except (TypeError, ValueError): except (TypeError, ValueError):
continue continue
if port != self.port: if self.port is not None and port != self.port:
continue continue
if result["pstate"] is None: if result["pstate"] is None:
continue continue