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('My Lamp', ['OnOffSwitch', 'Light'], 'A web connected lamp') thing.add_property( Property(thing, 'on', Value(True), metadata={ '@type': 'OnOffProperty', 'title': 'On/Off', 'type': 'boolean', 'description': 'Whether the lamp is turned on', })) thing.add_property( Property(thing, 'brightness', Value(50), metadata={ '@type': 'BrightnessProperty', 'title': 'Brightness', 'type': 'integer', 'description': 'The level of light from 0-100', 'minimum': 0, 'maximum': 100, 'unit': 'percent', })) 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