This repository has been archived by the owner on Dec 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Update_State_Data.py
95 lines (76 loc) · 2.32 KB
/
Update_State_Data.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import ctypes
import time
import python_aida64
from pprint import pprint
import json
from volume import get_volume
from MQTT import Send_MQTT_Discovery,Update_State_data
debug = False
# 发送音量信息
def send_volume():
volume = get_volume()
Update_State_data(volume,"volume","number")
# 初始化Aida64数据
def get_aida64_data():
global aida64_data
aida64_data = python_aida64.getData()
if aida64_data == None:
print("11")
# 发送Aida64传感器数据
def send_aida64():
get_aida64_data()
Update_State_data(json.dumps(aida64_data),"","sensor")
# 发送传感器信息
def send_data():
info = "发送数据成功"
# 音量数据
try:
send_volume()
except:
print("找不到扬声器")
info = "扬声器获取错误"
# Aida64数据
send_aida64()
return info
# 发现设备
def discovery():
get_aida64_data()
info = ""
id1 = 0
id2 = 0
id3 = 0
id4 = 0
print("发送Discovery MQTT信息")
for category, items in aida64_data.items():
if category == "temp":
for item in items:
name = item["label"]
name_id = item["id"]
info += Send_MQTT_Discovery(category, id1, name, name_id,is_aida64=True,timeout=30)+"\n"
id1 = id1 + 1
if category == "pwr":
for item in items:
name = item["label"]
name_id = item["id"]
info += Send_MQTT_Discovery(category, id2, name, name_id,is_aida64=True,timeout=30)+"\n"
id2 = id2 + 1
if category == "fan":
for item in items:
name = item["label"]
name_id = item["id"]
info += Send_MQTT_Discovery(category, id3, name, name_id,is_aida64=True,timeout=30)+"\n"
id3 = id3 + 1
if category == "sys":
for item in items:
name = item["label"]
name_id = item["id"]
info += Send_MQTT_Discovery(category, id4, name, name_id,is_aida64=True,timeout=30) + "\n"
id4 = id4 + 1
info = "发现了" + str(id1 + id2 + id3 + id4) + "个实体\n" + info
return info
if __name__ == "__main__":
get_aida64_data()
pprint(aida64_data)
discovery()
time.sleep(1)
send_data()