added control for single rooms

This commit is contained in:
root 2017-07-30 18:55:38 +00:00
parent eef3aca82b
commit c7ec11a4ea
1 changed files with 29 additions and 3 deletions

32
cli.py
View File

@ -41,21 +41,47 @@ def chch_all_off(pfd):
for i in range(button_count):
pfd.output_pins[i].turn_off()
def chch_all_on(pfd):
for i in range(button_count):
pfd.output_pins[i].turn_on()
def chch_off(pfd, i):
pfd.output_pins[i].turn_off()
def chch_on(pfd, i):
print(i)
pfd.output_pins[i].turn_on()
def help():
print('valid commands: status, all_off')
print('valid commands: status, on <room_number>, off <room_number>, all_on, all_off')
if __name__ == "__main__":
# listener = pifacedigitalio.InputEventListener()
# listener.activate()
# chch_status_output(listener.chip)
pifc = pifacedigitalio.PiFaceDigital()
room_number = ''
if len(sys.argv) == 3:
try:
room_number = int(sys.argv[2])
if room_number < 0 or room_number > button_count-1:
room_number = ''
except:
room_number = ''
try:
command = sys.argv[1]
except:
help()
exit(1)
if command=='status':
chch_status(pifacedigitalio.PiFaceDigital())
chch_status(pifc)
elif command=='all_off':
chch_all_off(pifacedigitalio.PiFaceDigital())
chch_all_off(pifc)
elif command=='all_on':
chch_all_on(pifc)
elif command=='off' and isinstance( room_number, int ):
chch_off(pifc, room_number)
elif command=='on' and isinstance( room_number, int ):
chch_on(pifc, room_number)
else:
help()