forked from openhab-scripters/openhab-helper-libraries
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path000_JythonThingProvider.py
45 lines (34 loc) · 1.32 KB
/
000_JythonThingProvider.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
from org.eclipse.smarthome.core.thing import ThingProvider
import openhab
import openhab.osgi
class JythonThingProvider(ThingProvider):
def __init__(self):
self.things = []
self.listeners = []
def addProviderChangeListener(self, listener): # ProviderChangeListener
self.listeners.append(listener)
def getAll(self):
return self.things
def removeProviderChangeListener(self, listener):
if listener in self.listeners:
self.listeners.remove(listener)
def add(self, thing):
self.things.append(thing)
for listener in self.listeners:
listener.added(self, thing)
def remove(self, thing):
if thing in self.things:
self.things.remove(thing)
for listener in self.listeners:
listener.removed(self, thing)
def update(self, thing):
for listener in self.listeners:
listener.updated(self, thing)
openhab.JythonThingProvider = JythonThingProvider()
def scriptLoaded(id):
openhab.osgi.register_service(
openhab.JythonThingProvider,
["org.eclipse.smarthome.core.thing.ThingProvider"])
def scriptUnloaded():
openhab.osgi.unregister_service(openhab.JythonThingProvider)
delattr(openhab, 'JythonThingProvider')