Toggle added
This commit is contained in:
parent
cd9ab64d54
commit
33a68f3c0e
19
powerplug.py
19
powerplug.py
@ -51,6 +51,13 @@ class sispmctl(object):
|
||||
logger.info('sispmctl channel %s changed to %s', output, state)
|
||||
self.publish_states()
|
||||
|
||||
def toggle_out_state(self, output):
|
||||
if output == "all":
|
||||
for i in range(1,5):
|
||||
self.toggle_out_state(str(i))
|
||||
else:
|
||||
self.set_out_state(output, not self.__state__[int(output) - 1])
|
||||
|
||||
def get_out_states(self):
|
||||
try:
|
||||
out_txt = subprocess.check_output(["sudo", "sispmctl", "-g", "all"])
|
||||
@ -79,7 +86,12 @@ class mqtt_powerplug(object):
|
||||
"set/2",
|
||||
"set/3",
|
||||
"set/4",
|
||||
"set/all"
|
||||
"set/all",
|
||||
"toggle/1",
|
||||
"toggle/2",
|
||||
"toggle/3",
|
||||
"toggle/4",
|
||||
"toggle/all",
|
||||
]
|
||||
|
||||
def __init__(self):
|
||||
@ -97,9 +109,14 @@ class mqtt_powerplug(object):
|
||||
def __receive__(self, client, userdata, message):
|
||||
if message.topic in self.__topics__:
|
||||
output = message.topic.split("/")[-1]
|
||||
if message.topic.find("set") >= 0:
|
||||
state = message.payload == b"true"
|
||||
logger.info("Received request to set output channel %s to state %s", output, str(state))
|
||||
self.__sc__.set_out_state(output, state)
|
||||
elif message.topic.find("toggle") >= 0:
|
||||
logger.info("Received request to toggle output channel %s", output)
|
||||
if message.payload != b"false":
|
||||
self.__sc__.toggle_out_state(output)
|
||||
else:
|
||||
logger.warning("Ignoring unknown mqtt topic %s", message.topic)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user