Skip to content

Commit

Permalink
Merge pull request #37 from albertomontesg/patch-2
Browse files Browse the repository at this point in the history
Update retain configuration for HomeAssistant discovery messages.
  • Loading branch information
gaetancollaud authored Jan 21, 2023
2 parents 1904f40 + 15cd6c2 commit d96b767
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
2 changes: 1 addition & 1 deletion digitalstrom_mqtt/mqtt.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func (dm *DigitalstromMqtt) ListenForCircuitValues(changes chan digitalstrom.Cir
func (dm *DigitalstromMqtt) publishServerStatus(message string) {
topic := dm.getStatusTopic()
log.Info().Str("status", message).Str("topic", topic).Msg("Updating server status topic")
dm.client.Publish(topic, 0, dm.config.Retain, message)
dm.client.Publish(topic, 0, true, message)
}

func (dm *DigitalstromMqtt) publishSceneEvent(sceneEvent digitalstrom.SceneEvent) {
Expand Down
8 changes: 2 additions & 6 deletions digitalstrom_mqtt/mqtt_homeassistant.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ func (hass *HomeAssistantMqtt) publishDiscoveryMessages() {
messages, err := hass.deviceToHomeAssistantDiscoveryMessage(device)
if utils.CheckNoErrorAndPrint(err) {
for _, discovery_message := range messages {
hass.mqtt.client.Publish(discovery_message.topic, 0, hass.config.Retain, discovery_message.message)
hass.mqtt.client.Publish(discovery_message.topic, 0, true, discovery_message.message)
}
}
}
for _, circuit := range hass.mqtt.digitalstrom.GetAllCircuits() {
messages, err := hass.circuitToHomeAssistantDiscoveryMessage(circuit)
if utils.CheckNoErrorAndPrint(err) {
for _, discovery_message := range messages {
hass.mqtt.client.Publish(discovery_message.topic, 0, hass.config.Retain, discovery_message.message)
hass.mqtt.client.Publish(discovery_message.topic, 0, true, discovery_message.message)
}
}
}
Expand Down Expand Up @@ -100,7 +100,6 @@ func (hass *HomeAssistantMqtt) deviceToHomeAssistantDiscoveryMessage(device digi
device.Name,
hass.config.RemoveRegexpFromName),
"unique_id": device.Dsid + "_" + nodeId,
"retain": hass.config.Retain,
"availability": availability,
"availability_mode": "all",
"command_topic": hass.mqtt.getTopic(
Expand Down Expand Up @@ -169,7 +168,6 @@ func (hass *HomeAssistantMqtt) deviceToHomeAssistantDiscoveryMessage(device digi
hass.config.RemoveRegexpFromName),
"unique_id": device.Dsid + "_" + nodeId,
"device_class": "blind",
"retain": hass.config.Retain,
"availability": availability,
"availability_mode": "all",
"state_topic": hass.mqtt.getTopic(
Expand Down Expand Up @@ -262,7 +260,6 @@ func (hass *HomeAssistantMqtt) circuitToHomeAssistantDiscoveryMessage(circuit di
"device": deviceConfig,
"name": "Power " + circuit.Name,
"unique_id": circuit.Dsid + "_" + powerNodeId,
"retain": hass.config.Retain,
"availability": availability,
"availability_mode": "all",
"state_topic": hass.mqtt.getTopic(
Expand All @@ -287,7 +284,6 @@ func (hass *HomeAssistantMqtt) circuitToHomeAssistantDiscoveryMessage(circuit di
"device": deviceConfig,
"name": "Energy " + circuit.Name,
"unique_id": circuit.Dsid + "_" + energyNodeId,
"retain": hass.config.Retain,
"availability": availability,
"availability_mode": "all",
"state_topic": hass.mqtt.getTopic(
Expand Down

0 comments on commit d96b767

Please sign in to comment.