@homebridge-plugins/homebridge-tado 8.3.0-beta.0 → 8.3.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@homebridge-plugins/homebridge-tado",
3
- "version": "8.3.0-beta.0",
3
+ "version": "8.3.0-beta.1",
4
4
  "description": "Homebridge plugin for controlling tado° devices.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -6,11 +6,15 @@ import { join } from "path";
6
6
  var settingState = false;
7
7
  var delayTimer = {};
8
8
 
9
+ let statesInterval;
10
+ let counterInterval;
11
+
9
12
  const timeout = (ms) => new Promise((res) => setTimeout(res, ms));
10
13
  const aRefreshHistoryHandlers = [];
11
14
 
12
15
  export default (api, accessories, config, tado, telegram) => {
13
16
  const storagePath = api.user.storagePath();
17
+ initTasks();
14
18
 
15
19
  async function setStates(accessory, accs, target, value) {
16
20
  accessories = accs.filter((acc) => acc && acc.context.config.homeName === config.homeName);
@@ -726,8 +730,26 @@ export default (api, accessories, config, tado, telegram) => {
726
730
  }
727
731
  }
728
732
 
733
+ async function logCounter() {
734
+ try {
735
+ const iCounter = (await tado.getCounterData()).counter;
736
+ Logger.info(`Tado API counter: ${iCounter.toLocaleString('en-US')}`);
737
+ } catch (error) {
738
+ Logger.warn(`Failed to get Tado API counter: ${error.message || error}`);
739
+ }
740
+ }
741
+
742
+ function initTasks() {
743
+ if (statesInterval) clearInterval(statesInterval);
744
+ void getStates();
745
+ statesInterval = setInterval(() => getStates(), Math.max(config.polling, 300) * 1000);
746
+
747
+ if (counterInterval) clearInterval(counterInterval);
748
+ void logCounter();
749
+ counterInterval = setInterval(() => logCounter(), 60 * 60 * 1000);
750
+ }
751
+
729
752
  async function getStates() {
730
- let zoneStates = {};
731
753
  try {
732
754
  //ME
733
755
  if (!config.homeId) await updateMe();
@@ -736,7 +758,12 @@ export default (api, accessories, config, tado, telegram) => {
736
758
  if (!config.temperatureUnit) await updateHome();
737
759
 
738
760
  //Zones
739
- if (config.zones.length) zoneStates = await updateZones();
761
+ let zoneStates = {};
762
+ try {
763
+ if (config.zones.length) zoneStates = await updateZones();
764
+ } finally {
765
+ void refreshHistory(config.homeId, zoneStates);
766
+ }
740
767
 
741
768
  //MobileDevices
742
769
  if (config.presence.length) await updateMobileDevices();
@@ -754,24 +781,7 @@ export default (api, accessories, config, tado, telegram) => {
754
781
  if (config.childLock.length) await updateDevices();
755
782
  } catch (err) {
756
783
  errorHandler(err);
757
- } finally {
758
- refreshHistory(config.homeId, zoneStates);
759
- setTimeout(() => {
760
- getStates();
761
- }, Math.max(config.polling, 300) * 1000);
762
784
  }
763
-
764
- //log tado api counter every hour
765
- async function logCounter() {
766
- try {
767
- const iCounter = (await tado.getCounterData()).counter;
768
- Logger.info(`Tado API counter: ${iCounter.toLocaleString('en-US')}`);
769
- } catch (error) {
770
- Logger.warn(`Failed to get Tado API counter: ${error.message || error}`);
771
- }
772
- }
773
- void logCounter();
774
- setInterval(logCounter, 60 * 60 * 1000);
775
785
  }
776
786
 
777
787
  async function updateMe() {
@@ -1276,7 +1286,7 @@ export default (api, accessories, config, tado, telegram) => {
1276
1286
  });
1277
1287
  }
1278
1288
  }
1279
- return zoneStates = {};
1289
+ return zoneStates;
1280
1290
  }
1281
1291
 
1282
1292
  async function updateMobileDevices() {
package/src/platform.js CHANGED
@@ -192,8 +192,7 @@ class TadoPlatform {
192
192
 
193
193
  let accessories = this.accessories.filter((acc) => acc && acc.context.config.homeName === name);
194
194
 
195
- const deviceHandler = DeviceHandler(this.api, accessories, config, tado, this.telegram);
196
- deviceHandler.getStates();
195
+ DeviceHandler(this.api, accessories, config, tado, this.telegram);
197
196
  }
198
197
  }
199
198