Set qos and retain for MQTT publishing
This commit is contained in:
parent
99fed12faf
commit
a4098bf50d
4 changed files with 14 additions and 9 deletions
|
@ -4,6 +4,8 @@ mqtt:
|
|||
user: user
|
||||
password: secret
|
||||
topic: "mqtt/topic/for/fronius"
|
||||
qos: 1
|
||||
retain: true
|
||||
fronius:
|
||||
- inverter:
|
||||
host: "inverter.myfroniusfarm"
|
||||
|
|
|
@ -28,16 +28,19 @@ class Config:
|
|||
if "mqtt" in config:
|
||||
self._mqtt = config["mqtt"]
|
||||
if not "host" in self._mqtt:
|
||||
raise ValueError("MQTT host not set")
|
||||
raise ValueError("MQTT host not set")
|
||||
if not "port" in self._mqtt:
|
||||
raise ValueError("MQTT port not set")
|
||||
raise ValueError("MQTT port not set")
|
||||
if not "user" in self._mqtt:
|
||||
raise ValueError("MQTT user not set")
|
||||
raise ValueError("MQTT user not set")
|
||||
if not "password" in self._mqtt:
|
||||
raise ValueError("MQTT password not set")
|
||||
raise ValueError("MQTT password not set")
|
||||
if not "topic" in self._mqtt:
|
||||
raise ValueError("MQTT topic not set")
|
||||
|
||||
raise ValueError("MQTT topic not set")
|
||||
if not "qos" in self._mqtt:
|
||||
self._mqtt["qos"] = 0
|
||||
if not "retain" in self._mqtt:
|
||||
self._mqtt["retain"] = False
|
||||
|
||||
def _parse_fronius(self, config):
|
||||
"""Parse the fronius section of fronius2mqtt.yaml."""
|
||||
|
|
|
@ -18,5 +18,5 @@ class Mqtt:
|
|||
|
||||
def publish(self, topic, payload):
|
||||
topic = "{}/{}".format(self.config['topic'], topic)
|
||||
logging.info("Publish %s: %s", topic, payload)
|
||||
self.client.publish(topic, payload)
|
||||
logging.info("Publish %s: %s, %s, %s", topic, payload, self._config["qos"], self._config["retain"])
|
||||
self._client.publish(topic, payload, self._config["qos"], self._config["retain"])
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
from setuptools import setup
|
||||
|
||||
setup(name='fronius2mqtt',
|
||||
version='0.1',
|
||||
version='0.2',
|
||||
description='Fronius 2 MQTT bridge',
|
||||
url='https://github.com/gbeine/fronius2mqtt',
|
||||
author='Gerrit',
|
||||
|
|
Loading…
Reference in a new issue