Пример #1
0
def make_thing():
    thing = Thing('Sense Hat',
                  type_='Sense Hat',
                  description='A Web Thing Enable Raspberry PI Sense Hat')
    thing.add_property(
        Property(thing,
                 'on',
                 Value(True),
                 metadata={
                     '@type': 'OnOffProperty',
                     'label': 'On/Off',
                     'type': 'boolean',
                     'description': 'Whether the Sense Hat is turned on',
                 }))
    thing.add_available_action(
        'Hello', {
            'label': 'Hello',
            'description': 'Make the sense hat say hello',
            'input': {
                'type': 'object',
                'required': [
                    'text',
                ],
                'properties': {
                    'text': {
                        'type': 'string',
                    },
                },
            },
        }, HelloAction)

    return thing
Пример #2
0
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
Пример #3
0
def initialize_thing():
    thing = Thing('urn:dev:ops:smart_lamp_7256', 'SLamp',
                  ['OnOffSwitch', 'Light'],
                  'A smart lamp connected to the web')

    thing.add_property(
        Property(thing,
                 'on',
                 Value(True),
                 metadata={
                     '@type': 'SwitchProperty',
                     'title': 'On/Off',
                     'type': 'boolean',
                     'description': 'Shows if the lamp is on',
                 }))

    thing.add_property(
        Property(thing,
                 'brightness',
                 Value(50),
                 metadata={
                     '@type': 'BrightnessProperty',
                     'title': 'Brightness',
                     'type': 'integer',
                     'description': 'The light level from 0 to 100',
                     'minimum': 0,
                     'maximum': 100,
                     'unit': 'percent',
                 }))

    thing.add_available_action(
        'change_brightness', {
            'title': 'Change Brightness',
            'description': "Change the lamp brightness to a given level",
            'input': {
                'type': 'object',
                'required': [
                    'brightness',
                ],
                'properties': {
                    'brightness': {
                        'type': 'integer',
                        'minimum': 0,
                        'maximum': 100,
                        'unit': 'percent',
                    },
                },
            },
        }, ChangeBrightnessAction)

    return thing
Пример #4
0
def make_blinds2_thing():
    thing_type = ['UpDownStop', 'Blinds2']
    thing = Thing('blinds_2', 'blinds', thing_type)

    thing.add_available_action(
        'blinds_up', {
            'title': 'Blinds up',
            'description': 'Rise the blinds',
            'metadata': {
                'input': 'None'
            }
        }, blinds_up)

    thing.add_available_action(
        'blinds_down', {
            'title': 'Blinds down',
            'description': 'Lower the blinds',
            'metadata': {
                'input': 'None'
            }
        }, blinds_down)

    thing.add_available_action(
        'blinds_stop', {
            'title': 'Blinds stop',
            'description': 'Stop the blinds',
            'metadata': {
                'input': 'None'
            }
        }, blinds_stop)

    return thing
Пример #5
0
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
Пример #6
0
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
Пример #7
0
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
Пример #8
0
def make_hue_lamp_thing():
    # thing init #
    thing_type = ['OnOffSwitch', 'Light']
    thing = Thing(
        'lights_1',
        'hue_lamp',
        thing_type,
    )

    # thind properties #
    thing.add_property(
        Property(thing,
                 'on',
                 Value(False),
                 metadata={
                     '@type': 'OnOffProperty',
                     'title': 'On/Off',
                     'type': 'boolean',
                     'description': 'Whether the lamp is turned on',
                 }))

    thing.add_property(
        Property(thing,
                 'brightness',
                 Value(0),
                 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,
                 'color',
                 Value('white'),
                 metadata={
                     '@type': 'Color',
                     'title': 'Light color',
                     'type': 'string',
                     'description': 'Lamp Color',
                 }))

    # thing actions #
    thing.add_available_action(
        'on', {
            'title': 'OnAction',
            'description': 'Turn the lamp on',
            'metadata': {
                'input': {
                    'type': 'None'
                }
            }
        }, OnAction)

    thing.add_available_action(
        'off', {
            'title': 'OffAction',
            'description': 'Turn the lamp off',
            'metadata': {
                'input': {
                    'type': 'None'
                }
            }
        }, OffAction)

    thing.add_available_action(
        'color', {
            'title': 'ChangeColor',
            'description': 'Change hue_light color',
            'metadata': {
                'input': {
                    'type': 'object',
                    'required': ['color']
                }
            }
        }, ChangeColor)
    return thing