Skip to content

Commit

Permalink
refresh interval for thinq 2 device due some AC mqtt not working #231
Browse files Browse the repository at this point in the history
  • Loading branch information
Jin committed May 12, 2023
1 parent 48a305c commit 40c3cd5
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions src/platform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -185,34 +185,15 @@ export class LGThinQHomebridgePlatform implements DynamicPlatformPlugin {
setInterval(() => {
this.ThinQ.devices().then((devices) => {
devices.filter(device => device.platform === PlatformType.ThinQ2).forEach(device => {
// only emit if device online
if (device.snapshot.online) {
this.events.emit('refresh.'+device.id, device.snapshot);
}
this.events.emit(device.id, device.snapshot);
});
});
}, 600000); // every 10 minute

const refreshList = {};

thinq2devices.forEach(accessory => {
const device: Device = accessory.context.device;
refreshList[device.id] = setTimeout(() => {
this.events.once('refresh.'+device.id, (snapshot) => {
this.events.emit(device.id, snapshot);
refreshList[device.id].refresh();
});
}, 300000);
});
}, this.intervalTime); // every interval minute - backup method if mqtt not working

this.log.info('Start MQTT listener for thinq2 device');
await this.ThinQ.registerMQTTListener((data) => {
if ('data' in data && 'deviceId' in data) {
this.events.emit(data.deviceId, data.data?.state?.reported);

if (data.deviceId in refreshList) {
refreshList[data.deviceId].refresh();
}
}
});
}
Expand Down

0 comments on commit 40c3cd5

Please sign in to comment.