Improve tests.

This commit is contained in:
Koenkk authored and Koen Kanters committed 2018-12-06 21:27:41 +01:00
1 parent cb9beaa2ad
commit 698b40554e
6 files changed
+113 -22

No files matched your search

+4 -2
View File
@@ -126,6 +126,8 @@ class Controller {
}
start() {
this.state.start();
this.startupLogVersion(() => {
this.zigbee.start(this.onZigbeeMessage, (error) => {
if (error) {
@@ -142,7 +144,7 @@ class Controller {
this.extensions.filter((e) => e.stop).forEach((e) => e.stop());
// Wrap-up
this.state.save();
this.state.stop();
this.mqtt.disconnect();
this.zigbee.stop(callback);
}
@@ -237,7 +239,7 @@ class Controller {
return {
ieeeAddr,
friendlyName: deviceSettings.friendly_name || '',
friendlyName: deviceSettings ? (deviceSettings.friendly_name || '') : '',
type,
nwkAddr,
manufId,
+17
View File
@@ -8,12 +8,29 @@ class State {
constructor() {
this.state = {};
this.file = data.joinPath('state.json');
this.timer = null;
}
start() {
this._load();
// Save the state on every interval
this.clearTimer();
this.timer = setInterval(() => this.save(), saveInterval);
}
clearTimer() {
if (this.timer) {
clearTimeout(this.timer);
this.timer = null;
}
}
stop() {
this.clearTimer();
this.save();
}
_load() {
if (fs.existsSync(this.file)) {
try {