-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUsingPushover.py
More file actions
72 lines (53 loc) · 2.33 KB
/
Copy pathUsingPushover.py
File metadata and controls
72 lines (53 loc) · 2.33 KB
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
from pushover_open_client import *
from CommandToDomoticz import *
import json
import os
domoticz = None
client = None
inputConfigFile = os.path.dirname(os.path.abspath(__file__)) + "/device.cfg"
def messageCallback(messageList):
try:
# Process/do work with messageList!
if(messageList):
for message in messageList:
#Do work with message here!
print("Received: " + message.message + "\n")
#domoticz.PrintObject()
domoticz.ProcessCommand(message.message)
#Make sure to acknowledge messages with priority >= 2
if(message.priority >= 2):
if(message.acked != 1):
client.acknowledgeEmergency(message.receipt)
#Make sure you delete messages that you recieve!
client.deleteMessages(messageList[-1].id)
except Exception as inst:
print(type(inst)) # the exception instance
print(inst.args) # arguments stored in .args
print(inst) # __str__ allows args to be printed directly,
# but may be overridden in exception subclasses
x, y = inst.args # unpack args
def main():
##Setups with a device configuration
global client
client = Client(inputConfigFile)
# Process the domoticz part of the configuration
with open(inputConfigFile, 'r') as inputConfig:
jsonConfig = json.load(inputConfig)
domoticzAddress = jsonConfig["domoticzAddress"]
domoticzUser = jsonConfig["domoticzUser"]
domoticzPassword = jsonConfig["domoticzPassword"]
# Create a new Domoticz instance
global domoticz
domoticz = Domoticz(domoticzAddress, domoticzUser, domoticzPassword)
domoticz.PrintObject()
#Get any messages sent before the client has started
messageList = client.getOutstandingMessages()
#Do work with outstanding messages
#Make sure you delete messages that you recieve!
if(messageList):
client.deleteMessages(messageList[-1].id)
print("Request for Messages sent")
#Pass our function as a parameter, this will run 'forever'
client.getWebSocketMessages(messageCallback)
if __name__ == '__main__':
main()