Example #1
0
class BitronSirenAdapterWithBattery(AdapterWithBattery):
    def __init__(self, devices):
        super().__init__(devices)
        self.switch = OnOffSwitch(devices, 'switch', 'state')
        self.switch.set_icon(13)
        self.devices.append(self.switch)

    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)

        mode = 'emergency' if command.upper() == 'ON' else 'stop'
        flash = False if command.upper() == 'ON' else True

        return {
            'topic': device_data['friendly_name'] + '/set',
            'payload': json.dumps({
                'warning': {
                    'mode': mode,
					'level': 'high',
                    'strobe': flash,
					'duration': 30
                }
            })
        }
class WeiserLock(Adapter):
    def __init__(self, devices):
        super().__init__(devices)
        self.switch = OnOffSwitch(devices, 'switch', 'state')
        self.devices.append(self.switch)

    def convert_message(self, message):
        message = super().convert_message(message)

        if 'state' in message.raw:
            state = message.raw['state']
            message.raw['state'] = 'ON' if state == 'LOCK' else 'OFF'

        return message

    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)

        return {
            'topic':
            device_data['friendly_name'] + '/set',
            'payload':
            json.dumps(
                {"state": 'LOCK' if command.upper() == 'ON' else 'UNLOCK'})
        }
class OnOffSwitchAdapter(Adapter):
    def __init__(self, devices):
        super().__init__(devices)
        self.switch = OnOffSwitch(devices, 'switch', 'state')
        self.devices.append(self.switch)

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

        return {
            'topic': device_data['friendly_name'] + '/set',
            'payload': json.dumps({"state": command.upper()})
        }
Example #4
0
class SirenAdapter(Adapter):
    def __init__(self, devices):
        super().__init__(devices)
        self.switch = OnOffSwitch(devices, 'switch', 'state')
        self.switch.set_icon(13)
        self.devices.append(self.switch)

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

        mode = 'emergency' if command.upper() == 'ON' else 'stop'

        return {
            'topic': device_data['friendly_name'] + '/set',
            'payload': json.dumps({'warning': {
                'mode': mode,
                'duration': 10
            }})
        }