diff --git a/README.md b/README.md index 8bb4137..32c8ba2 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,37 @@ options. $ c4ctrl.py -h ``` +#### Usage example: switching lights +The best way to get used to the light switch control syntax is by giving either +the *-W*, *-P*, *-F* or *-K* flag without argument. This will display what bit +corresponds to which light. The string of 0s and 1s shows the current state of +every light in the room. +``` +$ c4ctrl -W +``` +``` +[Wohnzimmer] +Please enter 0 or 1 for every light: +,- Tür +|,- Mitte +||,- Flur +|||,- Küche +1011 +``` +Example input values: +* *0011*: sets every light to the given state +* *3* (Decimal representation of *0011*): same as the above +* *^2* or *^0010* (XOR operand): toggle light "Flur" +* *|9* or *|1001* (OR operand): turn on light "Tür" and "Küche" +* *&1* or *&0001* (AND operand): turn off every light but "Küche" + +These values may be given directly on the command line: +``` +$ c4ctrl -W ^2 +``` +NOTE: Remember to escape *|* and *&* characters when giving them on the command +line! + ### Preset file location *c4ctrl* searches for preset files in the directory *$XDG_CONFIG_HOME/c4ctrl/*, defaulting to *$HOME/.config/c4ctrl/*. If you use the *-o* flag and this diff --git a/c4ctrl.py b/c4ctrl.py index f8d5e04..5d24fc7 100755 --- a/c4ctrl.py +++ b/c4ctrl.py @@ -1259,6 +1259,17 @@ class RemotePresets: # {{{1 c4 = C4Interface() return c4.push(cmd) + + def store_preset(self, name, domain="global"): + """Define remote preset.""" + + if domain not in self.map.keys(): + print("Error: \"{}\" is not a valid domain! Valid domains are: {}" + .format(domain, ", ".join(self.map.keys()))) + return False + + c4 = C4Interface() + return c4.push(name, topic=self.map[domain]["def_topic"]) # }}}1 if __name__ == "__main__": # {{{1 @@ -1349,6 +1360,9 @@ if __name__ == "__main__": # {{{1 "-R", "--list-remote", nargs='?', const="global", metavar="ROOM", help="list remote presets for ROOM. Will list global presets if ROOM \ is omitted.") + group_rp.add_argument( + "--store-remote-preset", nargs=2, type=str, metavar=("NAME", "ROOM"), + help="store remote preset NAME for ROOM.") args = parser.parse_args() # Debug, gate, status and shutdown. @@ -1413,6 +1427,9 @@ if __name__ == "__main__": # {{{1 else: RemotePresets().apply_preset(args.remote_preset[0].strip(), args.remote_preset[1:]) + if args.store_remote_preset: + RemotePresets().store_preset(args.store_remote_preset[0].strip(), + args.store_remote_preset[1].strip()) # No or no useful command line options? if len(sys.argv) <= 1 or len(sys.argv) == 2 and args.debug: