示例#1
0
文件: 2-sensors.py 项目: xtile/sensor
    def __init__(self, address):
        Thing.__init__(
            self,
            'urn:dev:ops:temperature-sensor',
            'Temperature Sensor',
            ['TemperatureSensor'],
        )

        self.sensor = DS18B20(address)

        self.temperature = Value(self.read_celsius())
        self.add_property(
            Property(self,
                     'temperature',
                     self.temperature,
                     metadata={
                         '@type': 'TemperatureProperty',
                         'title': 'Temperature',
                         'type': 'number',
                         'description': 'The current temperature in °C',
                         'minimum': -50,
                         'maximum': 70,
                         'unit': '°C',
                         'readOnly': True,
                     }))

        logging.debug('starting the sensor update looping task')
        self.timer = tornado.ioloop.PeriodicCallback(self.update, 3000)
        self.timer.start()
示例#2
0
文件: webthings.py 项目: kupcimat/iot
    def __init__(self, uri_id, title, description, value_receiver):
        Thing.__init__(self, uri_id, title, ["MultiLevelSwitch"], description)

        self.add_property(
            Property(thing=self,
                     name="switch",
                     value=Value(
                         False,
                         create_value_forwarder(value_receiver, lambda x: "on" if x else "off")
                     ),
                     metadata={
                         "title": "Switch",
                         "description": "Display on/off switch",
                         "@type": "OnOffProperty",
                         "type": "boolean",
                         "readOnly": False
                     }))
        self.add_property(
            Property(thing=self,
                     name="digit",
                     value=Value(
                         0,
                         create_value_forwarder(value_receiver)
                     ),
                     metadata={
                         "title": "Digit",
                         "description": "Display digit",
                         "@type": "LevelProperty",
                         "type": "integer",
                         "minimum": 0,
                         "maximum": 19,
                         "readOnly": False
                     }))
def make_light(client, observer, light):
    thing = Thing(light['name'], ['OnOffSwitch', 'Light'], 'A web connected lamp')

    def update_on(on):
        client.normal_request(1, light['address'], 1 if on else 0)

    value = Value(False, update_on)
    ioloop = tornado.ioloop.IOLoop.instance()

    def update_handler(what):
        ioloop.add_callback(lambda : value.notify_of_external_update(what != '0'))

    observer.add_listener('1', str(light['address']), update_handler)

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

    return thing
示例#4
0
文件: webthings.py 项目: kupcimat/iot
    def __init__(self, uri_id, title, description, value_receiver):
        Thing.__init__(self, uri_id, title, ["Light"], description)

        self.add_property(
            Property(thing=self,
                     name="switch",
                     value=Value(
                         False,
                         create_value_forwarder(value_receiver, lambda x: "on" if x else "off")
                     ),
                     metadata={
                         "title": "Switch",
                         "description": "Light on/off switch",
                         "@type": "OnOffProperty",
                         "type": "boolean",
                         "readOnly": False
                     }))
        self.add_property(
            Property(thing=self,
                     name="color",
                     value=Value(
                         "#ffffff",
                         # TODO use hex value directly as arduino input?
                         create_value_forwarder(value_receiver, lambda x: int(x[1:], 16))  # convert #0000ff to 255
                     ),
                     metadata={
                         "title": "Color",
                         "description": "Light rgb color",
                         "@type": "ColorProperty",
                         "type": "string",
                         "readOnly": False
                     }))
示例#5
0
    def __init__(self, poll_delay):
        Thing.__init__(
            self,
            "urn:dev:ops:tsl2561-lux-sensor",
            "TSL2561 Lux Sensor",
            ["MultiLevelSensor"],
            "A web connected light/lux sensor",
        )

        self.level = Value(0.0)
        self.add_property(
            Property(
                self,
                "level",
                self.level,
                metadata={
                    "@type": "LevelProperty",
                    "title": "Lux",
                    "type": "number",
                    "description": "The current light in lux",
                    "minimum": 0,
                    "maximum": 200,  # apparently 1000 is an Overcast day; typical TV studio lighting
                    "unit": "lux",
                    "readOnly": True,
                },
            )
        )

        logging.debug("starting the sensor update looping task")
        self.timer = tornado.ioloop.PeriodicCallback(self.update_level, poll_delay)
        self.timer.start()
