-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
28 lines (18 loc) · 670 Bytes
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import paho.mqtt.client as mqtt
from mihome import XiaomiConnector
MQTT_SERVER = "192.168.0.149"
MQTT_PORT = 1883
PATH_FMT = "xiaomi/{model}/{sid}/{prop}" # short_id or sid ?
def prepare_mqtt():
client = mqtt.Client()
client.connect(MQTT_SERVER, MQTT_PORT, 60)
return client
def push_data(client, model, sid, cmd, data):
for key, value in data.items():
path = PATH_FMT.format(model=model, sid=sid, cmd=cmd, prop=key)
client.publish(path, payload=value, qos=0)
client = prepare_mqtt()
cb = lambda m, s, c, d: push_data(client, m, s, c, d)
connector = XiaomiConnector(data_callback=cb)
while True:
connector.check_incoming()