Skip to content

Commit

Permalink
Merge pull request #8 from khilman/wip/localcmdline
Browse files Browse the repository at this point in the history
drivers: localcmdline: use on/off commands from conf file
  • Loading branch information
mattface committed Apr 11, 2016
2 parents 91da01e + d07772c commit 4e79e63
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions lavapdu/drivers/localcmdline.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,16 @@
from subprocess import call
from lavapdu.drivers.localbase import LocalBase

log = logging.getLogger(__name__)

class LocalCmdline(LocalBase):

def __init__(self, hostname, settings):
self.hostname = hostname
self.settings = settings
self.cmd_on = settings.get("cmd_on", None)
self.cmd_off = settings.get("cmd_off", None)

@classmethod
def accepts(cls, drivername):
if drivername == "localcmdline":
Expand All @@ -33,15 +40,18 @@ def accepts(cls, drivername):

def _port_interaction(self, command, port_number):

if command == "on":
print("Attempting local commandline ON control: %s port: %i" % (command, port_number))
# replace the call arguments below with your command line for the ON and OFF commands
# call(["relay-ctrl.py", str(port_number) , "POWER_ON"])
cmd = None

log.debug("Attempting control: %s port: %i" % (command, port_number))
if command == "on" and self.cmd_on:
cmd = self.cmd_on % port_number

elif command == "off":
print("Attempting local commandline OFF control: %s port: %i" % (command, port_number))
# call(["relay-ctrl.py", str(port_number) , "POWER_OFF"])
elif command == "off" and self.cmd_off:
cmd = self.cmd_off % port_number

else:
logging.debug("Unknown command!")
log.debug("Unknown command!")

if cmd:
log.debug("running %s" % cmd)
call(cmd, shell = True)

0 comments on commit 4e79e63

Please sign in to comment.