Created
December 29, 2014 19:08
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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