Implemented --define-remote-preset
This commit is contained in:
parent
ccbe2c8912
commit
bb039b5b65
2 changed files with 48 additions and 0 deletions
31
README.md
31
README.md
|
@ -35,6 +35,37 @@ options.
|
||||||
$ c4ctrl.py -h
|
$ 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
|
### Preset file location
|
||||||
*c4ctrl* searches for preset files in the directory *$XDG_CONFIG_HOME/c4ctrl/*,
|
*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
|
defaulting to *$HOME/.config/c4ctrl/*. If you use the *-o* flag and this
|
||||||
|
|
17
c4ctrl.py
17
c4ctrl.py
|
@ -1259,6 +1259,17 @@ class RemotePresets: # {{{1
|
||||||
|
|
||||||
c4 = C4Interface()
|
c4 = C4Interface()
|
||||||
return c4.push(cmd)
|
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
|
# }}}1
|
||||||
|
|
||||||
if __name__ == "__main__": # {{{1
|
if __name__ == "__main__": # {{{1
|
||||||
|
@ -1349,6 +1360,9 @@ if __name__ == "__main__": # {{{1
|
||||||
"-R", "--list-remote", nargs='?', const="global", metavar="ROOM",
|
"-R", "--list-remote", nargs='?', const="global", metavar="ROOM",
|
||||||
help="list remote presets for ROOM. Will list global presets if ROOM \
|
help="list remote presets for ROOM. Will list global presets if ROOM \
|
||||||
is omitted.")
|
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()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# Debug, gate, status and shutdown.
|
# Debug, gate, status and shutdown.
|
||||||
|
@ -1413,6 +1427,9 @@ if __name__ == "__main__": # {{{1
|
||||||
else:
|
else:
|
||||||
RemotePresets().apply_preset(args.remote_preset[0].strip(),
|
RemotePresets().apply_preset(args.remote_preset[0].strip(),
|
||||||
args.remote_preset[1:])
|
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?
|
# No or no useful command line options?
|
||||||
if len(sys.argv) <= 1 or len(sys.argv) == 2 and args.debug:
|
if len(sys.argv) <= 1 or len(sys.argv) == 2 and args.debug:
|
||||||
|
|
Loading…
Reference in a new issue