Release 5.0.0

This commit is contained in:
tsightler
2022-02-22 11:38:18 -05:00
parent 46d011a101
commit 3e7346f5b8
2 changed files with 25 additions and 19 deletions

View File

@@ -16,7 +16,7 @@ class Mqtt {
debug('Starting connection to MQTT broker...')
this.client = await this.connect()
if (this.client.connected) {
this.connected = true
this.updateMqttState(true)
debug('MQTT connection established, sending config/state information in 5 seconds.')
}
// Monitor configured/default Home Assistant status topic
@@ -51,10 +51,10 @@ class Mqtt {
// On MQTT connect/reconnect send config/state information after delay
this.client.on('connect', async function () {
if (!mqtt.connected) {
mqtt.connected = true
mqtt.updateMqttState(true)
debug('MQTT connection established, processing locations...')
}
mqtt.ring.processLocations(mqtt)
mqtt.ring.processLocations(mqtt.client)
})
this.client.on('reconnect', function () {
@@ -63,12 +63,12 @@ class Mqtt {
} else {
debug('Attempting to reconnect to MQTT broker...')
}
mqtt.connected = false
mqtt.updateMqttState(false)
})
this.client.on('error', function (error) {
debug('Unable to connect to MQTT broker.', error.message)
mqtt.connected = false
mqtt.updateMqttState(false)
})
// Process MQTT messages from subscribed command topics
@@ -83,12 +83,17 @@ class Mqtt {
if (topic === this.config.hass_topic || topic === 'hass/status' || topic === 'hassio/status') {
debug('Home Assistant state topic '+topic+' received message: '+message)
if (message === 'online') {
this.ring.republishDevices()
this.ring.republishDevices(this.client)
}
} else {
this.ring.processDeviceCommand(topic, message)
}
}
updateMqttState(state) {
this.connected = state
this.ring.updateMqttState(state)
}
}
module.exports = new Mqtt()