hoffmation-base 3.0.0-alpha.41 → 3.0.0-alpha.43

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.
Files changed (47) hide show
  1. package/lib/index.js +6 -3
  2. package/lib/models/action/batteryLevelChangeAction.d.ts +13 -0
  3. package/lib/models/action/batteryLevelChangeAction.js +14 -0
  4. package/lib/models/action/index.d.ts +1 -0
  5. package/lib/models/action/index.js +3 -1
  6. package/lib/models/command/blockAutomaticUntilCommand.js +1 -1
  7. package/lib/models/command/commandType.d.ts +1 -0
  8. package/lib/models/command/commandType.js +1 -0
  9. package/lib/models/deviceSettings/dachsSettings.d.ts +8 -0
  10. package/lib/models/deviceSettings/dachsSettings.js +10 -1
  11. package/lib/server/devices/baseDeviceInterfaces/iBatteryDevice.d.ts +9 -3
  12. package/lib/server/devices/dachs/dachs.d.ts +6 -2
  13. package/lib/server/devices/dachs/dachs.js +19 -2
  14. package/lib/server/devices/groups/lightGroup.js +2 -3
  15. package/lib/server/devices/groups/presenceGroup.js +14 -10
  16. package/lib/server/devices/hmIPDevices/hmIpGriff.d.ts +9 -0
  17. package/lib/server/devices/hmIPDevices/hmIpGriff.js +21 -0
  18. package/lib/server/devices/hmIPDevices/hmIpHeizung.d.ts +12 -3
  19. package/lib/server/devices/hmIPDevices/hmIpHeizung.js +32 -12
  20. package/lib/server/devices/hmIPDevices/hmIpPraezenz.d.ts +9 -1
  21. package/lib/server/devices/hmIPDevices/hmIpPraezenz.js +20 -0
  22. package/lib/server/devices/hmIPDevices/hmIpTaster.d.ts +13 -4
  23. package/lib/server/devices/hmIPDevices/hmIpTaster.js +28 -8
  24. package/lib/server/devices/hmIPDevices/hmIpTherm.d.ts +10 -1
  25. package/lib/server/devices/hmIPDevices/hmIpTherm.js +25 -5
  26. package/lib/server/devices/shelly/shellyTrv.d.ts +9 -1
  27. package/lib/server/devices/shelly/shellyTrv.js +20 -0
  28. package/lib/server/devices/zigbee/BaseDevices/zigbeeHeater.d.ts +19 -11
  29. package/lib/server/devices/zigbee/BaseDevices/zigbeeHeater.js +47 -27
  30. package/lib/server/devices/zigbee/BaseDevices/zigbeeMagnetContact.d.ts +16 -7
  31. package/lib/server/devices/zigbee/BaseDevices/zigbeeMagnetContact.js +45 -25
  32. package/lib/server/devices/zigbee/BaseDevices/zigbeeMotionSensor.d.ts +9 -1
  33. package/lib/server/devices/zigbee/BaseDevices/zigbeeMotionSensor.js +20 -0
  34. package/lib/server/devices/zigbee/zigbeeAquaraVibra.d.ts +9 -0
  35. package/lib/server/devices/zigbee/zigbeeAquaraVibra.js +20 -0
  36. package/lib/server/devices/zigbee/zigbeeAquaraWater.d.ts +18 -9
  37. package/lib/server/devices/zigbee/zigbeeAquaraWater.js +44 -24
  38. package/lib/server/devices/zigbee/zigbeeHeimanSmoke.d.ts +21 -12
  39. package/lib/server/devices/zigbee/zigbeeHeimanSmoke.js +37 -17
  40. package/lib/server/devices/zigbee/zigbeeSonoffTemp.d.ts +17 -9
  41. package/lib/server/devices/zigbee/zigbeeSonoffTemp.js +30 -10
  42. package/lib/server/services/ac/own-daikin-device.d.ts +8 -0
  43. package/lib/server/services/ac/own-daikin-device.js +8 -0
  44. package/lib/server/services/victron/victron-device.d.ts +15 -4
  45. package/lib/server/services/victron/victron-device.js +54 -12
  46. package/lib/tsconfig.tsbuildinfo +1 -1
  47. package/package.json +1 -1
@@ -20,6 +20,8 @@ class ZigbeeMotionSensor extends index_1.ZigbeeDevice {
20
20
  this._movementDetected = false;
21
21
  this._battery = -99;
22
22
  this._lastBatteryPersist = 0;
23
+ this._lastBatteryLevel = -1;
24
+ this._batteryLevelCallbacks = [];
23
25
  this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.motionSensor);
24
26
  this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.batteryDriven);
