Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

discovery fixes #15

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
48 changes: 0 additions & 48 deletions .github/workflows/dev.yml

This file was deleted.

10 changes: 6 additions & 4 deletions src/Diematic32MQTT.py
Expand Up @@ -9,6 +9,10 @@
import json
import time,datetime


ONLINE = 'Online'
OFFLINE = 'Offline'

class MessageBuffer:
def __init__(self,mqtt):
#logger
Expand Down Expand Up @@ -50,7 +54,7 @@ def intValue(parameter):
return (f"{parameter:d}" if parameter is not None else '');

#boiler
buffer.update('status','Online' if self.availability else 'Offline');
buffer.update('status',ONLINE if self.availability else OFFLINE);
buffer.update('date',self.datetime.isoformat() if self.datetime is not None else '');
buffer.update('lastTimeSync',self.lastTimeSync.isoformat() if self.lastTimeSync is not None else '');
buffer.update('type',intValue(self.type));
Expand Down Expand Up @@ -143,8 +147,6 @@ def haSendDiscoveryMessages(client, userdata, message):
hassio.addNumber('zone_B_temp_night',"Température Nuit Zone B",'zoneB/nightTemp','zoneB/nightTemp/set',5,30,0.5,"°C");
hassio.addNumber('zone_B_temp_antiice',"Température Antigel Zone B",'zoneB/antiiceTemp','zoneB/antiiceTemp/set',5,20,0.5,"°C");




def on_connect(client, userdata, flags, rc):
logger.critical('Connected to MQTT broker');
Expand Down Expand Up @@ -326,7 +328,7 @@ def sigterm_exit(signum, frame):
#create HomeAssistant discovery instance

hassio=Hassio.Hassio(client,mqttTopicPrefix,mqttClientId,hassioDiscoveryPrefix);
hassio.availabilityInfo('status','Online','Offline');
hassio.availabilityInfo('status',ONLINE,OFFLINE);

#create mqtt message buffer
buffer=MessageBuffer(client);
Expand Down
14 changes: 11 additions & 3 deletions src/Hassio.py
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

import logging,json

#This class allow to interface with Home Assistant through the MQTT Discovery Protocol
class Hassio:

Expand All @@ -17,6 +17,11 @@ def __init__(self,mqttClient,topicRoot,clientId,discovery_prefix):
self.topicRoot=topicRoot;
self.clientId=clientId;
self.discovery_prefix=discovery_prefix;
self.device = {
"identifiers": [clientId],
"manufacturer": "Dietrich",
"name": clientId
}

def availabilityInfo(self,shortTopic,payload_available,payload_not_available):
#availability info saving
Expand All @@ -42,6 +47,7 @@ def addSensor(self,object_id,name,deviceClass,shortStateTopic,valueTemplate,unit
payload["payload_not_available"]=self.payload_not_available;
if (unit_of_measurement is not None):
payload["unit_of_measurement"]=unit_of_measurement;
payload['device'] = self.device
#send discovery message
self.mqtt.publish(discoveryTopic,json.dumps(payload),1,False);

Expand All @@ -61,6 +67,7 @@ def addBinarySensor(self,object_id,name,deviceClass,shortStateTopic,payload_on,p
payload["payload_available"]=self.payload_available;
payload["payload_not_available"]=self.payload_not_available;
payload["enabled_by_default"]=False;
payload['device'] = self.device
#send discovery message
self.mqtt.publish(discoveryTopic,json.dumps(payload),1,False);

Expand All @@ -82,6 +89,7 @@ def addNumber(self,object_id,name,shortStateTopic,shortCommandTopic,min,max,step
payload["step"]=step;
if (unit_of_measurement is not None):
payload["unit_of_measurement"]=unit_of_measurement;
payload['device'] = self.device
#send discovery message
self.mqtt.publish(discoveryTopic,json.dumps(payload),1,False);

Expand All @@ -99,7 +107,7 @@ def addSelect(self,object_id,name,shortStateTopic,shortCommandTopic,options):
payload["payload_not_available"]=self.payload_not_available;
payload["qos"]=2;
payload["options"]=options;

payload['device'] = self.device
#send discovery message
self.mqtt.publish(discoveryTopic,json.dumps(payload),1,False);

Expand All @@ -119,7 +127,7 @@ def addSwitch(self,object_id,name,shortStateTopic,shortCommandTopic,payload_off,
payload["payload_off"]=payload_off;
payload["payload_on"]=payload_on;
payload["qos"]=2;

payload['device'] = self.device
#send discovery message
self.mqtt.publish(discoveryTopic,json.dumps(payload),1,False);