Discovery (#74)

* add support for Home Assistants MQTT discovery

* add format_topic a flexible separator

* add mqtt discovery for miflora

* add mqtt discovery for mithermometer

* add mqtt discovery for thermostat

* add unit to illuminance in miflora

* switch to 'away_mode_command_topic' instead of 'away_command_topic'

* revert changing the date format

* add mac to ientifiers and change the id generation

* add mac to ientifiers and change the id generation on thermostat

* add mac to ientifiers and change the id generation for mithermometer
This commit is contained in:
Marcel Hoppe
2019-06-21 12:25:27 +02:00
committed by zewelor
parent 01b30f6c4a
commit 8fbf3540bd
8 changed files with 192 additions and 35 deletions
+22 -1
View File
@@ -1,3 +1,5 @@
import json
import paho.mqtt.client as mqtt
import logger
@@ -65,7 +67,6 @@ class MqttClient:
if self.availability_topic:
self.publish([MqttMessage(topic=self.availability_topic, payload=LWT_ONLINE, retain=True)])
def callbacks_subscription(self, callbacks):
self.mqttc.on_connect = self.on_connect
@@ -86,6 +87,7 @@ class MqttClient:
def _format_topic(self, topic):
return "{}/{}".format(self.topic_prefix, topic) if self.topic_prefix else topic
class MqttMessage:
def __init__(self, topic=None, payload=None, retain=False):
self._topic = topic
@@ -120,3 +122,22 @@ class MqttMessage:
def __str__(self):
return self.__repr__()
class MqttConfigMessage(MqttMessage):
SENSOR = 'sensor'
CLIMATE = 'climate'
BINARY_SENSOR = 'binary_sensor'
def __init__(self, component, name, payload=None, retain=False):
if 'name' not in payload: payload['name'] = name
super().__init__("{}/{}/config".format(component, name), json.dumps(payload), retain)
@property
def retain(self):
return self._retain
@retain.setter
def retain(self, new_retain):
self._retain = new_retain