-
Notifications
You must be signed in to change notification settings - Fork 19
/
plugin.py
109 lines (82 loc) · 3.05 KB
/
plugin.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
"""
<plugin key="plugins-manager" name="Python Plugins Manager" version="1.0.0">
<description>
<h2>Python Plugins Manager v.1.0.0</h2><br/>
<h3>Features:</h3>
<ul style="list-style-type:square">
<li>List available and installed plugins</li>
<li>Install / Update selected Domoticz plugin</li>
<li>Open plugin repository</li>
</ul>
</description>
<params>
<param field="Mode6" label="Debug" width="75px">
<options>
<option label="True" value="Debug"/>
<option label="False" value="Normal" default="true" />
</options>
</param>
</params>
</plugin>
"""
import Domoticz
import platform
import os
from shutil import copy2
from plugins import load
from api import APIManager
class BasePlugin:
def __init__(self):
self.ui_name = 'plugins-manager'
def onStart(self):
load(Parameters['HomeFolder'])
if Parameters["Mode6"] == 'Debug':
Domoticz.Debugging(2)
else:
Domoticz.Debugging(0)
if platform.system() == "Windows":
Domoticz.Error("Windows Platform is NOT YET SUPPORTED!")
return
self.install_ui()
self.api_manager = APIManager(Devices)
def onStop(self):
self.uninstall_ui()
def onDeviceModified(self, unit):
if (unit == self.api_manager.unit):
self.api_manager.handle_request(Devices[unit].sValue)
return
def install_ui(self):
Domoticz.Log('Installing plugin custom page...')
try:
source_path = Parameters['HomeFolder'] + 'frontend'
templates_path = Parameters['StartupFolder'] + 'www/templates'
Domoticz.Debug('Copying files from ' + source_path + ' to ' + templates_path)
copy2(source_path + '/index.html', templates_path + '/' + self.ui_name + '.html')
copy2(source_path + '/index.js', templates_path + '/' + self.ui_name + '.js')
Domoticz.Log('Installing plugin custom page completed.')
except Exception as e:
Domoticz.Error('Error during installing plugin custom page')
Domoticz.Error(repr(e))
def uninstall_ui(self):
Domoticz.Log('Uninstalling plugin custom page...')
try:
templates_path = Parameters['StartupFolder'] + 'www/templates'
if os.path.exists(templates_path + self.ui_name + '.html'):
os.remove(templates_path + self.ui_name + '.html')
if os.path.exists(templates_path + self.ui_name + '.js'):
os.remove(templates_path + self.ui_name + '.js')
Domoticz.Log('Uninstalling plugin custom page completed.')
except Exception as e:
Domoticz.Error('Error during uninstalling plugin custom page')
Domoticz.Error(repr(e))
global _plugin
_plugin = BasePlugin()
def onStart():
global _plugin
_plugin.onStart()
def onStop():
global _plugin
_plugin.onStop()
def onDeviceModified(Unit):
global _plugin
_plugin.onDeviceModified(Unit)