25
27
  if (!services_1.Utils.anyDboActive) {
@@ -62,6 +64,10 @@ class ZigbeeMotionSensor extends index_1.ZigbeeDevice {
62
64
  get timeSinceLastMotion() {
63
65
  return this._timeSinceLastMotion;
64
66
  }
67
+ /** @inheritDoc */
68
+ addBatteryLevelCallback(pCallback) {
69
+ this._batteryLevelCallbacks.push(pCallback);
70
+ }
65
71
  /**
66
72
  * Adds a callback for when a motion state has changed.
67
73
  * @param pCallback - Function that accepts the new state as parameter
@@ -112,6 +118,7 @@ class ZigbeeMotionSensor extends index_1.ZigbeeDevice {
112
118
  switch (idSplit[3]) {
113
119
  case 'battery':
114
120
  this._battery = state.val;
121
+ this.checkForBatteryChange();
115
122
  this.persistBatteryDevice();
116
123
  if (this._battery < 20) {
117
124
  this.log(models_1.LogLevel.Warn, 'Das Zigbee Gerät hat unter 20% Batterie.');
@@ -153,5 +160,18 @@ class ZigbeeMotionSensor extends index_1.ZigbeeDevice {
153
160
  this.updateMovement(false);
154
161
  }, 270000, this);
155
162
  }
163
+ /**
164
+ * Checks whether the battery level did change and if so fires the callbacks
165
+ */
166
+ checkForBatteryChange() {
167
+ const newLevel = this.battery;
168
+ if (newLevel == -1 || newLevel == this._lastBatteryLevel) {
169
+ return;
170
+ }
171
+ for (const cb of this._batteryLevelCallbacks) {
172
+ cb(new models_1.BatteryLevelChangeAction(this));
173
+ }
174
+ this._lastBatteryLevel = newLevel;
175
+ }
156
176
  }
157
177
  exports.ZigbeeMotionSensor = ZigbeeMotionSensor;
@@ -1,3 +1,4 @@
1
+ import { BatteryLevelChangeAction } from '../../../models';
1
2
  import { iBatteryDevice, iVibrationSensor } from '../baseDeviceInterfaces';
2
3
  import { ZigbeeDevice } from './BaseDevices';
3
4
  import { IoBrokerDeviceInfo } from '../IoBrokerDeviceInfo';
@@ -43,6 +44,8 @@ export declare class ZigbeeAquaraVibra extends ZigbeeDevice implements iVibratio
43
44
  private _alarmMessage;
44
45
  private _vibrationBlockedByGriff;
45
46
  private _vibrationBlockedByMotion;
47
+ private _lastBatteryLevel;
48
+ private _batteryLevelCallbacks;
46
49
  constructor(pInfo: IoBrokerDeviceInfo);
47
50
  /** @inheritDoc */
48
51
  get vibration(): boolean;
@@ -63,9 +66,15 @@ export declare class ZigbeeAquaraVibra extends ZigbeeDevice implements iVibratio
63
66
  /** @inheritDoc */
64
67
  set vibrationBlockedByMotion(pVal: boolean);
65
68
  /** @inheritDoc */
69
+ addBatteryLevelCallback(pCallback: (action: BatteryLevelChangeAction) => void): void;
70
+ /** @inheritDoc */
66
71
  update(idSplit: string[], state: ioBroker.State, initial?: boolean): void;
67
72
  setSensitivity(pVal: number): void;
68
73
  /** @inheritDoc */
69
74
  persistBatteryDevice(): void;
70
75
  private alarmCheck;
76
+ /**
77
+ * Checks whether the battery level did change and if so fires the callbacks
78
+ */
79
+ private checkForBatteryChange;
71
80
  }
@@ -73,6 +73,8 @@ class ZigbeeAquaraVibra extends BaseDevices_1.ZigbeeDevice {
73
73
  this._idSensitivity = '';
74
74
  this._vibrationBlockedByGriff = false;
75
75
  this._vibrationBlockedByMotion = false;
76
+ this._lastBatteryLevel = -1;
77
+ this._batteryLevelCallbacks = [];
76
78
  this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.batteryDriven);
77
79
  this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.vibrationSensor);
78
80
  this._alarmMessage = services_1.Res.vibrationAlarm(this.info.customName);
@@ -125,12 +127,17 @@ class ZigbeeAquaraVibra extends BaseDevices_1.ZigbeeDevice {
125
127
  this._vibrationBlockedByMotion = pVal;
126
128
  }
127
129
  /** @inheritDoc */
