I'm trying to build a plugin to connect to the MQTT broker in my Dyson PureLink fan. I've got some stand alone Pyhon code to get it working based on the PAHO MQTT client, which has a method
Code: Select all
client.username_pw_set(USERNAME, _hashed_password())
Now when I want to integrate this into a domoticz plugin, I run into an issue. The MQTT broker requires a password on connection. I'm trying to use the built in MQTT connection but that only takes the 'Password' parameter from the plugin as password. And that is not encrypted. I've tried to overwrite the password but that doesn't work:
Code: Select all
def onStart(self):
self.password = self._hashed_password(Parameters['Password'])
Domoticz.Debug("START: self.Password: " + self.password)
Parameters['Password'] = self.password #override the default password with the hased variant
Domoticz.Debug("START: Password field hashed: " + Parameters['Password'])
#create the connection
self.mqttClient = MqttClient(self.ip_address, self.port_number, mqtt_client_id, self.onMQTTConnected, self.onMQTTDisconnected, self.onMQTTPublish, self.onMQTTSubscribed)
def _hashed_password(self, pwd):
"""Hash password (found in manual) to a base64 encoded of its shad512 value"""
hash = hashlib.sha512()
hash.update(pwd.encode('utf-8'))
return base64.b64encode(hash.digest()).decode('utf-8')