add mqtt_client.py with scene_recall + shutdown commands
This commit is contained in:
parent
20f90018c0
commit
872d56fcbd
1 changed files with 54 additions and 0 deletions
54
mqtt_client.py
Normal file
54
mqtt_client.py
Normal file
|
@ -0,0 +1,54 @@
|
|||
#!/bin/python
|
||||
|
||||
import argparse
|
||||
import json
|
||||
|
||||
import paho.mqtt.client as mqtt
|
||||
import mixer
|
||||
from mixer import Mixer
|
||||
|
||||
MQTT_SERVER_ADDRESS = "localhost"
|
||||
MQTT_SERVER_PORT = 1883
|
||||
MQTT_TOPIC = "homeassistant/device/mixer"
|
||||
|
||||
m: Mixer = None
|
||||
|
||||
|
||||
def on_connect(client, userdata, flags, reason_code, properties):
|
||||
print(f"Connected: {reason_code}")
|
||||
client.subscribe("#")
|
||||
|
||||
|
||||
def on_message(client, userdata, msg):
|
||||
payload = msg.payload.decode()
|
||||
|
||||
print(f"{msg.topic}: {payload}")
|
||||
|
||||
j = json.loads(payload)
|
||||
|
||||
match j["command"]:
|
||||
case "scene_recall":
|
||||
m.scene_recall(j["args"]["scene_id"])
|
||||
case "shutdown":
|
||||
m.shutdown()
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Allen & Heath Qu MQTT Remote Control")
|
||||
parser.add_argument("ip", help="IP of the mixer")
|
||||
args = parser.parse_args()
|
||||
print(f"IP: {args.ip}")
|
||||
|
||||
global m
|
||||
m = mixer.Mixer(args.ip, mixer.MIXER_PORT)
|
||||
|
||||
client = mqtt.Client(callback_api_version=mqtt.CallbackAPIVersion.VERSION2)
|
||||
client.on_connect = on_connect
|
||||
client.on_message = on_message
|
||||
|
||||
client.connect(MQTT_SERVER_ADDRESS, MQTT_SERVER_PORT, 60)
|
||||
client.loop_forever()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
Loading…
Add table
Add a link
Reference in a new issue