def __init__(self, devices):
        super().__init__(devices)

        self.switch = ToggleSwitch(devices, 'switch', 'action')

        self.arrow_left = SelectorSwitch(devices, 'arrowL', 'action',
                                         ' (Left Arrow)')
        self.arrow_left.add_level('Off', None)
        self.arrow_left.add_level('Click', 'arrow_left_click')
        self.arrow_left.add_level('Hold', 'arrow_left_hold')
        self.arrow_left.add_level('Release', 'arrow_left_release')
        self.arrow_left.set_selector_style(
            SelectorSwitch.SELECTOR_TYPE_BUTTONS)
        self.arrow_left.disable_value_check_on_update()

        self.arrow_right = SelectorSwitch(devices, 'arrowR', 'action',
                                          ' (Right Arrow)')
        self.arrow_right.add_level('Off', None)
        self.arrow_right.add_level('Click', 'arrow_right_click')
        self.arrow_right.add_level('Hold', 'arrow_right_hold')
        self.arrow_right.add_level('Release', 'arrow_right_release')
        self.arrow_right.set_selector_style(
            SelectorSwitch.SELECTOR_TYPE_BUTTONS)
        self.arrow_right.disable_value_check_on_update()

        self.brightness_up = SelectorSwitch(devices, 'brUp', 'action',
                                            ' (Brightness Up)')
        self.brightness_up.add_level('Off', None)
        self.brightness_up.add_level('Click', 'brightness_up_click')
        self.brightness_up.add_level('Hold', 'brightness_up_hold')
        self.brightness_up.add_level('Release', 'brightness_up_release')
        self.brightness_up.set_selector_style(
            SelectorSwitch.SELECTOR_TYPE_BUTTONS)
        self.brightness_up.disable_value_check_on_update()

        self.brightness_down = SelectorSwitch(devices, 'brDown', 'action',
                                              ' (Brightness Down)')
        self.brightness_down.add_level('Off', None)
        self.brightness_down.add_level('Click', 'brightness_down_click')
        self.brightness_down.add_level('Hold', 'brightness_down_hold')
        self.brightness_down.add_level('Release', 'brightness_down_release')
        self.brightness_down.set_selector_style(
            SelectorSwitch.SELECTOR_TYPE_BUTTONS)
        self.brightness_down.disable_value_check_on_update()

        self.devices.append(self.switch)
        self.devices.append(self.arrow_left)
        self.devices.append(self.arrow_right)
        self.devices.append(self.brightness_up)
        self.devices.append(self.brightness_down)
Пример #2
0
    def __init__(self, devices):
        super().__init__(devices)

        rotation_switch = SelectorSwitch(devices, 'rotate', 'rotation', ' (Rotation)')
        rotation_switch.add_level('Off', 'rotate_stop')
        rotation_switch.add_level('Left', 'rotate_left')
        rotation_switch.add_level('Right', 'rotate_right')
        rotation_switch.disable_value_check_on_update()

        self.devices.append(DimmerSwitch(devices, 'dimmer', 'brightness', ' (Level)'))
        self.devices.append(ToggleSwitch(devices, 'switch', 'click', ' (Switch)'))
        self.devices.append(rotation_switch)
Пример #3
0
    def __init__(self, devices):
        super().__init__(devices)

        self.switch = ToggleSwitch(devices, 'switch', 'action')

        self.selector_switch = SelectorSwitch(devices, 'sel', 'action',
                                              ' (Selector)')
        self.selector_switch.add_level('Off', None)

        self.selector_switch.add_level('brightness-up-click',
                                       'brightness_up_click')
        self.selector_switch.add_level('brightness-up-hold',
                                       'brightness_up_hold')
        self.selector_switch.add_level('brightness-up-release',
                                       'brightness_up_release')

        self.selector_switch.add_level('brightness-down-click',
                                       'brightness_down_click')
        self.selector_switch.add_level('brightness-down-hold',
                                       'brightness_down_hold')
        self.selector_switch.add_level('brightness-down-release',
                                       'brightness_down_release')

        self.selector_switch.add_level('arrow-left-click', 'arrow_left_click')
        self.selector_switch.add_level('arrow-left-hold', 'arrow_left_hold')
        self.selector_switch.add_level('arrow-left-release',
                                       'arrow_left_release')

        self.selector_switch.add_level('arrow-right-click',
                                       'arrow_right_click')
        self.selector_switch.add_level('arrow-right-hold', 'arrow_right_hold')
        self.selector_switch.add_level('arrow-right-release',
                                       'arrow_right_release')

        self.selector_switch.disable_value_check_on_update()

        self.selector_switch.set_selector_style(
            SelectorSwitch.SELECTOR_TYPE_MENU)
        self.devices.append(self.switch)
        self.devices.append(self.selector_switch)