130
+ addBatteryLevelCallback(pCallback) {
131
+ this._batteryLevelCallbacks.push(pCallback);
132
+ }
133
+ /** @inheritDoc */
128
134
  update(idSplit, state, initial = false) {
129
135
  this.log(models_1.LogLevel.DeepTrace, `Stecker Update: ID: ${idSplit.join('.')} JSON: ${JSON.stringify(state)}`);
130
136
  super.update(idSplit, state, initial, true);
131
137
  switch (idSplit[3]) {
132
138
  case 'battery':
133
139
  this._battery = state.val;
140
+ this.checkForBatteryChange();
134
141
  this.persistBatteryDevice();
135
142
  if (this._battery < 20) {
136
143
  this.log(models_1.LogLevel.Warn, 'Das Zigbee Gerät hat unter 20% Batterie.');
@@ -222,5 +229,18 @@ class ZigbeeAquaraVibra extends BaseDevices_1.ZigbeeDevice {
222
229
  services_1.SonosService.speakOnAll(message);
223
230
  this.log(models_1.LogLevel.Alert, message);
224
231
  }
232
+ /**
233
+ * Checks whether the battery level did change and if so fires the callbacks
234
+ */
235
+ checkForBatteryChange() {
236
+ const newLevel = this.battery;
237
+ if (newLevel == -1 || newLevel == this._lastBatteryLevel) {
238
+ return;
239
+ }
240
+ for (const cb of this._batteryLevelCallbacks) {
241
+ cb(new models_1.BatteryLevelChangeAction(this));
242
+ }
243
+ this._lastBatteryLevel = newLevel;
244
+ }
225
245
  }
226
246
  exports.ZigbeeAquaraVibra = ZigbeeAquaraVibra;
@@ -1,14 +1,9 @@
1
1
  /// <reference types="node" />
2
2
  import { ZigbeeDevice } from './BaseDevices';
3
+ import { BatteryLevelChangeAction } from '../../../models';
3
4
  import { IoBrokerDeviceInfo } from '../IoBrokerDeviceInfo';
4
5
  import { iBatteryDevice } from '../baseDeviceInterfaces';
5
6
  export declare class ZigbeeAquaraWater extends ZigbeeDevice implements iBatteryDevice {
6
- private _battery;
7
- private _lastBatteryPersist;
8
- /** @inheritDoc */
9
- get lastBatteryPersist(): number;
10
- /** @inheritDoc */
11
- get battery(): number;
12
7
  /**
13
8
  * Whether water is detected
14
9
  */
@@ -18,19 +13,33 @@ export declare class ZigbeeAquaraWater extends ZigbeeDevice implements iBatteryD
18
13
  * @default undefined (no alarm active)
19
14
  */
20
15
  iAlarmTimeout: NodeJS.Timeout | undefined;
16
+ private _battery;
17
+ private _lastBatteryPersist;
18
+ private _lastBatteryLevel;
19
+ private _batteryLevelCallbacks;
21
20
  private _messageAlarmFirst;
22
21
  private _messageAlarm;
23
22
  private _messageAlarmEnd;
24
23
  private _supressAlarmTimeStamp;
25
- constructor(pInfo: IoBrokerDeviceInfo);
26
24
  private _roomName;
25
+ constructor(pInfo: IoBrokerDeviceInfo);
26
+ /** @inheritDoc */
27
+ get lastBatteryPersist(): number;
28
+ /** @inheritDoc */
29
+ get battery(): number;
30
+ /** @inheritDoc */
31
+ addBatteryLevelCallback(pCallback: (action: BatteryLevelChangeAction) => void): void;
27
32
  /** @inheritDoc */
28
33
  update(idSplit: string[], state: ioBroker.State, initial?: boolean): void;
29
34
  stopAlarm(quiet?: boolean, timeout?: number): void;
30
- private startAlarm;
31
- private alarm;
32
35
  /** @inheritDoc */
33
36
  persistBatteryDevice(): void;
34
37
  /** @inheritDoc */
35
38
  dispose(): void;
39
+ private startAlarm;
40
+ private alarm;
41
+ /**
42
+ * Checks whether the battery level did change and if so fires the callbacks
43
+ */
44
+ private checkForBatteryChange;
36
45
  }
@@ -8,18 +8,8 @@ const models_1 = require("../../../models");
8
8
  const DeviceCapability_1 = require("../DeviceCapability");
9
9
  // TODO: Add iWaterSensor
10
10
  class ZigbeeAquaraWater extends BaseDevices_1.ZigbeeDevice {
11
- /** @inheritDoc */
12
- get lastBatteryPersist() {
13
- return this._lastBatteryPersist;
14
- }
15
- /** @inheritDoc */
16
- get battery() {
17
- return this._battery;
18
- }
19
11
  constructor(pInfo) {
20
12
  super(pInfo, deviceType_1.DeviceType.ZigbeeAquaraWater);
21
- this._battery = -99;
22
- this._lastBatteryPersist = 0;
23
13
  /**
24
14
  * Whether water is detected
25
15
  */
@@ -29,6 +19,10 @@ class ZigbeeAquaraWater extends BaseDevices_1.ZigbeeDevice {
29
19
  * @default undefined (no alarm active)
30
20
  */
31
21
  this.iAlarmTimeout = undefined;
22
+ this._battery = -99;
23
+ this._lastBatteryPersist = 0;
24
+ this._lastBatteryLevel = -1;
25
+ this._batteryLevelCallbacks = [];
32
26
  this._messageAlarmFirst = '';
33
27
  this._messageAlarm = '';
34
28
  this._messageAlarmEnd = '';
@@ -40,12 +34,25 @@ class ZigbeeAquaraWater extends BaseDevices_1.ZigbeeDevice {
40
34
  this._messageAlarmEnd = services_1.Res.waterAlarmEnd(this._roomName);
41
35
  }
42
36
  /** @inheritDoc */
37
+ get lastBatteryPersist() {
38
+ return this._lastBatteryPersist;
39
+ }
40
+ /** @inheritDoc */
41
+ get battery() {
42
+ return this._battery;
43
+ }
44
+ /** @inheritDoc */
45
+ addBatteryLevelCallback(pCallback) {
46
+ this._batteryLevelCallbacks.push(pCallback);
47
+ }
48
+ /** @inheritDoc */
43
49
  update(idSplit, state, initial = false) {
44
50
  this.log(models_1.LogLevel.DeepTrace, `Water Update: ID: ${idSplit.join('.')} JSON: ${JSON.stringify(state)}`);
45
51
  super.update(idSplit, state, initial, true);
46
52
  switch (idSplit[3]) {
47
53
  case 'battery':
48
54
  this._battery = state.val;
55
+ this.checkForBatteryChange();
49
56
  this.persistBatteryDevice();
50
57
  if (this._battery < 20) {
51
58
  this.log(models_1.LogLevel.Warn, 'Das Zigbee Gerät hat unter 20% Batterie.');
@@ -82,6 +89,24 @@ class ZigbeeAquaraWater extends BaseDevices_1.ZigbeeDevice {
82
89
  services_1.SonosService.speakOnAll(message);
83
90
  });
84
91
  }
92
+ /** @inheritDoc */
93
+ persistBatteryDevice() {
94
+ var _a;
95
+ const now = services_1.Utils.nowMS();
96
+ if (this._lastBatteryPersist + 60000 > now) {
97
+ return;
98
+ }
99
+ (_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistBatteryDevice(this);
100
+ this._lastBatteryPersist = now;
101
+ }
102
+ /** @inheritDoc */
103
+ dispose() {
104
+ if (this.iAlarmTimeout) {
105
+ clearInterval(this.iAlarmTimeout);
106
+ this.iAlarmTimeout = undefined;
107
+ }
108
+ super.dispose();
109
+ }
85
110
  startAlarm() {
86
111
  if (services_1.Utils.nowMS() < this._supressAlarmTimeStamp) {
87
112
  this.log(models_1.LogLevel.Warn, 'Would start alarm, but we are supressed.');
@@ -104,23 +129,18 @@ class ZigbeeAquaraWater extends BaseDevices_1.ZigbeeDevice {
104
129
  services_1.SonosService.speakOnAll(message, 80);
105
130
  });
106
131
  }
107
- /** @inheritDoc */
108
- persistBatteryDevice() {
109
- var _a;
110
- const now = services_1.Utils.nowMS();
111
- if (this._lastBatteryPersist + 60000 > now) {
132
+ /**
133
+ * Checks whether the battery level did change and if so fires the callbacks
134
+ */
135
+ checkForBatteryChange() {
136
+ const newLevel = this.battery;
137
+ if (newLevel == -1 || newLevel == this._lastBatteryLevel) {
112
138
  return;
113
139
  }
114
- (_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistBatteryDevice(this);
115
- this._lastBatteryPersist = now;
116
- }
117
- /** @inheritDoc */
118
- dispose() {
119
- if (this.iAlarmTimeout) {
120
- clearInterval(this.iAlarmTimeout);
121
- this.iAlarmTimeout = undefined;
140
+ for (const cb of this._batteryLevelCallbacks) {
141
+ cb(new models_1.BatteryLevelChangeAction(this));
122
142
  }
123
- super.dispose();
143
+ this._lastBatteryLevel = newLevel;
124
144
  }
125
145
  }
126
146
  exports.ZigbeeAquaraWater = ZigbeeAquaraWater;
@@ -1,10 +1,23 @@
1
1
  /// <reference types="node" />
2
2
  import { ZigbeeDevice } from './BaseDevices';
3
+ import { BatteryLevelChangeAction } from '../../../models';
3
4
  import { IoBrokerDeviceInfo } from '../IoBrokerDeviceInfo';
4
5
  import { iBatteryDevice, iSmokeDetectorDevice } from '../baseDeviceInterfaces';
5
6
  export declare class ZigbeeHeimanSmoke extends ZigbeeDevice implements iBatteryDevice, iSmokeDetectorDevice {
7
+ /**
8
+ * The timeout for the alarm to fire again
9
+ * @default undefined (no alarm active)
10
+ */
11
+ iAlarmTimeout: NodeJS.Timeout | undefined;
6
12
  private _battery;
7
13
  private _lastBatteryPersist;
14
+ private _lastBatteryLevel;
15
+ private _batteryLevelCallbacks;
16
+ private _smoke;
17
+ private _messageAlarmFirst;
18
+ private _messageAlarm;
19
+ private _messageAlarmEnd;
20
+ private _roomName;
8
21
  /**
9
22
  * Creates an instance of {@link DeviceType.ZigbeeHeimanSmoke}.
10
23
  * @param pInfo - Device creation information
@@ -14,30 +27,26 @@ export declare class ZigbeeHeimanSmoke extends ZigbeeDevice implements iBatteryD
14
27
  get lastBatteryPersist(): number;
15
28
  /** @inheritDoc */
16
29
  get battery(): number;
17
- private _smoke;
18
- /**
19
- * The timeout for the alarm to fire again
20
- * @default undefined (no alarm active)
21
- */
22
- iAlarmTimeout: NodeJS.Timeout | undefined;
23
- private _messageAlarmFirst;
24
- private _messageAlarm;
25
- private _messageAlarmEnd;
26
30
  /** @inheritDoc */
27
31
  get smoke(): boolean;
28
- private _roomName;
29
32
  /**
30
33
  * The name of the room the device is in (Set during initialization)
31
34
  */
32
35
  set roomName(val: string);
33
36
  /** @inheritDoc */
37
+ addBatteryLevelCallback(pCallback: (action: BatteryLevelChangeAction) => void): void;
38
+ /** @inheritDoc */
34
39
  update(idSplit: string[], state: ioBroker.State, initial?: boolean): void;
35
40
  /** @inheritDoc */
36
41
  stopAlarm(quiet?: boolean): void;
37
- private startAlarm;
38
- private alarm;
39
42
  /** @inheritdoc */
40
43
  persistBatteryDevice(): void;
41
44
  /** @inheritDoc */
42
45
  dispose(): void;
46
+ private startAlarm;
47
+ private alarm;
48
+ /**
49
+ * Checks whether the battery level did change and if so fires the callbacks
50
+ */
51
+ private checkForBatteryChange;
43
52
  }
@@ -13,14 +13,16 @@ class ZigbeeHeimanSmoke extends BaseDevices_1.ZigbeeDevice {
13
13
  */
14
14
  constructor(pInfo) {
15
15
  super(pInfo, deviceType_1.DeviceType.ZigbeeHeimanSmoke);
16
- this._battery = -99;
17
- this._lastBatteryPersist = 0;
18
- this._smoke = false;
19
16
  /**
20
17
  * The timeout for the alarm to fire again
21
18
  * @default undefined (no alarm active)
22
19
  */
23
20
  this.iAlarmTimeout = undefined;
21
+ this._battery = -99;
22
+ this._lastBatteryPersist = 0;
23
+ this._lastBatteryLevel = -1;
24
+ this._batteryLevelCallbacks = [];
25
+ this._smoke = false;
24
26
  this._messageAlarmFirst = '';
25
27
  this._messageAlarm = '';
26
28
  this._messageAlarmEnd = '';
@@ -56,12 +58,17 @@ class ZigbeeHeimanSmoke extends BaseDevices_1.ZigbeeDevice {
56
58
  services_1.PollyService.preloadTTS(this._messageAlarmEnd);
57
59
  }
58
60
  /** @inheritDoc */
61
+ addBatteryLevelCallback(pCallback) {
62
+ this._batteryLevelCallbacks.push(pCallback);
63
+ }
64
+ /** @inheritDoc */
59
65
  update(idSplit, state, initial = false) {
60
66
  this.log(models_1.LogLevel.DeepTrace, `Smoke Update: ID: ${idSplit.join('.')} JSON: ${JSON.stringify(state)}`);
61
67
  super.update(idSplit, state, initial, true);
62
68
  switch (idSplit[3]) {
63
69
  case 'battery':
64
70
  this._battery = state.val;
71
+ this.checkForBatteryChange();
65
72
  this.persistBatteryDevice();
66
73
  if (this._battery < 20) {
67
74
  this.log(models_1.LogLevel.Warn, 'Das Zigbee Gerät hat unter 20% Batterie.');
@@ -96,6 +103,24 @@ class ZigbeeHeimanSmoke extends BaseDevices_1.ZigbeeDevice {
96
103
  services_1.SonosService.speakOnAll(message);
97
104
  });
98
105
  }
106
+ /** @inheritdoc */
107
+ persistBatteryDevice() {
108
+ var _a;
109
+ const now = services_1.Utils.nowMS();
110
+ if (this._lastBatteryPersist + 60000 > now) {
111
+ return;
112
+ }
113
+ (_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistBatteryDevice(this);
114
+ this._lastBatteryPersist = now;
115
+ }
116
+ /** @inheritDoc */
117
+ dispose() {
118
+ if (this.iAlarmTimeout) {
119
+ clearInterval(this.iAlarmTimeout);
120
+ this.iAlarmTimeout = undefined;
121
+ }
122
+ super.dispose();
123
+ }
99
124
  startAlarm() {
100
125
  if (this.iAlarmTimeout !== undefined) {
101
126
  clearInterval(this.iAlarmTimeout);
@@ -118,23 +143,18 @@ class ZigbeeHeimanSmoke extends BaseDevices_1.ZigbeeDevice {
118
143
  services_1.RoomService.setAllShutterOfFloor(new models_1.FloorSetAllShuttersCommand(models_1.CommandSource.Force, 100, undefined, 'Fire alarm'));
119
144
  });
120
145
  }
121
- /** @inheritdoc */
122
- persistBatteryDevice() {
123
- var _a;
124
- const now = services_1.Utils.nowMS();
125
- if (this._lastBatteryPersist + 60000 > now) {
146
+ /**
147
+ * Checks whether the battery level did change and if so fires the callbacks
148
+ */
149
+ checkForBatteryChange() {
150
+ const newLevel = this.battery;
151
+ if (newLevel == -1 || newLevel == this._lastBatteryLevel) {
126
152
  return;
127
153
  }
128
- (_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistBatteryDevice(this);
129
- this._lastBatteryPersist = now;
130
- }
131
- /** @inheritDoc */
132
- dispose() {
133
- if (this.iAlarmTimeout) {
134
- clearInterval(this.iAlarmTimeout);
135
- this.iAlarmTimeout = undefined;
154
+ for (const cb of this._batteryLevelCallbacks) {
155
+ cb(new models_1.BatteryLevelChangeAction(this));
136
156
  }
137
- super.dispose();
157
+ this._lastBatteryLevel = newLevel;
138
158
  }
139
159
  }
140
160
  exports.ZigbeeHeimanSmoke = ZigbeeHeimanSmoke;
@@ -2,23 +2,26 @@
2
2
  import { ZigbeeDevice } from './BaseDevices';
3
3
  import { iBatteryDevice, iHumiditySensor, iTemperatureSensor } from '../baseDeviceInterfaces';
4
4
  import { IoBrokerDeviceInfo } from '../IoBrokerDeviceInfo';
5
- import { HumiditySensorChangeAction, TemperatureSensorChangeAction } from '../../../models';
5
+ import { BatteryLevelChangeAction, HumiditySensorChangeAction, TemperatureSensorChangeAction } from '../../../models';
6
6
  export declare class ZigbeeSonoffTemp extends ZigbeeDevice implements iTemperatureSensor, iHumiditySensor, iBatteryDevice {
7
- private _battery;
8
- private _lastBatteryPersist;
9
- /** @inheritDoc */
10
- get lastBatteryPersist(): number;
11
7
  /** @inheritDoc */
12
8
  readonly persistTemperatureSensorInterval: NodeJS.Timeout;
13
9
  /** @inheritDoc */
14
10
  readonly persistHumiditySensorInterval: NodeJS.Timeout;
15
- /** @inheritDoc */
16
- get battery(): number;
11
+ private _battery;
12
+ private _lastBatteryPersist;
17
13
  private _humidityCallbacks;
18
14
  private _temperaturCallbacks;
19
- constructor(pInfo: IoBrokerDeviceInfo);
20
15
  private _humidity;
21
16
  private _roomTemperature;
17
+ private _temperature;
18
+ private _lastBatteryLevel;
19
+ private _batteryLevelCallbacks;
20
+ constructor(pInfo: IoBrokerDeviceInfo);
21
+ /** @inheritDoc */
22
+ get lastBatteryPersist(): number;
23
+ /** @inheritDoc */
24
+ get battery(): number;
22
25
  /** @inheritDoc */
23
26
  get roomTemperature(): number;
24
27
  /** @inheritDoc */
@@ -30,9 +33,10 @@ export declare class ZigbeeSonoffTemp extends ZigbeeDevice implements iTemperatu
30
33
  get iTemperature(): number;
31
34
  /** @inheritDoc */
32
35
  get sTemperature(): string;
33
- private _temperature;
34
36
  private set temperature(value);
35
37
  /** @inheritDoc */
38
+ addBatteryLevelCallback(pCallback: (action: BatteryLevelChangeAction) => void): void;
39
+ /** @inheritDoc */
36
40
  update(idSplit: string[], state: ioBroker.State, initial?: boolean): void;
37
41
  /** @inheritDoc */
38
42
  addHumidityCallback(pCallback: (action: HumiditySensorChangeAction) => void): void;
@@ -48,4 +52,8 @@ export declare class ZigbeeSonoffTemp extends ZigbeeDevice implements iTemperatu
48
52
  persistBatteryDevice(): void;
49
53
  /** @inheritDoc */
50
54
  dispose(): void;
55
+ /**
56
+ * Checks whether the battery level did change and if so fires the callbacks
57
+ */
58
+ private checkForBatteryChange;
51
59
  }
@@ -8,18 +8,8 @@ const DeviceCapability_1 = require("../DeviceCapability");
8
8
  const models_1 = require("../../../models");
9
9
  const services_1 = require("../../services");
10
10
  class ZigbeeSonoffTemp extends BaseDevices_1.ZigbeeDevice {
11
- /** @inheritDoc */
12
- get lastBatteryPersist() {
13
- return this._lastBatteryPersist;
14
- }
15
- /** @inheritDoc */
16
- get battery() {
17
- return this._battery;
18
- }
19
11
  constructor(pInfo) {
20
12
  super(pInfo, deviceType_1.DeviceType.ZigbeeSonoffTemp);
21
- this._battery = -99;
22
- this._lastBatteryPersist = 0;
23
13
  /** @inheritDoc */
24
14
  this.persistTemperatureSensorInterval = services_1.Utils.guardedInterval(() => {
25
15
  this.persistTemperaturSensor();
@@ -28,16 +18,28 @@ class ZigbeeSonoffTemp extends BaseDevices_1.ZigbeeDevice {
28
18
  this.persistHumiditySensorInterval = services_1.Utils.guardedInterval(() => {
29
19
  this.persistHumiditySensor();
30
20
  }, 5 * 60 * 1000, this, false);
21
+ this._battery = -99;
22
+ this._lastBatteryPersist = 0;
31
23
  this._humidityCallbacks = [];
32
24
  this._temperaturCallbacks = [];
33
25
  this._humidity = baseDeviceInterfaces_1.UNDEFINED_TEMP_VALUE;
34
26
  this._roomTemperature = baseDeviceInterfaces_1.UNDEFINED_TEMP_VALUE;
35
27
  this._temperature = baseDeviceInterfaces_1.UNDEFINED_TEMP_VALUE;
28
+ this._lastBatteryLevel = -1;
29
+ this._batteryLevelCallbacks = [];
36
30
  this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.temperatureSensor);
37
31
  this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.humiditySensor);
38
32
  this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.batteryDriven);
39
33
  }
40
34
  /** @inheritDoc */
35
+ get lastBatteryPersist() {
36
+ return this._lastBatteryPersist;
37
+ }
38
+ /** @inheritDoc */
39
+ get battery() {
40
+ return this._battery;
41
+ }
42
+ /** @inheritDoc */
41
43
  get roomTemperature() {
42
44
  return this._roomTemperature;
43
45
  }
@@ -70,11 +72,16 @@ class ZigbeeSonoffTemp extends BaseDevices_1.ZigbeeDevice {
70
72
  }
71
73
  }
72
74
  /** @inheritDoc */
75
+ addBatteryLevelCallback(pCallback) {
76
+ this._batteryLevelCallbacks.push(pCallback);
77
+ }
78
+ /** @inheritDoc */
73
79
  update(idSplit, state, initial = false) {
74
80
  super.update(idSplit, state, initial, true);
75
81
  switch (idSplit[3]) {
76
82
  case 'battery':
77
83
  this._battery = state.val;
84
+ this.checkForBatteryChange();
78
85
  this.persistBatteryDevice();
79
86
  if (this._battery < 20) {
80
87
  this.log(models_1.LogLevel.Warn, 'Das Zigbee Gerät hat unter 20% Batterie.');
@@ -136,5 +143,18 @@ class ZigbeeSonoffTemp extends BaseDevices_1.ZigbeeDevice {
136
143
  }
137
144
  super.dispose();
138
145
  }
146
+ /**
147
+ * Checks whether the battery level did change and if so fires the callbacks
148
+ */
149
+ checkForBatteryChange() {
150
+ const newLevel = this.battery;
151
+ if (newLevel == -1 || newLevel == this._lastBatteryLevel) {
152
+ return;
153
+ }
154
+ for (const cb of this._batteryLevelCallbacks) {
155
+ cb(new models_1.BatteryLevelChangeAction(this));
156
+ }
157
+ this._lastBatteryLevel = newLevel;
158
+ }
139
159
  }
140
160
  exports.ZigbeeSonoffTemp = ZigbeeSonoffTemp;
@@ -36,6 +36,14 @@ export declare class OwnDaikinDevice extends AcDevice {
36
36
  protected automaticCheck(): void;
37
37
  private setDesiredInfo;
38
38
  private updateInfo;
39
+ /**
40
+ * Handles the situation when the device is unreachable, attempts to reconnect and log the outcome.
41
+ *
42
+ * This function logs a warning message indicating that the device is unreachable,
43
+ * then attempts to reconnect using the `DaikinService.reconnect` method.
44
+ * If the reconnection is successful, it sets the desired information and schedules a timeout of 5000ms.
45
+ * If the reconnection fails, it logs an error message with the reason for the failure.
46
+ */
39
47
  private handleDeviceUnreach;
40
48
  private handleParamNg;
41
49
  /** @inheritDoc */
@@ -161,6 +161,14 @@ class OwnDaikinDevice extends ac_device_1.AcDevice {
161
161
  });
162
162
  });
163
163
  }
164
+ /**
165
+ * Handles the situation when the device is unreachable, attempts to reconnect and log the outcome.
166
+ *
167
+ * This function logs a warning message indicating that the device is unreachable,
168
+ * then attempts to reconnect using the `DaikinService.reconnect` method.
169
+ * If the reconnection is successful, it sets the desired information and schedules a timeout of 5000ms.
170
+ * If the reconnection fails, it logs an error message with the reason for the failure.
171
+ */
164
172
  handleDeviceUnreach() {
165
173
  this.log(models_1.LogLevel.Warn, `Detected EHOSTUNREACH for ${this.name}(${this.ip}), will try reconecting`);
166
174
  daikin_service_1.DaikinService.reconnect(this.name, this.ip, this._mac)
@@ -1,9 +1,8 @@
1
- import { DeviceInfo, DeviceType, iEnergyManager, iExcessEnergyConsumer } from '../../devices';
2
- import { LogLevel, VictronDeviceSettings } from '../../../models';
3
- import { DeviceCapability } from '../../devices/DeviceCapability';
1
+ import { DeviceCapability, DeviceInfo, DeviceType, iBatteryDevice, iEnergyManager, iExcessEnergyConsumer } from '../../devices';
2
+ import { BatteryLevelChangeAction, LogLevel, VictronDeviceSettings } from '../../../models';
4
3
  import { LogDebugType } from '../log-service';
5
4
  import { VictronDeviceData, VictronMqttConnectionOptions, VictronMqttConsumer } from 'victron-mqtt-consumer';
6
- export declare class VictronDevice implements iEnergyManager {
5
+ export declare class VictronDevice implements iEnergyManager, iBatteryDevice {
7
6
  private readonly _victronConsumer;
8
7
  /** @inheritDoc */
9
8
  readonly deviceCapabilities: DeviceCapability[];
@@ -18,9 +17,16 @@ export declare class VictronDevice implements iEnergyManager {
18
17
  private _iDatabaseLoggerInterval;
19
18
  private _lastPersistenceCalculation;
20
19
  private _nextPersistEntry;
20
+ private _lastBatteryPersist;
21
+ private _lastBatteryLevel;
22
+ private _batteryLevelCallbacks;
21
23
  constructor(opts: VictronMqttConnectionOptions);
24
+ /** @inheritDoc */
25
+ get lastBatteryPersist(): number;
22
26
  protected _info: DeviceInfo;
23
27
  get info(): DeviceInfo;
28
+ /** @inheritDoc */
29
+ get battery(): number;
24
30
  get victronConsumer(): VictronMqttConsumer;
25
31
  get data(): VictronDeviceData;
26
32
  private _excessEnergy;
@@ -28,6 +34,8 @@ export declare class VictronDevice implements iEnergyManager {
28
34
  get name(): string;
29
35
  get customName(): string;
30
36
  get id(): string;
37
+ /** @inheritDoc */
38
+ addBatteryLevelCallback(pCallback: (action: BatteryLevelChangeAction) => void): void;
31
39
  addExcessConsumer(device: iExcessEnergyConsumer): void;
32
40
  get injectingWattage(): number;
33
41
  get drawingWattage(): number;
@@ -39,6 +47,8 @@ export declare class VictronDevice implements iEnergyManager {
39
47
  loadDeviceSettings(): void;
40
48
  log(level: LogLevel, message: string, debugType?: LogDebugType): void;
41
49
  persistDeviceInfo(): void;
50
+ /** @inheritDoc */
51
+ persistBatteryDevice(): void;
42
52
  toJSON(): Partial<VictronDevice>;
43
53
  /**
44
54
  * Changes the grid set point of the Victron device, to the desired value.
@@ -50,4 +60,5 @@ export declare class VictronDevice implements iEnergyManager {
50
60
  private turnOffAdditionalConsumer;
51
61
  private persist;
52
62
  private calculatePersistenceValues;
63
+ private checkForBatteryChange;
53
64
  }