def onMQTTPublish(self, topic, message):
        Domoticz.Debug("MQTT message: " + topic + " " + str(message))

        if (topic == self.base_topic + '/bridge/config/permit_join'
                or topic == self.base_topic + '/bridge/config/devices'):
            return

        if (topic == self.base_topic + '/bridge/config'):
            permit_join = 'enabled' if message['permit_join'] else 'disabled'
            Domoticz.Debug('Zigbee2mqtt log level is ' + message['log_level'])
            Domoticz.Log('Joining new devices is ' + permit_join +
                         ' on the zigbee bridge')
            return

        if (topic == self.base_topic + '/bridge/state'):
            Domoticz.Log('Zigbee2mqtt bridge is ' + message)

            if message == 'online':
                self.mqttClient.publish(
                    self.base_topic + '/bridge/config/devices', '')
                self.handlePairingMode()

            return

        if (topic == self.base_topic + '/bridge/log'):
            if message['type'] == 'devices':
                Domoticz.Log('Received available devices list from bridge')

                self.available_devices.clear()
                self.available_devices.update(Devices, message['message'])

                if self.subscribed_for_devices == False:
                    self.mqttClient.subscribe([self.base_topic + '/+'])
                    self.subscribed_for_devices = True

            if message['type'] == 'device_connected' or message[
                    'type'] == 'device_removed':
                self.mqttClient.publish(
                    self.base_topic + '/bridge/config/devices', '')

            return

        device_name = topic.replace(self.base_topic + "/", "")
        device_data = self.available_devices.get_device_by_name(device_name)

        if (device_data != None):
            model = device_data['model']

            if (model in adapter_by_model):
                zigbee_message = ZigbeeMessage(message)
                adapter = adapter_by_model[model](Devices)
                adapter.handleMqttMessage(device_data, zigbee_message)
            else:
                Domoticz.Debug('Unsupported zigbee device type with model "' +
                               model + '"')
        else:
            Domoticz.Debug('Unhandled message from zigbee2mqtt: ' + topic +
                           ' ' + str(message))
    def handle_mqtt_message(self, group_name, message):
        adapter = self.get_group_by_name(group_name)

        if adapter == None:
            domoticz.debug('Group "' + group_name + '" not found')
            return None

        zigbee_message = ZigbeeMessage(message)
        adapter.handle_mqtt_message(zigbee_message)
Beispiel #3
0
    def handle_mqtt_message(self, device_name, message):
        adapter = self.get_device_by_name(device_name)

        if (adapter == None):
            domoticz.debug(device_name + ': no adapter found to handle MQTT message from device')
            return

        zigbee_message = ZigbeeMessage(message)
        adapter.handle_mqtt_message(zigbee_message)
Beispiel #4
0
    def handle_mqtt_message(self, domoticz_devices, device_name, message):
        device_data = self.get_device_by_name(device_name)

        if (device_data == None):
            return

        model = device_data['model']

        if (model in adapter_by_model):
            zigbee_message = ZigbeeMessage(message)
            adapter = adapter_by_model[model](domoticz_devices)
            adapter.handleMqttMessage(device_data, zigbee_message)
        else:
            Domoticz.Log('This plugin does not support zigbee device with model "' + model + '" yet')
            Domoticz.Log('If you would like plugin to support this device, please create ticket by this link: https://github.com/stas-demydiuk/domoticz-zigbee2mqtt-plugin/issues/new?labels=new+device&template=new-device-support.md')
    def handle_mqtt_message(self, group_name, message):
        group = self.get_group_by_name(group_name)

        if group == None:
            Domoticz.Debug('Group "' + group_name + '" not found')
            return None

        adapter = group['adapter']
        zigbee_message = ZigbeeMessage(message)
        device_data = {
            'ieee_addr': self._get_group_address_by_name(group_name),
            'friendly_name': group_name
        }

        adapter.handleMqttMessage(device_data, zigbee_message)
Beispiel #6
0
    def onMQTTPublish(self, topic, message):
        Domoticz.Debug("MQTT message: " + topic + " " + str(message))

        if (topic == self.base_topic + '/bridge/state'):
            Domoticz.Log('Zigbee2mqtt bridge is ' + message)

            if message == 'online':
                self.mqttClient.Publish(
                    self.base_topic + '/bridge/config/devices', '')
                self.handlePairingMode()

            return

        if (topic == self.base_topic + '/bridge/log'):
            if message['type'] == 'device_removed':
                Domoticz.Debug('Device ' + message['message'] +
                               ' removed from bridge')
                #do we need to handle the situation where the removal is triggered from the bridge?
                #normally the removal is triggered from Domoticz itself (via the OnDeviceRemoved method)

            if message['type'] == 'devices':
                Domoticz.Log('Received available devices list from bridge')

                self.available_devices.update(Devices, message['message'])

                if self.subscribed_for_devices == False:
                    self.mqttClient.Subscribe([self.base_topic + '/+'])
                    self.subscribed_for_devices = True
            return

        device_name = topic.replace(self.base_topic + "/", "")
        device_data = self.available_devices.get_device_by_name(device_name)

        if (device_data != None):
            model = device_data['model']

            if (model in adapter_by_model):
                zigbee_message = ZigbeeMessage(message)
                adapter = adapter_by_model[model](Devices)
                adapter.handleMqttMessage(device_data, zigbee_message)
            else:
                Domoticz.Debug('Unsupported zigbee device type with model "' +
                               model + '"')
        else:
            Domoticz.Debug('Unhandled message from zigbee2mqtt: ' + topic +
                           ' ' + str(message))