def make_thing(): thing = Thing('My Lamp', 'dimmableLight', 'A web connected lamp') def noop(_): pass thing.add_property( Property(thing, 'on', Value(True, noop), metadata={ 'type': 'boolean', 'description': 'Whether the lamp is turned on', })) thing.add_property( Property(thing, 'level', Value(50, noop), metadata={ 'type': 'number', 'description': 'The level of light from 0-100', 'minimum': 0, 'maximum': 100, })) thing.add_available_action( 'fade', { 'description': 'Fade the lamp to a given level', 'input': { 'type': 'object', 'required': [ 'level', 'duration', ], 'properties': { 'level': { 'type': 'number', 'minimum': 0, 'maximum': 100, }, 'duration': { 'type': 'number', 'unit': 'milliseconds', }, }, } }, FadeAction) thing.add_available_event( 'overheated', { 'description': 'The lamp has exceeded its safe operating temperature', 'type': 'number', 'unit': 'celsius' }) return thing
def make_thing(): thing = Thing('urn:dev:ops:my-lamp-1234', 'My pi Led', ['OnOffSwitch', 'Light'], 'A web connected Led') thing.add_property( Property(thing, 'on', Value(True, lambda v: GPIO.output(led, v)), metadata={ '@type': 'OnOffProperty', 'title': 'On/Off', 'type': 'boolean', 'description': 'Whether the lamp is turned on', })) thing.add_available_event( 'overheated', { 'description': 'The lamp has exceeded its safe operating temperature', 'type': 'number', 'unit': 'degree celsius', }) return thing
def make_thing(): thing = Thing('My Lamp', ['OnOffSwitch', 'Light'], 'A web connected lamp') thing.add_property( Property(thing, 'on', Value(True), metadata={ '@type': 'OnOffProperty', 'label': 'On/Off', 'type': 'boolean', 'description': 'Whether the lamp is turned on', })) thing.add_property( Property(thing, 'brightness', Value(50), metadata={ '@type': 'BrightnessProperty', 'label': 'Brightness', 'type': 'integer', 'description': 'The level of light from 0-100', 'minimum': 0, 'maximum': 100, 'unit': 'percent', })) thing.add_available_action( 'fade', { 'label': 'Fade', 'description': 'Fade the lamp to a given level', 'input': { 'type': 'object', 'required': [ 'brightness', 'duration', ], 'properties': { 'brightness': { 'type': 'integer', 'minimum': 0, 'maximum': 100, 'unit': 'percent', }, 'duration': { 'type': 'integer', 'minimum': 1, 'unit': 'milliseconds', }, }, }, }, FadeAction) thing.add_available_event( 'overheated', { 'description': 'The lamp has exceeded its safe operating temperature', 'type': 'number', 'unit': 'degree celsius', }) return thing
def make_thing(): thing = Thing( 'urn:dev:ops:my-lamp-1234', 'My Simple Lamp', ['OnOffSwitch', 'Light'], 'A web connected lamp' ) thing.add_property( Property(thing, 'on', Value(True, lambda v: logging.debug("On-state is now %s" % v)), metadata={ '@type': 'OnOffProperty', 'title': 'On/Off', 'type': 'boolean', 'description': 'Whether the lamp is turned on', })) thing.add_property( Property(thing, 'brightness', Value(50, lambda v: logging.debug("Brightness is now %d" % v)), metadata={ '@type': 'BrightnessProperty', 'title': 'Brightness', 'type': 'integer', 'description': 'The level of light from 0-100', 'minimum': 0, 'maximum': 100, 'unit': 'percent', })) thing.add_property( Property(thing, "URL", Value(None), metadata={ '@type': 'ImageProperty', 'title': 'Image URL', 'type': 'null', 'description': 'URL of the image to be played', 'links': [{ 'rel': 'alternate', 'href': '/static/current.jpg', 'mediaType': 'image/jpeg', }, ], })) thing.add_available_action( 'fade', { 'title': 'Fade', 'description': 'Fade the lamp to a given level', 'input': { 'type': 'object', 'required': [ 'brightness', 'duration', ], 'properties': { 'brightness': { 'type': 'integer', 'minimum': 0, 'maximum': 100, 'unit': 'percent', }, 'duration': { 'type': 'integer', 'minimum': 1, 'unit': 'milliseconds', }, }, }, }, FadeAction) thing.add_available_event( 'overheated', { 'description': 'The lamp has exceeded its safe operating temperature', 'type': 'number', 'unit': 'degree celsius', }) return thing
class ExampleDimmableLight: """A dimmable light that logs received commands to stdout.""" def __init__(self): self.thing = Thing('My Lamp', 'dimmableLight', 'A web connected lamp') self.thing.add_available_action( 'fade', { 'description': 'Fade the lamp to a given level', 'input': { 'type': 'object', 'required': [ 'level', 'duration', ], 'properties': { 'level': { 'type': 'number', 'minimum': 0, 'maximum': 100, }, 'duration': { 'type': 'number', 'unit': 'milliseconds', }, }, } }, FadeAction) self.thing.add_available_event( 'overheated', { 'description': 'The lamp has exceeded its safe operating temperature', 'type': 'number', 'unit': 'celsius' }) self.thing.add_property(self.get_on_property()) self.thing.add_property(self.get_level_property()) def get_on_property(self): return Property(self.thing, 'on', Value(True, lambda v: print('On-State is now', v)), metadata={ 'type': 'boolean', 'description': 'Whether the lamp is turned on', }) def get_level_property(self): return Property(self.thing, 'level', Value(50, lambda l: print('New light level is', l)), metadata={ 'type': 'number', 'description': 'The level of light from 0-100', 'minimum': 0, 'maximum': 100, }) def get_thing(self): return self.thing