示例#6
0
    def __init__(self, gpio_number, name, description):
        Thing.__init__(self, 'urn:dev:ops:illuminanceSensor-1',
                       'Illuminance ' + name + ' Sensor', ['MultiLevelSensor'],
                       description)

        self.bright = Value(0)
        self.add_property(
            Property(self,
                     'brightness',
                     self.bright,
                     metadata={
                         '@type': 'BrightnessProperty',
                         'title': 'Brightness',
                         "type": "integer",
                         'minimum': 0,
                         'maximum': 100,
                         'unit': 'percent',
                         'description': '"The level of light from 0-100',
                         'readOnly': True,
                     }))

        self.ioloop = tornado.ioloop.IOLoop.current()
        logging.info('bind to gpio ' + str(gpio_number))
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(gpio_number, GPIO.IN)
        GPIO.add_event_detect(gpio_number,
                              GPIO.BOTH,
                              callback=self.__update,
                              bouncetime=5)
        self.__update(gpio_number)
示例#7
0
    def __init__(self, deviceid):
        self.deviceid = deviceid
        Thing.__init__(self, 'myhumidsensor:{}'.format(self.deviceid),
                       'My {} Humidity Sensor'.format(self.deviceid),
                       ['MultiLevelSensor'], 'A web connected Humid sensor')

        self.level = Value(0.0)
        self.add_property(
            Property(self,
                     'level',
                     self.level,
                     metadata={
                         '@type': 'LevelProperty',
                         'title': 'Humidity',
                         'type': 'number',
                         'description': 'The current humidity in %',
                         'minimum': 0,
                         'maximum': 100,
                         'unit': 'percent',
                         'readOnly': True,
                     }))

        logging.debug('starting the sensor update looping task')
        self.timer = tornado.ioloop.PeriodicCallback(self.update_level, 60000)
        self.timer.start()
    def __init__(self):
        self.thing = Thing('My Humidity Sensor', 'multiLevelSensor',
                           'A web connected humidity sensor')

        self.thing.add_property(
            Property(self.thing,
                     'on',
                     Value(True),
                     metadata={
                         'type': 'boolean',
                         'description': 'Whether the sensor is on',
                     }))

        self.level = Value(0.0)
        self.thing.add_property(
            Property(self.thing,
                     'level',
                     self.level,
                     metadata={
                         'type': 'number',
                         'description': 'The current humidity in %',
                         'unit': '%',
                     }))

        self.ioloop = tornado.ioloop.IOLoop.current()
        t = threading.Thread(target=self.update_level)
        t.daemon = True
        t.start()
    def __init__(self,
                 mqtt_name: str = "mqtt_abstract",
                 uri: str = "urn:dev:siis:abstract",
                 title: str = "Abstract Sensor",
                 capabilities: list = [],
                 desc: str = "An abstract device"):
        Thing.__init__(self,
                       id_=uri,
                       title=title,
                       type_=capabilities,
                       description=desc)
        # Variables
        self.auto_update: bool = True  # Whether the device should use the hardware polling to update itself
        self.name: str = mqtt_name
        self.scheduler_topic: str = cfg.scheduler_topic + self.name

        # MQTT client
        self.client: mqtt.Client = mqtt.Client(self.name)
        self.client.on_connect = self.on_connect
        self.client.on_message = self.on_message
        self.client.tls_set(ca_certs=cfg.cafile,
                            certfile=cfg.certfile,
                            keyfile=cfg.keyfile)
        self.connect()

        # Intruder module
        self.intruder: IntruderNode = IntruderNode(self.name, self.client)
示例#10
0
    def __init__(self, gpio_number, description):
        Thing.__init__(self, 'urn:dev:ops:eltakowsSensor-1', 'Wind Sensor',
                       ['MultiLevelSensor'], description)

        self.gpio_number = gpio_number
        self.start_time = time.time()
        self.num_raise_events = 0
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.gpio_number, GPIO.IN)
        GPIO.add_event_detect(self.gpio_number,
                              GPIO.RISING,
                              callback=self.__spin,
                              bouncetime=5)

        self.timer = tornado.ioloop.PeriodicCallback(self.__measure, 5000)

        self.windspeed = Value(0.0)
        self.add_property(
            Property(self,
                     'windspeed',
                     self.windspeed,
                     metadata={
                         '@type': 'LevelProperty',
                         'title': 'Windspeed',
                         'type': 'number',
                         'minimum': 0,
                         'maximum': 200,
                         'description': 'The current windspeed',
                         'unit': 'km/h',
                         'readOnly': True,
                     }))
        self.timer.start()
    def __init__(self):
        Thing.__init__(self, 'My Humidity Sensor', 'multiLevelSensor',
                       'A web connected humidity sensor')

        self.add_property(
            Property(self,
                     'on',
                     Value(True),
                     metadata={
                         'type': 'boolean',
                         'description': 'Whether the sensor is on',
                     }))

        self.level = Value(0.0)
        self.add_property(
            Property(self,
                     'level',
                     self.level,
                     metadata={
                         'type': 'number',
                         'description': 'The current humidity in %',
                         'unit': '%',
                     }))

        logging.debug('starting the sensor update looping task')
        self.sensor_update_task = \
            get_event_loop().create_task(self.update_level())
示例#12
0
    def __init__(self, tet):
        Thing.__init__(self, 'Tetrahedron', ['OnOffSwitch', 'Light'],
                       'A tetrahedron shaped LED art installation.')

        self.on = False
        self.tetrahedron = tet

        self.add_property(
            Property(self,
                     'on',
                     Value(self.on, self.set_on_off),
                     metadata={
                         '@type': 'OnOffProperty',
                         'title': 'On/Off',
                         'type': 'boolean',
                         'description': 'Whether the tetrahedron is turned on',
                     }))

        self.add_property(
            Property(self,
                     'brightness',
                     Value(50),
                     metadata={
                         '@type': 'BrightnessProperty',
                         'title': 'Brightness',
                         'type': 'integer',
                         'description': 'The level of tetrahedron from 0-100',
                         'minimum': 0,
                         'maximum': 100,
                         'unit': 'percent',
                     }))
示例#13
0
    def __init__(self):
        self.update_period: int = 1500
        Thing.__init__(
            self,
            'urn:dev:ops:my-humidity-sensor-1234',
            'My Humidity Sensor',
            ['MultiLevelSensor'],
            'A web connected humidity sensor'
        )

        self.level = Value(0.0)
        self.add_property(
            Property(self,
                     'level',
                     self.level,
                     metadata={
                         '@type': 'LevelProperty',
                         'title': 'Humidity',
                         'type': 'number',
                         'description': 'The current humidity in %',
                         'minimum': 0,
                         'maximum': 100,
                         'unit': 'percent',
                         'readOnly': True,
                     }))

        logging.debug('starting the sensor update looping task')
        self.timer = tornado.ioloop.PeriodicCallback(
            self.update_level,
            self.update_period
        )
        self.timer.start()
示例#14
0
    def __init__(self, gpio: int, urn: str, title: str, description: str):
        Thing.__init__(
            self,
            urn,
            title,
            ['OnOffSwitch', 'Light'],
            description
        )

        self.add_property(
            Property(self,
                     'on',
                     Value(False, lambda v:
                         self.toggle_level(gpio,v)
                         ),
                     metadata={
                         '@type': 'OnOffProperty',
                         'title': 'On/Off',
                         'type': 'boolean',
                         'description': 'Sprinkler state',
                     }))

        self.add_property(
            Property(self,
                     'brightness',
                     Value(120, lambda v: logging.info('Timeout is now %d min. %d sec.',  v / 60 , v % 60)),
                     metadata={
                         '@type': 'LevelProperty',
                         'title': 'Durée',
                         'type': 'integer',
                         'description': 'Time of sprinkle from 60 to 300 seconds',
                         'minimum': 60,
                         'maximum': 300,
                         'unit': 'second',
                     }))
 def __init__(self, id, description, data_to_measure, measures_tick):
     # Create the device
     Thing.__init__(self, 'urn:dev:ops:' + id, description,
                    ['MultiLevelSensor'], 'A web connected sensor')
     # create a variable that will be update in each measure
     self.level = Value(0.0)
     # add level property to the thing
     self.add_property(
         Property(self,
                  'level',
                  self.level,
                  metadata={
                      '@type': 'LevelProperty',
                      'title': data_to_measure,
                      'type': 'number',
                      'description':
                      'The current ' + data_to_measure + ' in %',
                      'minimum': 0,
                      'maximum': 100,
                      'unit': 'percent',
                      'readOnly': True,
                  }))
     # create a timer that will call update_level periodically
     logging.debug('starting the sensor update looping task')
     self.timer = tornado.ioloop.PeriodicCallback(self.update_level,
                                                  measures_tick)
     self.timer.start()
    def __init__(self, name):
        self.name = name
        Thing.__init__(self, 'urn:dev:ops:'+name, name, ['OnOffSwitch', 'Light'], 'A virtual Unity light')
        self.add_property(
            Property(self,
                     'on',
                     Value(True, lambda v: print('On-State is now', v)),
                     metadata={
                         '@type': 'OnOffProperty',
                         'title': 'On/Off',
                         'type': 'boolean',
                         'description': 'Whether the lamp is turned on',
                     }))

        self.add_property(
            Property(self,
                     'brightness',
                     Value(50, lambda v: print('Brightness is now', v)),
                     metadata={
                         '@type': 'BrightnessProperty',
                         'title': 'Brightness',
                         'type': 'integer',
                         'description': 'The level of light from 0-100',
                         'minimum': 0,
                         'maximum': 100,
                         'unit': 'percent',
                     }))
示例#17
0
 def __init__(self, _location, _w1_device_id_list):
     self.location = _location
     self.id = f'urn:dev:ops:{self.location}-vorraum-node'
     self.name = f'{self.location}-node_functions'
     self.w1_device_id_list = _w1_device_id_list
     Thing.__init__(self, self.id, self.name, ['EnergyMonitor'],
                    'A web connected node')
     self.ina219 = ina219.INA219(busnum=0, address=0x40)
     self.power = Value(0.0)
     self.add_property(
         Property(self,
                  f'{self.name}-power',
                  self.power,
                  metadata={
                      '@type': 'InstantaneousPowerProperty',
                      'title': f'{self.name}-Power',
                      'type': 'float',
                      'multipleOf': 0.01,
                      'description': 'the power used by this node',
                  }))
     self.volt = Value(0.0)
     self.add_property(
         Property(self,
                  f'{self.name}-voltage',
                  self.volt,
                  metadata={
                      '@type': 'VoltageProperty',
                      'title': f'{self.name}-Voltage',
                      'type': 'float',
                      'multipleOf': 0.01,
                      'description': 'the voltage used by this node',
                  }))
     self.current = Value(0.0)
     self.add_property(
         Property(self,
                  f'{self.name}-current',
                  self.current,
                  metadata={
                      '@type': 'CurrentProperty',
                      'title': f'{self.name}-Current',
                      'type': 'float',
                      'multipleOf': 0.01,
                      'description': 'the current used by this node',
                  }))
     self.temperature = Value(0.0)
     self.add_property(
         Property(self,
                  f'{self.name}-Temperature',
                  self.temperature,
                  metadata={
                      '@type': 'TemperatureProperty',
                      'title': f'{self.name}-Temperature',
                      'type': 'float',
                      'multipleOf': 0.01,
                      'description': 'the temperature in the case',
                  }))
     self.timer = tornado.ioloop.PeriodicCallback(self.get_sensors, 300000)
     self.timer.start()
示例#18
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
示例#19
0
 def __init__(self):
     Thing.__init__(self, 'urn:dev:ops:my-picam-thing-1234',
                    'My PiCamera Thing', ['VideoCamera'],
                    'A web connected Pi Camera')
     self.terminated = False
     self.picam = picamera.PiCamera(resolution='720p', framerate=30)
     self.still_img = Value(None)
     self.add_property(
         Property(self,
                  'snapshot',
                  self.still_img,
                  metadata={
                      '@type':
                      'ImageProperty',
                      'title':
                      'Snapshot',
                      'type':
                      'null',
                      'readOnly':
                      True,
                      'links': [{
                          'rel': 'alternate',
                          'href': '/media/snapshot',
                          'mediaType': 'image/jpeg'
                      }]
                  }))
     #self.stream_active = Value(False)
     #self.add_property(
     #    Property(self, 'streamActive', self.stream_active,
     #            metadata = {
     #                        'title': 'Streaming',
     #                        'type': 'boolean',
     #                        }))
     self.stream = Value(None)
     self.add_property(
         Property(self,
                  'stream',
                  self.stream,
                  metadata={
                      '@type':
                      'VideoProperty',
                      'title':
                      'Stream',
                      'type':
                      'null',
                      'readOnly':
                      True,
                      'links': [{
                          'rel': 'alternate',
                          'href': '/media/stream',
                          'mediaType': 'video/x-jpeg'
                      }]
                  }))
     syslog.syslog('Starting the camera')
     self.cam_thr = threading.Thread(target=self.start_PiCam, args=())
     self.cam_thr.start()
    def __init__(self):
        Thing.__init__(self, 'urn:dev:ops:my-sense-hat-sensor-1234',
                       'SenseHat Sensor', [], 'A web connected sense hat')
        controller.set_imu_config(True, True, True)

        self.pitch = Value(0.0)
        self.add_property(
            Property(self,
                     'pitch',
                     self.pitch,
                     metadata={
                         'title': 'Pitch',
                         'type': 'number',
                         'description': 'Angle pitch',
                         'unit': 'd',
                         'minimum': 0,
                         'maximum': 360,
                         'readOnly': True,
                     }))

        self.roll = Value(0.0)
        self.add_property(
            Property(self,
                     'roll',
                     self.roll,
                     metadata={
                         'title': 'Roll',
                         'type': 'number',
                         'description': 'Angle',
                         'unit': 'd',
                         'minimum': 0,
                         'maximum': 360,
                         'readOnly': True,
                     }))

        self.yaw = Value(0.0)
        self.add_property(
            Property(self,
                     'yaw',
                     self.yaw,
                     metadata={
                         'title': 'Yaw',
                         'type': 'number',
                         'description': 'Angle',
                         'unit': 'd',
                         'minimum': 0,
                         'maximum': 360,
                         'readOnly': True,
                     }))

        logging.debug('info: starting the sensor update looping task')
        self.timer = tornado.ioloop.PeriodicCallback(self.update_properties,
                                                     1000)
        self.timer.start()
示例#21
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
示例#22
0
    def __init__(self, photos_path, static_path):
        """Initialize the thing."""
        Thing.__init__(self, 'urn:dev:ops:photo-cycler', 'Photo Cycler', [],
                       'Photo Cycler')

        self.photos_path = photos_path
        self.static_path = static_path
        self.update_rate = 5

        self.add_property(
            Property(self,
                     'updateRate',
                     Value(self.update_rate, self.set_update_rate),
                     metadata={
                         'type': 'integer',
                         'description': 'Photo cycle rate',
                         'minimum': 0,
                         'unit': 'second',
                         'title': 'Update Rate',
                     }))

        self.add_property(
            Property(self,
                     'image',
                     Value(None),
                     metadata={
                         '@type':
                         'ImageProperty',
                         'type':
                         'null',
                         'description':
                         'Current image',
                         'title':
                         'Image',
                         'readOnly':
                         True,
                         'links': [
                             {
                                 'rel': 'alternate',
                                 'href': '/static/current.jpg',
                                 'mediaType': 'image/jpeg',
                             },
                         ],
                     }))

        self.set_ui_href('/static/index.html')

        self.timer = None
        self.set_update_rate(self.update_rate)
示例#23
0
文件: webthings.py 项目: kupcimat/iot
    def __init__(self, uri_id, title, description, value):
        Thing.__init__(self, uri_id, title, ["TemperatureSensor"], description)

        self.add_property(
            Property(thing=self,
                     name="temperature",
                     value=value,
                     metadata={
                         "title": "Temperature",
                         "description": "The current temperature in °C",
                         "@type": "TemperatureProperty",
                         "type": "number",
                         "unit": "degree celsius",
                         "readOnly": True
                     }))
    def __init__(self):
        Thing.__init__(self, 'urn:dev:ops:my-sense-hat-light-1234',
                       'SenseHat Light', ['OnOffSwitch', 'Light'],
                       'A web connected lamp')

        self.add_property(
            Property(self,
                     'on',
                     Value(True, lambda v: self.toggle(v)),
                     metadata={
                         '@type': 'OnOffProperty',
                         'title': 'On/Off',
                         'type': 'boolean',
                         'description': 'Whether the lamp is turned on',
                     }))
class FakeGpioHumiditySensor:
    """A humidity sensor which updates its measurement every few seconds."""
    def __init__(self):
        self.thing = Thing('My Humidity Sensor', 'multiLevelSensor',
                           'A web connected humidity sensor')

        self.thing.add_property(
            Property(self.thing,
                     'on',
                     Value(True),
                     metadata={
                         'type': 'boolean',
                         'description': 'Whether the sensor is on',
                     }))

        self.level = Value(0.0)
        self.thing.add_property(
            Property(self.thing,
                     'level',
                     self.level,
                     metadata={
                         'type': 'number',
                         'description': 'The current humidity in %',
                         'unit': '%',
                     }))

        self.ioloop = tornado.ioloop.IOLoop.current()
        t = threading.Thread(target=self.update_level)
        t.daemon = True
        t.start()

    def update_level(self):
        while True:
            time.sleep(3)

            # Update the underlying value, which in turn notifies all listeners
            self.ioloop.add_callback(self.level.notify_of_external_update,
                                     self.read_from_gpio())

    @staticmethod
    def read_from_gpio():
        """Mimic an actual sensor updating its reading every couple seconds."""
        return 70.0 * random.random() * (-0.5 + random.random())

    def get_thing(self):
        return self.thing
示例#26
0
文件: webthings.py 项目: kupcimat/iot
    def __init__(self, uri_id, title, description, value, property_title, property_description):
        Thing.__init__(self, uri_id, title, ["MultiLevelSensor"], description)

        self.add_property(
            Property(thing=self,
                     name=property_title.lower(),
                     value=value,
                     metadata={
                         "title": property_title,
                         "description": property_description,
                         "@type": "LevelProperty",
                         "type": "number",
                         "unit": "percent",
                         "minimum": 0,
                         "maximum": 100,
                         "readOnly": True
                     }))
示例#27
0
 def __init__(self):
     self.listening = True
     self.volume = 50
     self.sensitivity = 45
     Thing.__init__(self, 'VoiceAssistant1', ['VoiceAssistant1'],
                    'CustomThing')
     self.add_property(
         Property(
             self,
             'on',
             #@https://discourse.mozilla.org/t/how-to-trigger-an-event-when-a-property-value-is-changed/34800/4
             Value(self.listening, self.setListen),
             metadata={
                 '@type': 'OnOffProperty',
                 'title': 'Listening',
                 'type': 'boolean',
                 'description':
                 'Whether the listening is muted on this object',
             }))
     self.add_property(
         Property(self,
                  'volume',
                  Value(self.volume, self.setVolume),
                  metadata={
                      '@type': 'BrightnessProperty',
                      'title': 'Volume',
                      'type': 'integer',
                      'description': 'The sound level from 0-100',
                      'minimum': 0,
                      'maximum': 100,
                      'unit': 'percent',
                  }))
     self.add_property(
         Property(self,
                  'sensitivity',
                  Value(self.sensitivity, self.setSensitivity),
                  metadata={
                      '@type': 'BrightnessProperty',
                      'title': 'Sensitivity',
                      'type': 'integer',
                      'description': 'The sensitivty level from 0-100',
                      'minimum': 20,
                      'maximum': 85,
                      'unit': 'percent',
                  }))
示例#28
0
文件: things.py 项目: rymurr/pyiot
    def __init__(self):
        Thing.__init__(self, 'ObserverIP Weather Sensor', ['MultiLevelSensor'],
                       'A web connected weather sensor')

        self.humidity = Value(0.0)
        self.add_property(
            Property(self,
                     'humidity',
                     self.humidity,
                     metadata={
                         '@type': 'LevelProperty',
                         'title': 'Humidity',
                         'type': 'number',
                         'description': 'The current humidity in %',
                         'minimum': 0,
                         'maximum': 100,
                         'unit': 'percent',
                         'readOnly': True,
                     }))
示例#29
0
    def __init__(self, gpio_number, name, description):
        Thing.__init__(self, 'urn:dev:ops:motionSensor-1',
                       'Motion ' + name + ' Sensor', ['MotionSensor'],
                       description)

        self.gpio_number = gpio_number
        GPIO.setmode(GPIO.BCM)
        GPIO.setup(self.gpio_number, GPIO.IN)
        GPIO.add_event_detect(self.gpio_number,
                              GPIO.BOTH,
                              callback=self.__update,
                              bouncetime=5)
        self.is_motion = False

        self.motion = Value(False)
        self.add_property(
            Property(self,
                     'motion',
                     self.motion,
                     metadata={
                         '@type': 'MotionProperty',
                         'title': 'Motion detected',
                         "type": "boolean",
                         'description':
                         'Whether ' + name + ' motion is detected',
                         'readOnly': True,
                     }))

        self.last_motion = Value(datetime.now().isoformat())
        self.add_property(
            Property(self,
                     'motion_last_seen',
                     self.last_motion,
                     metadata={
                         'title': 'Motion last seen',
                         "type": "string",
                         'unit': 'datetime',
                         'description':
                         'The ISO 8601 date time of last movement',
                         'readOnly': True,
                     }))
        self.ioloop = tornado.ioloop.IOLoop.current()
    def __init__(self, name):
        self.name = name
        Thing.__init__(
            self,
            'urn:dev:ops:my-humidity-sensor-'+name,
            name,
            ['OnOffSwitch'],
            'A web button'
        )

        self.add_property(
            Property(self,
                     'on',
                     Value(True, lambda v: print('On-State is now', v)),
                     metadata={
                         '@type': 'OnOffProperty',
                         'title': 'On/Off',
                         'type': 'boolean',
                         'description': 'Whether the lamp is turned on',
                     }))