class TradfriRemoteControl(AdapterWithBattery):
    def __init__(self):
        super().__init__()

        self.switch = ToggleSwitch('switch', 'action')

        self.arrow_left = SelectorSwitch('arrowL', 'action', ' (Left Arrow)')
        self.arrow_left.add_level('Off', None)
        self.arrow_left.add_level('Click', 'arrow_left_click')
        self.arrow_left.add_level('Hold', 'arrow_left_hold')
        self.arrow_left.add_level('Release', 'arrow_left_release')
        self.arrow_left.set_selector_style(
            SelectorSwitch.SELECTOR_TYPE_BUTTONS)
        self.arrow_left.disable_value_check_on_update()

        self.arrow_right = SelectorSwitch('arrowR', 'action', ' (Right Arrow)')
        self.arrow_right.add_level('Off', None)
        self.arrow_right.add_level('Click', 'arrow_right_click')
        self.arrow_right.add_level('Hold', 'arrow_right_hold')
        self.arrow_right.add_level('Release', 'arrow_right_release')
        self.arrow_right.set_selector_style(
            SelectorSwitch.SELECTOR_TYPE_BUTTONS)
        self.arrow_right.disable_value_check_on_update()

        self.brightness_up = SelectorSwitch('brUp', 'action',
                                            ' (Brightness Up)')
        self.brightness_up.add_level('Off', None)
        self.brightness_up.add_level('Click', 'brightness_up_click')
        self.brightness_up.add_level('Hold', 'brightness_up_hold')
        self.brightness_up.add_level('Release', 'brightness_up_release')
        self.brightness_up.set_selector_style(
            SelectorSwitch.SELECTOR_TYPE_BUTTONS)
        self.brightness_up.disable_value_check_on_update()

        self.brightness_down = SelectorSwitch('brDown', 'action',
                                              ' (Brightness Down)')
        self.brightness_down.add_level('Off', None)
        self.brightness_down.add_level('Click', 'brightness_down_click')
        self.brightness_down.add_level('Hold', 'brightness_down_hold')
        self.brightness_down.add_level('Release', 'brightness_down_release')
        self.brightness_down.set_selector_style(
            SelectorSwitch.SELECTOR_TYPE_BUTTONS)
        self.brightness_down.disable_value_check_on_update()

        self.devices.append(self.switch)
        self.devices.append(self.arrow_left)
        self.devices.append(self.arrow_right)
        self.devices.append(self.brightness_up)
        self.devices.append(self.brightness_down)

    def handle_command(self, alias, device, command, level, color):
        device_data = self._get_legacy_device_data()
        device = self.get_device_by_alias(alias)

        if device != None:
            device.handle_command(device_data, command, level, color)

    def handle_mqtt_message(self, message):
        if 'action' not in message.raw:
            return

        device_data = self._get_legacy_device_data()
        converted_message = self.convert_message(message)
        action = message.raw['action']

        if action == None:
            return

        if action == 'toggle':
            self.switch.handle_message(device_data, converted_message)

        if action.startswith('brightness_up'):
            self.brightness_up.handle_message(device_data, converted_message)

        if action.startswith('brightness_down'):
            self.brightness_down.handle_message(device_data, converted_message)

        if action.startswith('arrow_right'):
            self.arrow_right.handle_message(device_data, converted_message)

        if action.startswith('arrow_left'):
            self.arrow_left.handle_message(device_data, converted_message)

        self.update_battery_status(device_data, converted_message)
        self.update_link_quality(device_data, converted_message)
Пример #5
0
class TradfriRemoteControl(AdapterWithBattery):
    def __init__(self, devices):
        super().__init__(devices)

        self.switch = ToggleSwitch(devices, 'switch', 'action')

        self.selector_switch = SelectorSwitch(devices, 'sel', 'action',
                                              ' (Selector)')
        self.selector_switch.add_level('Off', None)

        self.selector_switch.add_level('brightness-up-click',
                                       'brightness_up_click')
        self.selector_switch.add_level('brightness-up-hold',
                                       'brightness_up_hold')
        self.selector_switch.add_level('brightness-up-release',
                                       'brightness_up_release')

        self.selector_switch.add_level('brightness-down-click',
                                       'brightness_down_click')
        self.selector_switch.add_level('brightness-down-hold',
                                       'brightness_down_hold')
        self.selector_switch.add_level('brightness-down-release',
                                       'brightness_down_release')

        self.selector_switch.add_level('arrow-left-click', 'arrow_left_click')
        self.selector_switch.add_level('arrow-left-hold', 'arrow_left_hold')
        self.selector_switch.add_level('arrow-left-release',
                                       'arrow_left_release')

        self.selector_switch.add_level('arrow-right-click',
                                       'arrow_right_click')
        self.selector_switch.add_level('arrow-right-hold', 'arrow_right_hold')
        self.selector_switch.add_level('arrow-right-release',
                                       'arrow_right_release')

        self.selector_switch.disable_value_check_on_update()

        self.selector_switch.set_selector_style(
            SelectorSwitch.SELECTOR_TYPE_MENU)
        self.devices.append(self.switch)
        self.devices.append(self.selector_switch)

    def handle_command(self, alias, device, command, level, color):
        device_data = self._get_legacy_device_data()
        device = self.get_device_by_alias(alias)

        if device != None:
            device.handle_command(device_data, command, level, color)

    def handle_mqtt_message(self, message):
        if 'action' not in message.raw:
            return

        device_data = self._get_legacy_device_data()
        converted_message = self.convert_message(message)
        action = message.raw['action']

        if action == 'toggle':
            self.switch.handle_message(device_data, converted_message)

        if action.startswith('brightness_up'):
            self.selector_switch.handle_message(device_data, converted_message)

        if action.startswith('brightness_down'):
            self.selector_switch.handle_message(device_data, converted_message)

        if action.startswith('arrow_right'):
            self.selector_switch.handle_message(device_data, converted_message)

        if action.startswith('arrow_left'):
            self.selector_switch.handle_message(device_data, converted_message)

        self.update_battery_status(device_data, converted_message)
        self.update_link_quality(device_data, converted_message)
Пример #6
0
class TradfriRemoteControl(AdapterWithBattery):
    def __init__(self, devices):
        super().__init__(devices)

        self.switch = ToggleSwitch(devices, 'switch', 'action')

        self.arrow_left = SelectorSwitch(devices, 'arrowL', 'action',
                                         ' (Left Arrow)')
        self.arrow_left.add_level('Off', None)
        self.arrow_left.add_level('Click', 'arrow_left_click')
        self.arrow_left.add_level('Hold', 'arrow_left_hold')
        self.arrow_left.add_level('Release', 'arrow_left_release')
        self.arrow_left.set_selector_style(
            SelectorSwitch.SELECTOR_TYPE_BUTTONS)

        self.arrow_right = SelectorSwitch(devices, 'arrowR', 'action',
                                          ' (Right Arrow)')
        self.arrow_right.add_level('Off', None)
        self.arrow_right.add_level('Click', 'arrow_right_click')
        self.arrow_right.add_level('Hold', 'arrow_right_hold')
        self.arrow_right.add_level('Release', 'arrow_right_release')
        self.arrow_right.set_selector_style(
            SelectorSwitch.SELECTOR_TYPE_BUTTONS)

        self.brightness_up = SelectorSwitch(devices, 'brUp', 'action',
                                            ' (Brightness Up)')
        self.brightness_up.add_level('Off', None)
        self.brightness_up.add_level('Click', 'brightness_up_click')
        self.brightness_up.add_level('Hold', 'brightness_up_hold')
        self.brightness_up.add_level('Release', 'brightness_up_release')
        self.brightness_up.set_selector_style(
            SelectorSwitch.SELECTOR_TYPE_BUTTONS)

        self.brightness_down = SelectorSwitch(devices, 'brDown', 'action',
                                              ' (Brightness Down)')
        self.brightness_down.add_level('Off', None)
        self.brightness_down.add_level('Click', 'brightness_down_click')
        self.brightness_down.add_level('Hold', 'brightness_down_hold')
        self.brightness_down.add_level('Release', 'brightness_down_release')
        self.brightness_down.set_selector_style(
            SelectorSwitch.SELECTOR_TYPE_BUTTONS)

        self.devices.append(self.switch)
        self.devices.append(self.arrow_left)
        self.devices.append(self.arrow_right)
        self.devices.append(self.brightness_up)
        self.devices.append(self.brightness_down)

    def handleCommand(self, alias, device, device_data, command, level, color):
        if alias == self.switch.alias:
            self.switch.handle_command(device_data, command, level, color)

        if alias == self.arrow_left.alias:
            self.arrow_left.handle_command(device_data, command, level, color)

        if alias == self.arrow_right.alias:
            self.arrow_right.handle_command(device_data, command, level, color)

        if alias == self.brightness_up.alias:
            self.brightness_up.handle_command(device_data, command, level,
                                              color)

        if alias == self.brightness_down.alias:
            self.brightness_down.handle_command(device_data, command, level,
                                                color)

    def handleMqttMessage(self, device_data, message):
        if 'action' not in message.raw:
            return

        converted_message = self.convert_message(message)
        action = message.raw['action']

        if action == 'toggle':
            self.switch.handle_message(device_data, converted_message)

        if action.startswith('brightness_up'):
            self.brightness_up.handle_message(device_data, converted_message)

        if action.startswith('brightness_down'):
            self.brightness_down.handle_message(device_data, converted_message)

        if action.startswith('arrow_right'):
            self.arrow_right.handle_message(device_data, converted_message)

        if action.startswith('arrow_left'):
            self.arrow_left.handle_message(device_data, converted_message)