コード例 #1
0
    def register(self, features):
        devices = []

        temp = get_feature(features, 'temperature')
        humidity = get_feature(features, 'humidity')
        pressure = get_feature(features, 'pressure')

        if temp:
            alias = generate_alias(temp, 'temp')
            device = TemperatureSensor(domoticz.get_devices(), alias,
                                       temp['property'], ' (Temperature)')
            device.feature = temp
            devices.append(device)

        if humidity:
            alias = generate_alias(humidity, 'hum')
            device = TemperatureSensor(domoticz.get_devices(), alias,
                                       humidity['property'], ' (Humidity)')
            device.feature = humidity
            devices.append(device)

        if pressure:
            alias = generate_alias(pressure, 'pres')
            device = PressureSensor(domoticz.get_devices(), alias,
                                    pressure['property'], ' (Pressure)')
            device.feature = pressure
            devices.append(device)

        if temp and humidity:
            device = TemperatureHumiditySensor(domoticz.get_devices(), 'all',
                                               'temp+hum',
                                               ' (Temperature + Humidity)')
            device.set_temp_feature(temp)
            device.set_humidity_feature(humidity)
            device.feature = temp
            devices.append(device)

        if temp and humidity and pressure:
            device = TemperatureHumidityBarometerSensor(
                domoticz.get_devices(), 'thb', 'temp+hum+bar',
                ' (Temperature + Humidity + Barometer)')
            device.set_temp_feature(temp)
            device.set_humidity_feature(humidity)
            device.set_pressure_feature(pressure)
            device.feature = temp
            devices.append(device)

        return devices
コード例 #2
0
    def _add_light_feature(self, feature):
        light_features = feature['features']

        state = get_feature(light_features, 'state')
        brightness = get_feature(light_features, 'brightness')
        color_temp = get_feature(light_features, 'color_temp')
        color = get_feature(light_features, 'color_xy')

        alias = generate_alias(state, 'light')
        devices = domoticz.get_devices()

        if state and brightness and color_temp and color:
            device = RGBWLight(devices, alias)
            device.set_state_feature(state)
            device.set_brightness_feature(brightness)
            device.set_color_temp_feature(color_temp)
            device.set_color_feature(color)
        elif state and brightness and color:
            device = RGBLight(devices, alias)
            device.set_state_feature(state)
            device.set_brightness_feature(brightness)
            device.set_color_feature(color)
        elif state and brightness and color_temp:
            device = CTLight(devices, alias)
            device.set_state_feature(state)
            device.set_brightness_feature(brightness)
            device.set_color_temp_feature(color_temp)
        elif state and brightness:
            device = DimmerLight(devices, alias)
            device.set_state_feature(state)
            device.set_brightness_feature(brightness)
        elif state:
            device = OnOffLight(devices, 'switch')
            device.set_state_feature(state)
        else:
            domoticz.error(
                self.adapter.name +
                ': can not find appropriate device type to handle light feature'
            )
            domoticz.debug(json.dumps(feature))

        if device:
            device.feature = feature

        # Add rest light features
        for item in light_features:
            name = item['name']

            if name != 'state' and name != 'brightness' and name != 'color_temp' and name != 'color_xy':
                self.adapter._add_feature(item)

        return device
コード例 #3
0
    def _add_cover_feature(self, feature):
        cover_features = feature['features']
        state = get_feature(cover_features, 'state')
        position = get_feature(cover_features, 'position')
        device = None

        if state and position:
            alias = generate_alias(state, 'dimmer')
            device = BlindSwitch(alias, position['property'], ' (Position)')
            device.set_state_feature(state)
            device.set_position_feature(position)
            device.feature = feature

        # Add rest sub features
        for item in cover_features:
            name = item['name']

            if name != 'state' and name != 'position':
                self.adapter._add_feature(item)

        return device