Compare commits
5 commits
3c316dc759
...
bde5e940c8
Author | SHA1 | Date | |
---|---|---|---|
bde5e940c8 | |||
14c4ec65ee | |||
3a97a7a059 | |||
6acb919486 | |||
5ae6d1f832 |
2 changed files with 52 additions and 27 deletions
|
@ -22,13 +22,15 @@ def main():
|
||||||
client = mqtt.Client(callback_api_version=mqtt.CallbackAPIVersion.VERSION2)
|
client = mqtt.Client(callback_api_version=mqtt.CallbackAPIVersion.VERSION2)
|
||||||
client.on_connect = on_connect
|
client.on_connect = on_connect
|
||||||
|
|
||||||
client.connect(args.mqtt_hostname, mqtt_client.MQTT_SERVER_PORT, 60)
|
client.connect(args.mqtt_hostname, mqtt_client.MqttClient.MQTT_SERVER_PORT, 60)
|
||||||
client.loop_start()
|
client.loop_start()
|
||||||
|
|
||||||
j = json.dumps({"command": "scene_recall", "args": {"scene_id": 0}})
|
j = json.dumps({"command": "scene_recall", "args": {"scene_id": 0}})
|
||||||
# j = json.dumps({'command': 'shutdown'})
|
# j = json.dumps({'command': 'shutdown'})
|
||||||
|
|
||||||
client.publish(mqtt_client.MQTT_TOPIC, payload=j, qos=0, retain=False)
|
client.publish(
|
||||||
|
mqtt_client.MqttClient.MQTT_COMMAND_TOPIC, payload=j, qos=0, retain=False
|
||||||
|
)
|
||||||
|
|
||||||
time.sleep(2)
|
time.sleep(2)
|
||||||
|
|
||||||
|
|
|
@ -4,32 +4,62 @@ import argparse
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import paho.mqtt.client as mqtt
|
import paho.mqtt.client as mqtt
|
||||||
import mixer
|
|
||||||
from mixer import Mixer
|
from mixer import Mixer
|
||||||
|
|
||||||
MQTT_SERVER_PORT = 1883
|
|
||||||
MQTT_TOPIC = "homeassistant/device/mixer"
|
|
||||||
|
|
||||||
m: Mixer = None
|
class MqttClient:
|
||||||
|
MQTT_SERVER_PORT = 1883
|
||||||
|
MQTT_DISCOVERY_TOPIC = "homeassistant/button/mixer/config"
|
||||||
|
MQTT_COMMAND_TOPIC = "livingroom/voc/allen_heath_qu16_mixer"
|
||||||
|
|
||||||
|
def __init__(self, mixer_ip):
|
||||||
|
self.mixer = Mixer(mixer_ip)
|
||||||
|
self.client = mqtt.Client(callback_api_version=mqtt.CallbackAPIVersion.VERSION2)
|
||||||
|
|
||||||
def on_connect(client, userdata, flags, reason_code, properties):
|
def mqtt_autodiscovery(self, client):
|
||||||
print(f"Connected: {reason_code}")
|
j = json.dumps(
|
||||||
client.subscribe(MQTT_TOPIC)
|
{
|
||||||
|
"name": "Reset Settings",
|
||||||
|
"command_topic": self.MQTT_COMMAND_TOPIC,
|
||||||
|
"command_template": '{"command": "scene_recall", "args": {"scene_id": 0}}',
|
||||||
|
"device": {
|
||||||
|
"name": "Mischpult",
|
||||||
|
"model": "Qu-16",
|
||||||
|
"manufacturer": "Allen & Heath",
|
||||||
|
"suggested_area": "livingroom",
|
||||||
|
"identifiers": "Mischpult",
|
||||||
|
},
|
||||||
|
"unique_id": "mischpult_reset_settings",
|
||||||
|
}
|
||||||
|
)
|
||||||
|
|
||||||
|
self, client.publish(self.MQTT_DISCOVERY_TOPIC, payload=j, qos=0, retain=False)
|
||||||
|
|
||||||
def on_message(client, userdata, msg):
|
def on_connect(self, client, userdata, flags, reason_code, properties):
|
||||||
payload = msg.payload.decode()
|
print(f"Connected: {reason_code}")
|
||||||
|
|
||||||
print(f"{msg.topic}: {payload}")
|
client.subscribe(self.MQTT_COMMAND_TOPIC)
|
||||||
|
self.mqtt_autodiscovery(client)
|
||||||
|
|
||||||
j = json.loads(payload)
|
def on_message(self, client, userdata, msg):
|
||||||
|
payload = msg.payload.decode()
|
||||||
|
|
||||||
match j["command"]:
|
print(f"{msg.topic}: {payload}")
|
||||||
case "scene_recall":
|
|
||||||
m.scene_recall(j["args"]["scene_id"])
|
j = json.loads(payload)
|
||||||
case "shutdown":
|
|
||||||
m.shutdown()
|
match j["command"]:
|
||||||
|
case "scene_recall":
|
||||||
|
self.mixer.scene_recall(j["args"]["scene_id"])
|
||||||
|
case "shutdown":
|
||||||
|
self.mixer.shutdown()
|
||||||
|
|
||||||
|
def run(self, hostname):
|
||||||
|
self.client.on_connect = self.on_connect
|
||||||
|
self.client.on_message = self.on_message
|
||||||
|
|
||||||
|
self.client.connect(hostname, self.MQTT_SERVER_PORT, 60)
|
||||||
|
self.client.loop_forever()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -52,15 +82,8 @@ def main():
|
||||||
|
|
||||||
print(f"Mixer IP: {args.mixer_ip}, MQTT broker hostname: {args.mqtt_hostname}")
|
print(f"Mixer IP: {args.mixer_ip}, MQTT broker hostname: {args.mqtt_hostname}")
|
||||||
|
|
||||||
global m
|
client = MqttClient(args.mixer_ip)
|
||||||
m = mixer.Mixer(args.mixer_ip)
|
client.run(args.mqtt_hostname)
|
||||||
|
|
||||||
client = mqtt.Client(callback_api_version=mqtt.CallbackAPIVersion.VERSION2)
|
|
||||||
client.on_connect = on_connect
|
|
||||||
client.on_message = on_message
|
|
||||||
|
|
||||||
client.connect(args.mqtt_hostname, MQTT_SERVER_PORT, 60)
|
|
||||||
client.loop_forever()
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue