homebridge-smartsystem 7.0.1 → 7.0.3
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/duotecno/types.ts +4 -0
- package/package.json +1 -1
- package/server/smartapp.js +15 -0
- package/server/smartapp.ts +19 -1
package/duotecno/types.ts
CHANGED
|
@@ -251,6 +251,10 @@ export interface Switch extends UnitDef {
|
|
|
251
251
|
value?: number | boolean | string;
|
|
252
252
|
nomacro: string;
|
|
253
253
|
nostop: string;
|
|
254
|
+
|
|
255
|
+
// Track last sent status to prevent duplicate action to be triggered
|
|
256
|
+
lastSentStatus?: number | boolean;
|
|
257
|
+
lastSentValue?: number | boolean | string;
|
|
254
258
|
}
|
|
255
259
|
|
|
256
260
|
export const kEmptySwitch: Switch = {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "homebridge-smartsystem",
|
|
3
3
|
"displayname": "Duotecno Bridge",
|
|
4
|
-
"version": "7.0.
|
|
4
|
+
"version": "7.0.3",
|
|
5
5
|
"description": "SmartServer (Proxy TCP sockets to the cloud, Smappee MQTT, Duotecno IP Nodes, Homekit interface)",
|
|
6
6
|
"main": "index.js",
|
|
7
7
|
"author": "Johan Coppieters",
|
package/server/smartapp.js
CHANGED
|
@@ -1125,6 +1125,18 @@ class SmartApp extends webapp_1.WebApp {
|
|
|
1125
1125
|
(0, logger_1.err)("smartapp", "Don't have unit for switch: " + swtch.unitname);
|
|
1126
1126
|
}
|
|
1127
1127
|
else {
|
|
1128
|
+
// Check if state has actually changed (to prevent duplicate notifications/actions)
|
|
1129
|
+
// Exception: Moods should always execute even if state hasn't changed (they are actions, not states)
|
|
1130
|
+
const currentStatus = !!swtch.unit.status;
|
|
1131
|
+
const currentValue = +swtch.unit.value;
|
|
1132
|
+
const isMood = (swtch.unit.type === types_1.UnitType.kMood);
|
|
1133
|
+
if (!isMood &&
|
|
1134
|
+
swtch.lastSentStatus === currentStatus &&
|
|
1135
|
+
swtch.lastSentValue === currentValue) {
|
|
1136
|
+
(0, logger_1.debug)("smartapp", "Switch state unchanged (status=" + currentStatus + ", value=" + currentValue + "), skipping action for " + swtch.name);
|
|
1137
|
+
return;
|
|
1138
|
+
}
|
|
1139
|
+
// Dispatch to appropriate handler
|
|
1128
1140
|
if ((swtch.type === types_1.SwitchType.kSmappee) && (this.power.smappee)) {
|
|
1129
1141
|
this.power.smappee.setPlug(parseInt(swtch.plug), swtch.unit.value);
|
|
1130
1142
|
}
|
|
@@ -1152,6 +1164,9 @@ class SmartApp extends webapp_1.WebApp {
|
|
|
1152
1164
|
else {
|
|
1153
1165
|
(0, logger_1.err)("smartapp", "Don't know how to set a switch of type " + swtch.type);
|
|
1154
1166
|
}
|
|
1167
|
+
// Remember the state we just sent (for all switch types, including moods)
|
|
1168
|
+
swtch.lastSentStatus = currentStatus;
|
|
1169
|
+
swtch.lastSentValue = currentValue;
|
|
1155
1170
|
}
|
|
1156
1171
|
}
|
|
1157
1172
|
///////////
|
package/server/smartapp.ts
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
// v2.0: mar/apr 2020
|
|
10
10
|
|
|
11
11
|
import { Context, HttpResponse, WebApp } from "./webapp";
|
|
12
|
-
import { Sanitizers, Rule, kEmptyRule, actionValue, Action, kEmptySwitch, Switch, SwitchType, hex, Binding, NetworkConfig, SettingsConfig, kEmptySettings, Link, LinkType, kEmptyLink, Device, kEmptyDevice, PowerSource } from "../duotecno/types";
|
|
12
|
+
import { Sanitizers, Rule, kEmptyRule, actionValue, Action, kEmptySwitch, Switch, SwitchType, hex, Binding, NetworkConfig, SettingsConfig, kEmptySettings, Link, LinkType, kEmptyLink, Device, kEmptyDevice, PowerSource, UnitType } from "../duotecno/types";
|
|
13
13
|
import { log, debug, err } from "../duotecno/logger";
|
|
14
14
|
import { System } from "../duotecno/system";
|
|
15
15
|
import { Node, Unit } from "../duotecno/protocol";
|
|
@@ -1237,6 +1237,20 @@ export class SmartApp extends WebApp {
|
|
|
1237
1237
|
err("smartapp", "Don't have unit for switch: "+swtch.unitname);
|
|
1238
1238
|
|
|
1239
1239
|
} else {
|
|
1240
|
+
// Check if state has actually changed (to prevent duplicate notifications/actions)
|
|
1241
|
+
// Exception: Moods should always execute even if state hasn't changed (they are actions, not states)
|
|
1242
|
+
const currentStatus = !!swtch.unit.status;
|
|
1243
|
+
const currentValue = +swtch.unit.value;
|
|
1244
|
+
const isMood = (swtch.unit.type === UnitType.kMood);
|
|
1245
|
+
|
|
1246
|
+
if (!isMood &&
|
|
1247
|
+
swtch.lastSentStatus === currentStatus &&
|
|
1248
|
+
swtch.lastSentValue === currentValue) {
|
|
1249
|
+
debug("smartapp", "Switch state unchanged (status=" + currentStatus + ", value=" + currentValue + "), skipping action for " + swtch.name);
|
|
1250
|
+
return;
|
|
1251
|
+
}
|
|
1252
|
+
|
|
1253
|
+
// Dispatch to appropriate handler
|
|
1240
1254
|
if ((swtch.type === SwitchType.kSmappee) && (this.power.smappee)) {
|
|
1241
1255
|
this.power.smappee.setPlug(parseInt(swtch.plug), swtch.unit.value);
|
|
1242
1256
|
|
|
@@ -1264,6 +1278,10 @@ export class SmartApp extends WebApp {
|
|
|
1264
1278
|
} else {
|
|
1265
1279
|
err("smartapp", "Don't know how to set a switch of type " + swtch.type);
|
|
1266
1280
|
}
|
|
1281
|
+
|
|
1282
|
+
// Remember the state we just sent (for all switch types, including moods)
|
|
1283
|
+
swtch.lastSentStatus = currentStatus;
|
|
1284
|
+
swtch.lastSentValue = currentValue;
|
|
1267
1285
|
}
|
|
1268
1286
|
}
|
|
1269
1287
|
|