Source code for festivalgrid.device_templates.device
[docs]class DeviceTemplate:
"""The base class for device templates.
.. note::
Usually you will only inherit from this class if you implement a new low level device template class like :class:`.MQTTDevice`.
"""
[docs] def __init__(self, device):
"""Initialize a device template.
Args:
device (:class:`festivalgrid.models.Device`): Device object instance.
"""
self.device = device
[docs] def get_device_admin_link(self):
"""Implement this if your device has a web admin interface.
Returns:
dict. Should return a dict with two keys::
title -- Title of the link
url -- Full url to the device admin (e.g. http://192.168.1.4/admin)
"""
return None
[docs] def set_cut_power(self, state):
"""Implement this if your device supports turning on/off it's power state.
Returns:
bool::
True -- Cut the power
False -- Restore power
"""
raise NotImplementedError
[docs] def notify_setup_change(self, model):
"""This method gets called whenever a device's configuration was changed (e.g. through the app or admin interface)
Args:
model (:class:`festivalgrid.models.Device`): The device that was changed.
"""
raise NotImplementedError
[docs] def digest_msg(self, msg):
"""This method gets called whenever we fetch/receive a new message from a device. You must take care of parsing/interpreting the message and return a dict that can be stored into the time series database.
Args:
msg (str): The message that needs digesting
Returns:
bool::
True -- Cut the power
"""
raise NotImplementedError
[docs] @staticmethod
def provision(ip, stdout):
"""This static method gets called when a user wants to auto-provision a device.
Args:
ip (str): The ip address of the device
stdout (object): Use this to print messages to stdout (i.e. ``stdout.write('test')``)
"""
raise NotImplementedError