Custom Devices
You can build your own devices by inheriting karen.GenericDevice
which has the following basic structure:
import karen.GenericDevice
class MyCustomDevice(karen.GenericDevice):
def __init__(self,
parent=None,
callback=None):
self.parent = parent
self.callback = callback
self._isRunning = False
self.version = "1.0.0"
@property
def accepts(self):
return ["start","stop"] # Add "upgrade" to allow
# remote "pip install --upgrade" option.
@property
def isRunning(self):
return self._isRunning
def start(self, httpRequest=None):
self._isRunning = True
return True
def stop(self, httpRequest=None):
self._isRunning = False
return True
def upgrade(self, httpRequest=None):
return upgradePackage(self._packageName)
Adding Device to Container
import karen.containers
container = karen.containers.DeviceContainer()
container.initialize()
container.start()
myCustomDevice = MyDevice(callback=container.callbackHandler)
container.addDevice("MY_DEVICE", myCustomDevice, autoStart=True)
container.wait()