コード例 #1
0
    def onDisconnect(self, Connection):
        if (self._connection != Connection):
            return

        Domoticz.Debug("MqttClient::onDisonnect")
        Domoticz.Error("Disconnected from MQTT Server: {}:{}".format(
            Connection.Address, Connection.Port)
        )

        self.close()

        if self.on_mqtt_disconnected_cb != None:
            self.on_mqtt_disconnected_cb()
コード例 #2
0
    def onConnect(self, Connection, Status, Description):
        if (self._connection != Connection):
            return

        if (Status == 0):
            Domoticz.Log("Connected to MQTT Server: {}:{}".format(
                Connection.Address, Connection.Port)
            )
            Domoticz.Debug("MQTT CLIENT ID: '" + self.client_id + "'")
            self._connection.Send({'Verb': 'CONNECT', 'ID': self.client_id})
        else:
            Domoticz.Error("Failed to connect to: {}:{}, Description: {}".format(
                Connection.Address, Connection.Port, Description)
            )
コード例 #3
0
    def __str__(self):
        Domoticz.Debug("MqttClient::__str__")

        if (self._connection != None):
            return str(self._connection)
        else:
            return "None"
コード例 #4
0
    def _open(self):
        Domoticz.Debug("MqttClient::open")

        if (self._connection != None):
            self.close()

        self.isConnected = False

        self._connection = Domoticz.Connection(
            Name=self.address,
            Transport="TCP/IP",
            Protocol="MQTTS" if self.port == "8883" else "MQTT",
            Address=self.address,
            Port=self.port
        )

        self._connection.Connect()
コード例 #5
0
    def close(self):
        Domoticz.Debug("MqttClient::close")

        if self._connection != None and self._connection.Connected():
            self._connection.Send({ 'Verb' : 'DISCONNECT' })
            self._connection.Disconnect()

        self._connection = None
        self.isConnected = False
コード例 #6
0
 def subscribe(self, topics):
     Domoticz.Debug("MqttClient::subscribe")
     subscriptionlist = []
     for topic in topics:
         subscriptionlist.append({'Topic': topic, 'QoS': 0})
     
     if (self._connection == None or not self.isConnected):
         self._open()
     else:
         self._connection.Send({'Verb': 'SUBSCRIBE', 'Topics': subscriptionlist})
コード例 #7
0
    def publish(self, topic, payload, retain=0):
        Domoticz.Debug("MqttClient::publish " + topic + " (" + payload + ")")

        if (self._connection == None or not self.isConnected):
            self._open()
        else:
            self._connection.Send({
                'Verb': 'PUBLISH',
                'Topic': topic,
                'Payload': bytearray(payload, 'utf-8'),
                'Retain': retain
            })
コード例 #8
0
    def __init__(self, address, port, client_id, on_mqtt_connected_cb, on_mqtt_disconnected_cb, on_mqtt_message_cb, on_mqtt_subscribed_cb):
        Domoticz.Debug("MqttClient::__init__")

        self.address = address
        self.port = port
        self.client_id = client_id if client_id != "" else self._generate_mqtt_client_id()
        self.on_mqtt_connected_cb = on_mqtt_connected_cb
        self.on_mqtt_disconnected_cb = on_mqtt_disconnected_cb
        self.on_mqtt_subscribed_cb = on_mqtt_subscribed_cb
        self.on_mqtt_message_cb = on_mqtt_message_cb

        self._open()
コード例 #9
0
    def onStart(self):
        self.debugging = Parameters["Mode6"]

        if self.debugging == "Verbose":
            Domoticz.Debugging(2 + 4 + 8 + 16 + 64)
        if self.debugging == "Debug":
            Domoticz.Debugging(2)

        self.install()
        self.base_topic = Parameters["Mode1"].strip()

        mqtt_server_address = Parameters["Address"].strip()
        mqtt_server_port = Parameters["Port"].strip()
        mqtt_client_id = Parameters["Mode3"].strip()
        self.mqttClient = MqttClient(mqtt_server_address, mqtt_server_port,
                                     mqtt_client_id, self.onMQTTConnected,
                                     self.onMQTTDisconnected,
                                     self.onMQTTPublish, self.onMQTTSubscribed)

        self.api = API(self.onApiCommand)
        self.devices_manager = DevicesManager()
        self.groups_manager = GroupsManager()
コード例 #10
0
 def onHeartbeat(self):
     if self._connection is None or (not self._connection.Connecting() and not self._connection.Connected() or not self.isConnected):
         Domoticz.Debug("MqttClient::Reconnecting")
         self._open()
     else:
         self.ping()
コード例 #11
0
def error(message):
    return Domoticz.Error(message)
コード例 #12
0
def log(message):
    return Domoticz.Log(message)
コード例 #13
0
def set_configuration(value):
    return Domoticz.Configuration(value)
コード例 #14
0
def get_configuration():
    return Domoticz.Configuration()
コード例 #15
0
def create_device(**kwargs):
    device = Domoticz.Unit(**kwargs)
    device.Create()
    return device
コード例 #16
0
def debug(message):
    return Domoticz.Debug(message)