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);
|
||||
});
|
||||
|
||||
// Eagerly send discovery as soon as possible
|
||||
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.
|
||||
// Send discovery on MQTT connect to ensure Home Assistant receives device info after reconnects or broker restarts.
|
||||
this.mqttClient.on(MqttClient.EVENTS.connected, () => {
|
||||
try {
|
||||
logger.verbose('connected to mqtt.');
|
||||
|
|
@ -132,6 +124,14 @@ class PlejdAddon extends EventEmitter {
|
|||
|
||||
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
|
||||
this.plejdDeviceCommunication.on(
|
||||
PlejdDeviceCommunication.EVENTS.stateChanged,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue