Beispiel #1
0
 def addActor(self, index, type):
     if type == 'motor':
         self.outputs[index] = self.txt.C_MOTOR
         plug = 'M' + str(index + 1)
         self.thing.add_property(
             webthing.Property(
                 self.thing,
                 plug,
                 webthing.Value(
                     0,
                     lambda new_value: self.update_output(index, new_value)
                 ),
                 metadata={
                     '@type': 'LevelProperty',
                     'title': plug,
                     'type': 'integer',
                     'minimum': -512,
                     'maximum': 512
                 }
             )
         )
     elif type == 'light':
         self.outputs[index] = self.txt.C_OUTPUT
         for offset in range(1, 3):
             self.addLight(index, offset)
Beispiel #2
0
 def addStateProps(self):
     self.thing.add_property(
         webthing.Property(
             self.thing,
             'inputVoltage',
             webthing.Value(self.txt.getPower() / 1000),
             metadata={
                 '@type': 'VoltageProperty',
                 'type': 'number',
                 'readOnly': True,
                 'unit': 'volt',
                 'title': 'Input voltage'
             }
         )
     )
     self.thing.add_property(
         webthing.Property(
             self.thing,
             'refVoltage',
             webthing.Value(self.txt.getReferencePower() / 1000),
             metadata={
                 '@type': 'VoltageProperty',
                 'type': 'number',
                 'readOnly': True,
                 'unit': 'volt',
                 'title': 'Reference voltage'
             }
         )
     )
     self.thing.add_property(
         webthing.Property(
             self.thing,
             'temperature',
             webthing.Value(self.txt.getTemperature()),
             metadata={
                 # '@type': 'TemperatureProperty',
                 'type': 'number',
                 'readOnly': True,
                 'title': 'Temperature'
                 # 'unit': 'degrees celsius'
             }
         )
     )
Beispiel #3
0
    def addSensor(self, index, type):
        unit = None
        semanticType = None
        name = 'I' + str(index + 1)

        if type == 'pushbutton':
            rawType = 'boolean'
            semanticType = 'PushedProperty'
            self.addCapability('PushButton')
            self.inputs[index] = (self.txt.C_SWITCH, self.txt.C_DIGITAL)
            self.thing.add_available_event('pressedEvent' + name, {
                '@type': 'PressedEvent',
                'title': name + ' pressed'
            })
        elif type == 'resistor':
            rawType = 'number'
            unit = 'Ohm'
            self.inputs[index] = (self.txt.C_RESISTOR, self.txt.C_ANALOG)
        elif type == 'ultrasonic':
            rawType = 'number'
            unit = 'meter'
            self.inputs[index] = (self.txt.C_ULTRASONIC, self.txt.C_ANALOG)
        elif type == 'voltage':
            rawType = 'number'
            unit = 'volt'
            semanticType = 'VoltageProperty'
            self.inputs[index] = (self.txt.C_VOLTAGE, self.txt.C_ANALOG)
        elif type == 'linesens':
            rawType = 'boolean'
            semanticType = 'BooleanProperty'
            self.addCapability('BinarySensor')
            self.inputs[index] = (self.txt.C_SWITCH, self.txt.C_DIGITAL)
        elif type == 'colorsens':
            rawType = 'string'
            self.inputs[index] = (self.txt.C_VOLTAGE, self.txt.C_ANALOG)
            semanticType = 'ColorProperty'
            self.addCapability('ColorControl')

        self.sensors[index] = type
        value = webthing.Value(self.getSensorValue(index, type))

        self.thing.add_property(
            webthing.Property(
                self.thing,
                name,
                value,
                metadata={
                    'title': name,
                    'type': rawType,
                    'readOnly': True,
                    'unit': unit,
                    '@type': semanticType
                }
            )
        )
Beispiel #4
0
 def addCounter(self, index):
     self.thing.add_property(
         webthing.Property(
             self.thing,
             'C' + str(index + 1),
             webthing.Value(self.txt.getCurrentCounterValue(index)),
             metadata={
                 'type': 'integer',
                 'minimum': 0,
                 'readOnly': True
             }
         )
     )
Beispiel #5
0
 def addLight(self, index, offset):
     plug = 'O' + str((index * 2) + offset)
     self.thing.add_property(
         webthing.Property(
             self.thing,
             plug,
             webthing.Value(
                 1,
                 lambda new_value: self.update_output(
                     index,
                     new_value,
                     offset
                 )
             ),
             metadata={
                 '@type': 'LevelProperty',
                 'title': plug,
                 'type': 'integer',
                 'minimum': 1,
                 'maximum': 512
             }
         )
     )
Beispiel #6
0
 def addCamera(self, cam):
     if self.temp_dir is None:
         self.temp_dir = TemporaryDirectory()
     self.thing.add_property(
         webthing.Property(
             self.thing,
             'camera' + str(cam),
             webthing.Value(None),
             metadata={
                 'title': 'Camera',
                 'readOnly': True,
                 '@type': 'ImageProperty',
                 'links': [
                     {
                         'rel': 'alternate',
                         'href': '/static/camera' + str(cam) + '.jpg',
                         'mediaType': 'image/jpeg'
                     }
                 ]
             }
         )
     )
     self.addCapability('Camera')
     self.cams.append(cam)