Communication adaptions
This commit is contained in:
parent
4ecd37f1ca
commit
944824d502
21
powerplug.py
21
powerplug.py
@ -73,7 +73,7 @@ class sispmctl(object):
|
||||
self.send_state(i)
|
||||
|
||||
def send_state(self, output):
|
||||
topic = config.MQTT_TOPIC + "/status/" + str(output)
|
||||
topic = config.MQTT_TOPIC + "/output/" + str(output)
|
||||
logger.debug("Sending Powerplug status information of plug %s to mqtt %s = %s", str(output), topic, str(self.__state__[output - 1]))
|
||||
try:
|
||||
self.__mqtt_client__.send(topic, "true" if self.__state__[output - 1] else "false")
|
||||
@ -85,23 +85,18 @@ class mqtt_powerplug(mqtt.mqtt_client):
|
||||
def __init__(self):
|
||||
mqtt.mqtt_client.__init__(self, config.APP_NAME, config.MQTT_SERVER, 1883, config.MQTT_USER, config.MQTT_PASS)
|
||||
for target in ["1", "2", "3", "4", "all"]:
|
||||
self.add_callback(config.MQTT_TOPIC + "/set/" + target, self.__set__)
|
||||
self.add_callback(config.MQTT_TOPIC + "/toggle/" + target, self.__toggle__)
|
||||
self.add_callback(config.MQTT_TOPIC + "/output/%s/set" % target, self.__set__)
|
||||
#
|
||||
self.__sc__ = sispmctl(self)
|
||||
|
||||
def __set__(self, client, userdata, message):
|
||||
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)
|
||||
|
||||
def __toggle__(self, client, userdata, message):
|
||||
output = message.topic.split("/")[-1]
|
||||
logger.info("Received request to toggle output channel %s", output)
|
||||
if message.payload != b"false":
|
||||
output = message.topic.split("/")[-2]
|
||||
if message.payload == b"true" or message.payload == b"false":
|
||||
self.__sc__.set_out_state(output, message.payload == b"true")
|
||||
elif message.payload.lower() == b'toggle':
|
||||
self.__sc__.toggle_out_state(output)
|
||||
else:
|
||||
logger.warning("Ignoring set command due to payload: %s", message.payload)
|
||||
|
||||
def __del__(self):
|
||||
self.__client__.loop_stop() # stop the loop
|
||||
|
Loading…
x
Reference in New Issue
Block a user