Patching startup flow to enable eager discovery to HA
This commit is contained in:
parent
1766afb2e0
commit
32eda83f8f
2 changed files with 10 additions and 10 deletions
|
|
@ -55,15 +55,7 @@ class PlejdAddon extends EventEmitter {
|
||||||
process.on(signal, this.processCleanupFunc);
|
process.on(signal, this.processCleanupFunc);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Eagerly send discovery as soon as possible
|
// Send discovery on MQTT connect to ensure Home Assistant receives device info after reconnects or broker restarts.
|
||||||
try {
|
|
||||||
logger.verbose('Eagerly sending discovery to Home Assistant.');
|
|
||||||
this.mqttClient.sendDiscoveryToHomeAssistant();
|
|
||||||
} catch (err) {
|
|
||||||
logger.error('Error in eager discovery send', err);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send discovery again on MQTT connect to ensure Home Assistant receives device info after reconnects or broker restarts.
|
|
||||||
this.mqttClient.on(MqttClient.EVENTS.connected, () => {
|
this.mqttClient.on(MqttClient.EVENTS.connected, () => {
|
||||||
try {
|
try {
|
||||||
logger.verbose('connected to mqtt.');
|
logger.verbose('connected to mqtt.');
|
||||||
|
|
@ -132,6 +124,14 @@ class PlejdAddon extends EventEmitter {
|
||||||
|
|
||||||
this.mqttClient.init();
|
this.mqttClient.init();
|
||||||
|
|
||||||
|
// Eagerly send discovery after MQTT client is initialized
|
||||||
|
try {
|
||||||
|
logger.verbose('Eagerly sending discovery to Home Assistant.');
|
||||||
|
this.mqttClient.sendDiscoveryToHomeAssistant();
|
||||||
|
} catch (err) {
|
||||||
|
logger.error('Error in eager discovery send', err);
|
||||||
|
}
|
||||||
|
|
||||||
// subscribe to changes from Plejd
|
// subscribe to changes from Plejd
|
||||||
this.plejdDeviceCommunication.on(
|
this.plejdDeviceCommunication.on(
|
||||||
PlejdDeviceCommunication.EVENTS.stateChanged,
|
PlejdDeviceCommunication.EVENTS.stateChanged,
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "Plejd",
|
"name": "Plejd",
|
||||||
"version": "0.17.0",
|
"version": "0.17.1",
|
||||||
"slug": "plejd",
|
"slug": "plejd",
|
||||||
"description": "Adds support for the Swedish home automation devices from Plejd.",
|
"description": "Adds support for the Swedish home automation devices from Plejd.",
|
||||||
"url": "https://github.com/icanos/hassio-plejd/",
|
"url": "https://github.com/icanos/hassio-plejd/",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue