Skip to content

Instantly share code, notes, and snippets.

@philr
Created December 29, 2014 19:08
Show Gist options
  • Save philr/167f7fd337d83b7a9a2f to your computer and use it in GitHub Desktop.
Save philr/167f7fd337d83b7a9a2f to your computer and use it in GitHub Desktop.
Command line program to control Energenie remote controlled sockets on the Raspberry Pi
#!/usr/bin/python
import sys
from energenie import switch_on, switch_off
def arg_error():
sys.stderr.write("Usage: {0} 1-4|all on|off\n".format(sys.argv[0]));
sys.exit(1)
if len(sys.argv) != 3:
arg_error()
action = sys.argv[2]
if action not in ['on', 'off']:
arg_error()
group = sys.argv[1]
if not group.isdigit() and group != 'all':
arg_error()
if group == 'all':
print "Switching all {0}".format(action)
if action == 'on':
switch_on()
else:
switch_off()
else:
group_int = int(group)
if group_int < 1 or group_int > 4:
arg_error()
print "Switching group {0} {1}".format(group, action)
if action == 'on':
switch_on(group_int)
else:
switch_off(group_int)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment