def create_button(self, devices, index): button = SelectorSwitch(devices, 'btn' + str(index), 'action', ' (Button ' + str(index) + ')') button.add_level('Off', None) button.add_level('On', 'on') button.add_level('Up', 'up-press') button.add_level('Down', 'down-press') button.add_level('Stop', 'stop') button.set_selector_style(SelectorSwitch.SELECTOR_TYPE_BUTTONS) button.disable_value_check_on_update() return button
def create_button(self, devices, name): action_prefix = name + '_' device = SelectorSwitch(devices, 'btn_' + name[0], 'action_' + name, ' (' + name.capitalize() + ' Button)') device.add_level('Off', None) device.add_level('Click', action_prefix + 'single') device.add_level('Double', action_prefix + 'double') device.add_level('Triple', action_prefix + 'triple') device.add_level('Hold', action_prefix + 'hold') device.add_level('Release', action_prefix + 'release') device.set_selector_style(SelectorSwitch.SELECTOR_TYPE_BUTTONS) device.disable_value_check_on_update() return device
class TradfriRemoteSwitchOnOff(AdapterWithBattery): def __init__(self, devices): super().__init__(devices) self.switch = SelectorSwitch(devices, 'switch', 'click') self.switch.add_level('Off', 'off') self.switch.add_level('On', 'on') self.switch.add_level('Up', 'brightness_up') self.switch.add_level('Down', 'brightness_down') self.switch.add_level('Stop', 'brightness_stop') self.switch.set_selector_style(SelectorSwitch.SELECTOR_TYPE_BUTTONS) self.switch.disable_value_check_on_update() self.devices.append(self.switch) def handleMqttMessage(self, device_data, message): if 'click' not in message.raw: return converted_message = self.convert_message(message) click = message.raw['click'] if click == '': return else: for device in self.devices: device.handle_message(device_data, converted_message) def handleCommand(self, alias, device, device_data, command, level, color): self.switch.handle_command(device_data, command, level, color)
def create_button(self, index): action_prefix = 'button_' + str(index) + '_' button = SelectorSwitch('btn' + str(index), 'action', ' (Button ' + str(index) + ')') button.add_level('Off', None) button.add_level('Click', action_prefix + 'single') button.add_level('Double', action_prefix + 'double') button.add_level('Triple', action_prefix + 'triple') button.add_level('Hold', action_prefix + 'hold') button.add_level('Release', action_prefix + 'release') button.set_selector_style(SelectorSwitch.SELECTOR_TYPE_BUTTONS) button.disable_value_check_on_update() return button
class WXKG03LM(AdapterWithBattery): def init(self, devices): super().__init__(devices) self.switch = SelectorSwitch(devices, 'switch', 'state') self.switch.add_level('Off', None) self.switch.add_level('Click', 'single') self.switch.add_level('Double Click', 'double') self.switch.add_level('Hold', 'hold') self.switch.set_selector_style(SelectorSwitch.SELECTOR_TYPE_MENU) self.switch.disable_value_check_on_update() self.devices.append(self.switch) def convert_message(self, message): message = super().convert_message(message) if 'click' in message.raw: message.raw['state'] = message.raw['click'] elif 'action' in message.raw: message.raw['state'] = message.raw['action'] return message def handleCommand(self, alias, device, device_data, command, level, color): self.switch.handle_command(device_data, command, level, color)
def _add_selector_device(self, alias, feature, device_name_suffix = ''): suffix = device_name_suffix if device_name_suffix != '' else (' (' + feature['name'] + ')') device = SelectorSwitch(domoticz.get_devices(), alias, feature['property'], suffix) device.disable_value_check_on_update() device.add_level('Off', None) for value in feature['values']: device.add_level(value, value) if (len(feature['values']) >= 5): device.set_selector_style(SelectorSwitch.SELECTOR_TYPE_MENU) device.feature = feature self.devices.append(device)
def __init__(self): super().__init__() mode_switch = SelectorSwitch('mode', 'system_mode', ' (Mode)') mode_switch.add_level('Off', 'off') mode_switch.add_level('Auto', 'auto') mode_switch.add_level('Heat', 'heat') mode_switch.set_selector_style(SelectorSwitch.SELECTOR_TYPE_BUTTONS) mode_switch.set_icon(15) self.devices.append( TemperatureSensor('temp', 'local_temperature', ' (Temperature)')) self.devices.append( SetPoint('spoint', 'current_heating_setpoint', ' (Setpoint)')) self.devices.append(mode_switch)
class Zigbee2ButtonWallSwitchBlack(AdapterWithBattery): def __init__(self): super().__init__() self.devices.append(DimmerSwitch('dimmer', 'brightness')) self.switch = SelectorSwitch('switch', 'action') self.switch.add_level('Off', 'off') self.switch.add_level('On', 'on') self.switch.add_level('Up', 'brightness_move_up') self.switch.add_level('Down', 'brightness_move_down') self.switch.add_level('Stop', 'brightness_stop') self.switch.set_selector_style(SelectorSwitch.SELECTOR_TYPE_MENU) self.switch.disable_value_check_on_update() self.devices.append(self.switch)
def __init__(self, devices): super().__init__(devices) temperature_sensor = TemperatureSensor(devices, 'temp', 'local_temperature',' (Temperature)') self.devices.append(temperature_sensor) setpoint = SetPoint(devices, 'sp1', 'occupied_heating_setpoint',' (Occupied Setpoint)') self.devices.append(setpoint) mode_switch = SelectorSwitch(devices, 'mode', 'system_mode', ' (Mode)') mode_switch.add_level('Off', 'idle') mode_switch.add_level('Heat', 'heat') mode_switch.set_selector_style(SelectorSwitch.SELECTOR_TYPE_MENU) mode_switch.set_icon(15) self.devices.append(mode_switch)
def __init__(self): super().__init__() button = SelectorSwitch('click', 'click', ' (State)') button.add_level('Off', 'off') button.add_level('On', 'on') button.add_level('S1', 1) button.add_level('S2', 2) button.add_level('S3', 3) button.add_level('S4', 4) button.add_level('S5', 5) button.add_level('S6', 6) button.disable_value_check_on_update() self.devices.append(button) self.devices.append(DimmerSwitch('light', 'brightness', ' (Brightness)'))
def __init__(self, devices): super().__init__(devices) switch = SelectorSwitch(devices, 'btn', 'action') switch.add_level('Off', None) switch.add_level('Arm Away', 'arm_away') switch.add_level('Arm Stay', 'arm_stay') switch.add_level('Disarm', 'disarm') switch.add_level('Panic', 'panic') self.devices.append(switch)
def __init__(self, devices): super().__init__(devices) selector = SelectorSwitch(devices, 'action', 'action') selector.add_level('Off', None) selector.add_level('Click', 'single') selector.add_level('Hold', 'hold') selector.add_level('Release', 'release') selector.disable_value_check_on_update() self.devices.append(selector)
class HeimanAlarmRemoteAdapter(AdapterWithBattery): def __init__(self, devices): super().__init__(devices) self.switch = SelectorSwitch(devices, 'Remote', 'action') self.switch.add_level('Off', None) self.switch.add_level('Arm all zones', 'arm_all_zones') self.switch.add_level('Arm partial zones', 'arm_partial_zones') self.switch.add_level('Disarm', 'disarm') self.switch.add_level('Emergency', 'emergency') self.switch.set_selector_style(SelectorSwitch.SELECTOR_TYPE_MENU) self.devices.append(self.switch) def convert_message(self, message): message = super().convert_message(message) return message def handleCommand(self, alias, device, device_data, command, level, color): self.switch.handle_command(device_data, command, level, color)
def __init__(self, devices): super().__init__(devices) selector = SelectorSwitch(devices, 'click', 'click') selector.add_level('Off', None) selector.add_level('Left', 'left') selector.add_level('Right', 'right') selector.add_level('Both', 'both') selector.disable_value_check_on_update() self.devices.append(OnOffSwitch(devices, 'left', 'state_left')) self.devices.append(OnOffSwitch(devices, 'right', 'state_right')) self.devices.append(selector)
class GiraLightLink(Adapter): def __init__(self, devices): super().__init__(devices) self.switch = SelectorSwitch(devices, 'switch', 'action') self.switch.add_level('Off', 'off') self.switch.add_level('On', 'on') self.switch.add_level('Up', 'up') self.switch.add_level('Down', 'down') self.switch.add_level('Stop', 'stop') self.switch.add_level('1', 'select_0') self.switch.add_level('2', 'select_1') self.switch.add_level('3', 'select_2') self.switch.add_level('4', 'select_3') self.switch.set_selector_style(SelectorSwitch.SELECTOR_TYPE_MENU) self.switch.disable_value_check_on_update() self.devices.append(self.switch) def handleCommand(self, alias, device, device_data, command, level, color): self.switch.handle_command(device_data, command, level, color)
class DJT11LM(AdapterWithBattery): def __init__(self, devices): super().__init__(devices) self.switch = SelectorSwitch(devices, 'action', 'action') self.switch.add_level('Off', None) self.switch.add_level('Vibration', 'vibration') self.switch.add_level('Drop', 'drop') self.switch.add_level('Tilt', 'tilt') self.switch.set_selector_style(SelectorSwitch.SELECTOR_TYPE_MENU) self.devices.append(self.switch) self.devices.append( CustomSensor(devices, 'stgth', 'strength', ' (Strength)')) self.devices.append( JSONSensor(devices, 'angle', 'angle_raw', ' (Angle)')) def handle_command(self, alias, device, command, level, color): device_data = self._get_legacy_device_data() self.switch.handle_command(device_data, command, level, color) def convert_message(self, message): message = super().convert_message(message) message.raw['angle_raw'] = { 'angle': message.raw['angle'], 'angle_x': message.raw['angle_x'], 'angle_y': message.raw['angle_y'], 'angle_z': message.raw['angle_z'], 'angle_x_absolute': message.raw['angle_x_absolute'], 'angle_y_absolute': message.raw['angle_y_absolute'], } return message
class TradfriRollerBlind(Adapter): def __init__(self, devices): super().__init__(devices) self.switch = SelectorSwitch(devices, 'switch', 'click') self.switch.add_level('Up', 'open') self.switch.add_level('Down', 'close') self.devices.append(self.switch) def handleCommand(self, alias, device, device_data, command, level, color): self.switch.handle_command(device_data, command, level, color) if (command.upper() == "ON"): command = "close" else: command = "open" return { 'topic': device_data['friendly_name'] + '/set', 'payload': json.dumps({"state": command.upper()}) }
class TradfriRemoteCloseOpen(AdapterWithBattery): def __init__(self, devices): super().__init__(devices) self.switch = SelectorSwitch(devices, 'switch', 'click') #self.switch.add_level('On', 'open') #self.switch.add_level('Off', 'close') #self.switch.add_level('None', '') self.switch.add_level('Up', 'open') self.switch.add_level('Down', 'close') self.switch.set_selector_style(SelectorSwitch.SELECTOR_TYPE_BUTTONS) self.devices.append(self.switch) def handleCommand(self, alias, device, device_data, command, level, color): Domoticz.Debug(str(command) + str(level) + str(color)) self.switch.handle_command(device_data, command, level, color) return { 'topic': device_data['friendly_name'] + '/set', 'payload': json.dumps({"state": command.upper()}) }
class KEF1PA(AdapterWithBattery): def __init__(self, devices): super().__init__(devices) self.switch = SelectorSwitch(devices, 'KEF1PA', 'action') self.switch.add_level('Off', None) self.switch.add_level('Panic', 'panic') self.switch.add_level('Home', 'home') self.switch.add_level('Away', 'away') self.switch.add_level('Sleep', 'sleep') self.switch.set_selector_style(SelectorSwitch.SELECTOR_TYPE_MENU) self.devices.append(self.switch) def handleCommand(self, alias, device, device_data, command, level, color): self.switch.handle_command(device_data, command, level, color)
class WXKG02LM(AdapterWithBattery): def __init__(self, devices): super().__init__(devices) self.switch = SelectorSwitch(devices, 'switch', 'click') self.switch.add_level('Off', None) self.switch.add_level('Switch 1', 'left') self.switch.add_level('Switch 2', 'right') self.switch.add_level('Both_Click', 'both') self.switch.set_selector_style(SelectorSwitch.SELECTOR_TYPE_BUTTONS) self.devices.append(self.switch) def handleCommand(self, alias, device, device_data, command, level, color): self.switch.handle_command(device_data, command, level, color)
class SmartLock(Adapter): def __init__(self, devices): super().__init__(devices) self.switch = SelectorSwitch(devices, 'key', 'inserted') self.switch.add_level('Key 1', '01') self.switch.add_level('Key 2', '02') self.switch.add_level('Key 3', '03') self.switch.add_level('Key 4', '04') self.switch.add_level('Key 5', '05') self.switch.add_level('Strange', 'strange') self.switch.add_level('Unknown', 'unknown') self.switch.set_selector_style(SelectorSwitch.SELECTOR_TYPE_MENU) self.devices.append(self.switch) self.devices.append(ContactSensor(devices, 'error', 'keyerror'))
class TS0041(AdapterWithBattery): def __init__(self, devices): super().__init__(devices) self.switch = SelectorSwitch(devices, 'action', 'action') self.switch.add_level('Off', None) self.switch.add_level('Click', 'single') self.switch.add_level('Double Click', 'double') self.switch.add_level('Hold', 'hold') self.switch.disable_value_check_on_update() self.devices.append(self.switch) def handleCommand(self, alias, device, device_data, command, level, color): self.get_device_by_alias(alias).handle_command(device_data, command, level, color)
class TradfriRemoteSwitchOnOff(AdapterWithBattery): def __init__(self, devices): super().__init__(devices) self.switch = SelectorSwitch(devices, 'switch', 'click') self.switch.add_level('Off', 'off') self.switch.add_level('On', 'on') self.switch.add_level('Up', 'brightness_up') self.switch.add_level('Down', 'brightness_down') self.switch.add_level('Stop', 'brightness_stop') self.switch.set_selector_style(SelectorSwitch.SELECTOR_TYPE_BUTTONS) self.devices.append(self.switch) def handleCommand(self, alias, device, device_data, command, level, color): self.switch.handle_command(device_data, command, level, color)
class SNZB01(AdapterWithBattery): def __init__(self, devices): super().__init__(devices) self.switch = SelectorSwitch(devices, 'switch', 'action') self.switch.add_level('Off', None) self.switch.add_level('Click', 'single') self.switch.add_level('Double Click', 'double') self.switch.add_level('Long Press', 'long') self.switch.set_selector_style(SelectorSwitch.SELECTOR_TYPE_BUTTONS) self.switch.disable_value_check_on_update() self.devices.append(self.switch) def handleCommand(self, alias, device, device_data, command, level, color): self.switch.handle_command(device_data, command, level, color)
def __init__(self, devices): super().__init__(devices) self.devices.append(TemperatureSensor(devices, 'temp', 'temperature', 'temperature')) self.devices.append(HumiditySensor(devices, 'hum', 'humidity', ' (Humidity)')) self.devices.append(OnOffSwitch(devices, 'alarm', 'alarm', ' (Alarm)')) volume_switch = SelectorSwitch(devices, 'vol', 'volume', ' (Volume)') volume_switch.add_level('Low', 'low') volume_switch.add_level('Medium', 'medium') volume_switch.add_level('High', 'high') self.devices.append(volume_switch) melody_switch = SelectorSwitch(devices, 'mel', 'melody', ' (Melody)') for melody in range(1, 19): melody_switch.add_level(str(melody), melody) self.devices.append(melody_switch)
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)
def __init__(self): super().__init__() sensitivity_switch = SelectorSwitch('sens', 'sensitivity', ' (Sensivity)') sensitivity_switch.add_level('Low', 'low') sensitivity_switch.add_level('Medium', 'medium') sensitivity_switch.add_level('High', 'high') self.devices.append(SmokeSensor('smoke', 'smoke')) self.devices.append(OnOffSwitch('test', 'test_state', ' (Test)')) self.devices.append(sensitivity_switch) self.devices.append( CustomSensor('dnsty', 'smoke_density', ' (Smoke Density)'))
class SensorVibration(AdapterWithBattery): def __init__(self, devices): super().__init__(devices) self.switch = SelectorSwitch(devices, 'action', 'action') self.switch.add_level('Off', None) self.switch.add_level('Vibration', 'vibration') self.switch.add_level('Drop', 'drop') self.switch.add_level('Tilt', 'tilt') self.switch.set_selector_style(SelectorSwitch.SELECTOR_TYPE_MENU) self.devices.append(self.switch) def handleCommand(self, alias, device, device_data, command, level, color): self.switch.handle_command(device_data, command, level, color)
class WXKG01LM(AdapterWithBattery): def __init__(self, devices): super().__init__(devices) self.switch = SelectorSwitch(devices, 'switch', 'click') self.switch.add_level('Off', None) self.switch.add_level('Click', 'single') self.switch.add_level('Double Click', 'double') self.switch.add_level('Triple Click', 'triple') self.switch.add_level('Quadruple Click', 'quadruple') self.switch.add_level('Many clicks', 'many') self.switch.add_level('Long Click', 'long') self.switch.add_level('Long Click Release', 'long_release') self.switch.set_selector_style(SelectorSwitch.SELECTOR_TYPE_MENU) self.switch.disable_value_check_on_update() self.devices.append(self.switch) def handleCommand(self, alias, device, device_data, command, level, color): self.switch.handle_command(device_data, command, level, color)
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)