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

Power control: allow setting repetitions on OFF #19

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
33 changes: 19 additions & 14 deletions src/inet_nm/power_control.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging
import subprocess
from time import sleep
from typing import List
from typing import List, Optional

import inet_nm.locking as lck
import inet_nm.usb_ctrl as ucl
Expand Down Expand Up @@ -47,7 +47,7 @@ def power_on_uid(self, uid: str):
if id_path in self.powered_locations:
self._power_on(id_path)

def power_off_uid(self, uid: str):
def power_off_uid(self, uid: str, repeat: Optional[int] = None):
if uid not in self.id_path_to_node_uid.values():
raise ValueError(
f"Node with uid {uid} not found, "
Expand All @@ -56,23 +56,28 @@ def power_off_uid(self, uid: str):
for id_path, node_uid in self.id_path_to_node_uid.items():
if node_uid == uid:
if id_path in self.powered_locations:
self._power_off(id_path)
self._power_off(id_path, repeat=repeat)

def _power_off(self, id_path):
def _power_off(self, id_path, repeat: Optional[int] = None):
self.logging.debug("Powering off %s", id_path)
usb_info = self.powered_locations[id_path]
command = [
"sudo",
"uhubctl",
"-l",
usb_info["hub"],
"-p",
usb_info["port"],
"-a",
"off",
]

if repeat is not None:
command += ["-r", str(repeat)]

self._power_off_procs.append(
subprocess.Popen(
[
"sudo",
"uhubctl",
"-l",
usb_info["hub"],
"-p",
usb_info["port"],
"-a",
"off",
],
command,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
text=True,
Expand Down