-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
39 lines (34 loc) · 1.29 KB
/
utils.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
# -*- coding: utf-8 -*-
from flask_mqtt import Mqtt
from flask_socketio import SocketIO
from flask import current_app as app
import re
socketio = SocketIO()
mqtt = Mqtt()
def createSocketMessage(message):
blindId = ""
data = dict(topic=message.topic, payload=message.payload.decode(), id=blindId)
if message.topic.endswith("online"):
blindIdExtractor = re.search("shellies\/(.+?)\/online", message.topic)
if blindIdExtractor:
blindId = blindIdExtractor.group(1)
return {
"event": "online",
"data": {"id": blindId, "online": message.payload.decode()},
}
elif message.topic.endswith("pos"):
blindIdExtractor = re.search("shellies\/(.+?)\/roller", message.topic)
if blindIdExtractor:
blindId = blindIdExtractor.group(1)
return {
"event": "position",
"data": {"id": blindId, "position": message.payload.decode()},
}
else:
blindIdExtractor = re.search("shellies\/(.+?)\/roller\/0", message.topic)
if blindIdExtractor:
blindId = blindIdExtractor.group(1)
return {
"event": "action",
"data": {"id": blindId, "action": message.payload.decode()},
}