from .command import OnoffCommand
-def sispmctl_device(sock):
+def sispmctl_device(sock, device=None):
"""Create an OnoffCommand that controls the specified socket on a sispmctl
device.
@type sock: int
@param sock: the socket number of the sispmctl controlled device
+ @type device: None or int or str
+ @param device: optional identification of the device. If this is a number,
+ it is passed via -d. If it is a string, it is used as a serial and
+ passed via -D.
"""
- return OnoffCommand(["sispmctl", "-o", "%d" % sock],
- ["sispmctl", "-f", "%d" % sock])
+ cmd = ["sispmctl"]
+ if isinstance(device, int):
+ cmd.extend(["-d", "%d" % device])
+ elif isinstance(device, str):
+ cmd.extend(["-D", device])
+ elif device is not None:
+ raise TypeError("passed device must be int, str or None")
+ sock = "%d" % sock
+ return OnoffCommand(cmd + ["-o", sock], cmd + ["-f", sock])