-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin.py
More file actions
80 lines (65 loc) · 2.21 KB
/
Copy pathplugin.py
File metadata and controls
80 lines (65 loc) · 2.21 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
73
74
75
76
77
78
79
80
"""
<plugin key="Your-Plugin-Key" name="Your Plugin Name" author="Your Name" version="1.0.0" wikilink="https://example.com/wiki" externallink="https://github.com/repo-link">
<description>
Describe your plugin here.
</description>
<params>
<param field="Mode1" label="Custom Parameter 1" width="200px" required="true"/>
<param field="Mode2" label="Custom Parameter 2" width="200px"/>
<param field="Mode6" label="Debug Level" width="200px">
<options>
<option label="None" value="0" default="true" />
<option label="Basic Debugging" value="62"/>
<option label="All" value="-1"/>
</options>
</param>
</params>
</plugin>
"""
import Domoticz
class BasePlugin:
def __init__(self):
self.param1 = ""
self.param2 = ""
self.initialized = False
def onStart(self):
Domoticz.Debugging(int(Parameters["Mode6"]))
Domoticz.Log("Plugin started")
self.param1 = Parameters["Mode1"]
self.param2 = Parameters.get("Mode2", "")
if not self.param1:
Domoticz.Error("Missing required parameter: Mode1")
return
self.initialized = True
Domoticz.Heartbeat(30)
def onConnect(self, connection, status, description):
if status != 0:
Domoticz.Error(f"Connection failed: {status} - {description}")
else:
Domoticz.Log("Connected successfully")
def onMessage(self, connection, data):
Domoticz.Log(f"Message received: {data}")
def onStop(self):
Domoticz.Log("Plugin stopped")
def onHeartbeat(self):
if not self.initialized:
Domoticz.Error("Plugin not initialized yet")
return
Domoticz.Log("Heartbeat called")
global _plugin
_plugin = BasePlugin()
def onStart():
global _plugin
_plugin.onStart()
def onStop():
global _plugin
_plugin.onStop()
def onConnect(connection, status, description):
global _plugin
_plugin.onConnect(connection, status, description)
def onMessage(connection, data):
global _plugin
_plugin.onMessage(connection, data)
def onHeartbeat():
global _plugin
_plugin.onHeartbeat()