Decode integers to binary when controlling switches

This commit is contained in:
Shy 2017-03-21 18:14:00 +01:00
parent 72c3bfab91
commit d54ae9354e

View file

@ -210,6 +210,11 @@ class C4Room:
userinput = self._interactive_light_switch() userinput = self._interactive_light_switch()
if len(userinput) != len(self.switches): if len(userinput) != len(self.switches):
if int(userinput) <= 15:
# Try to interpret as integer
binary = bin(int(userinput))[2:]
userinput = str(len(self.switches)*'0')[:-len(binary)] + binary
else:
print("Error: wrong number of digits (expected {}, got {})!".format( print("Error: wrong number of digits (expected {}, got {})!".format(
len(self.switches), len(userinput))) len(self.switches), len(userinput)))
return False return False
@ -953,7 +958,7 @@ if __name__ == "__main__":
help="apply local colorscheme PRESET to Fnordcenter") help="apply local colorscheme PRESET to Fnordcenter")
group_cl.add_argument( group_cl.add_argument(
"-m", "--magic", action="store_true", default=False, "-m", "--magic", action="store_true", default=False,
help="EXPERIMENTAL: blend into preset (needs a running instance of fluffyd)") help="EXPERIMENTAL: blend into preset (needs a running instance of fluffyd on the network)")
group_cl.add_argument( group_cl.add_argument(
"-l", "--list-presets", action="store_true", "-l", "--list-presets", action="store_true",
help="list locally available presets") help="list locally available presets")
@ -971,7 +976,7 @@ if __name__ == "__main__":
help="list remote presets for ROOM") help="list remote presets for ROOM")
# Switch control # Switch control
group_sw = parser.add_argument_group(title="light switch control", group_sw = parser.add_argument_group(title="light switch control",
description="The optional DIGIT_CODE is a string of 0s or 1s for every light in the room. Works interactivly if missing.") description="The optional DIGIT_CODE is a string of 0s or 1s for every light in the room. Works interactively if missing.")
group_sw.add_argument( group_sw.add_argument(
"-W", nargs='?', dest="w_switch", const="", metavar="DIGIT_CODE", "-W", nargs='?', dest="w_switch", const="", metavar="DIGIT_CODE",
help="switch lights in Wohnzimmer on/off") help="switch lights in Wohnzimmer on/off")