20 lines
611 B
Python
20 lines
611 B
Python
from ..Thing import Thing
|
|
from .. import LowLevelMessages
|
|
|
|
class TemperatureSensor(Thing):
|
|
def __init__(self, network_id, thing_id):
|
|
super().__init__(network_id, thing_id, type = Thing.Type.TemperatureSensor)
|
|
self.temp = 0
|
|
self._watchers = []
|
|
|
|
def OnUpdate(self, handler):
|
|
self._watchers.append(handler)
|
|
def CancelOnUpdate(self, handler):
|
|
self._watchers.remove(handler)
|
|
|
|
def ProcessBinary(self, data):
|
|
ix = 0
|
|
self.temp = LowLevelMessages.ReceiveFloat16(data, [ix])
|
|
for watcher in self._watchers:
|
|
watcher(self.temp)
|