Newer
Older
pyenergenie / src / energenie_cmd
#!/bin/env python

import energenie
import argparse

parser = argparse.ArgumentParser(description='Control Energenie sockets/lights')
parser.add_argument('action', choices=['on', 'off'])
parser.add_argument('device')

args = parser.parse_args()

energenie.init()
energenie.registry.load_from('/etc/energenie')
device = energenie.registry.get(args.device)
if device != None:
   if args.action == 'on':
      device.turn_on()
   else:
      device.turn_off()
   energenie.finished()
else:
   energenie.finished()
   parser.error("Device '%s' not found." % args.device)