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
package/lib/index.js CHANGED
@@ -92,9 +92,6 @@ class HoffmationBase {
92
92
  server_1.DaikinService.addOwnDevices(server_1.OwnAcDevices.ownDevices);
93
93
  server_1.DaikinService.initialize();
94
94
  }
95
- if (server_1.SettingsService.settings.dachs !== undefined) {
96
- server_1.Devices.dachs = new dachs_1.Dachs(server_1.SettingsService.settings.dachs);
97
- }
98
95
  server_1.Utils.guardedNewThread(() => {
99
96
  if (server_1.SettingsService.settings.muell) {
100
97
  server_1.ServerLogService.writeLog(models_1.LogLevel.Info, 'Muell settings detected --> initializing');
@@ -117,6 +114,12 @@ class HoffmationBase {
117
114
  server_1.VictronService.initialize(server_1.SettingsService.settings.victron);
118
115
  }
119
116
  });
117
+ server_1.Utils.guardedNewThread(() => {
118
+ if (server_1.SettingsService.settings.dachs !== undefined) {
119
+ server_1.ServerLogService.writeLog(models_1.LogLevel.Info, 'Dachs settings detected --> initializing');
120
+ server_1.Devices.dachs = new dachs_1.Dachs(server_1.SettingsService.settings.dachs);
121
+ }
122
+ });
120
123
  if (server_1.SettingsService.TelegramActive)
121
124
  server_1.TelegramService.publishCommands();
122
125
  server_1.ServerLogService.writeLog(models_1.LogLevel.Info, 'Hoffmation-Base Post ioBrokerInitializations finished');
@@ -0,0 +1,13 @@
1
+ import { BaseAction } from './baseAction';
2
+ import { CommandType } from '../command';
3
+ import { iBatteryDevice } from '../../server';
4
+ export declare class BatteryLevelChangeAction extends BaseAction {
5
+ /** @inheritDoc */
6
+ type: CommandType;
7
+ /**
8
+ * The new level (0 empty, 100 full)
9
+ * @type {number}
10
+ */
11
+ readonly newLevel: number;
12
+ constructor(device: iBatteryDevice);
13
+ }
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BatteryLevelChangeAction = void 0;
4
+ const baseAction_1 = require("./baseAction");
5
+ const command_1 = require("../command");
6
+ class BatteryLevelChangeAction extends baseAction_1.BaseAction {
7
+ constructor(device) {
8
+ super(undefined, `New Battery Level received`);
9
+ /** @inheritDoc */
10
+ this.type = command_1.CommandType.BatteryManagerLevelChangeAction;
11
+ this.newLevel = device.battery;
12
+ }
13
+ }
14
+ exports.BatteryLevelChangeAction = BatteryLevelChangeAction;
@@ -5,3 +5,4 @@ export * from './presenceGroupLastLeftAction';
5
5
  export * from './presenceGroupFirstEnterAction';
6
6
  export * from './shutterPositionChangedAction';
7
7
  export * from './temperatureSensorChangeAction';
8
+ export { BatteryLevelChangeAction } from './batteryLevelChangeAction';
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.BaseAction = void 0;
17
+ exports.BatteryLevelChangeAction = exports.BaseAction = void 0;
18
18
  var baseAction_1 = require("./baseAction");
19
19
  Object.defineProperty(exports, "BaseAction", { enumerable: true, get: function () { return baseAction_1.BaseAction; } });
20
20
  __exportStar(require("./humiditySensorChangeAction"), exports);
@@ -23,3 +23,5 @@ __exportStar(require("./presenceGroupLastLeftAction"), exports);
23
23
  __exportStar(require("./presenceGroupFirstEnterAction"), exports);
24
24
  __exportStar(require("./shutterPositionChangedAction"), exports);
25
25
  __exportStar(require("./temperatureSensorChangeAction"), exports);
26
+ var batteryLevelChangeAction_1 = require("./batteryLevelChangeAction");
27
+ Object.defineProperty(exports, "BatteryLevelChangeAction", { enumerable: true, get: function () { return batteryLevelChangeAction_1.BatteryLevelChangeAction; } });
@@ -26,7 +26,7 @@ class BlockAutomaticUntilCommand extends baseCommand_1.BaseCommand {
26
26
  (_f = revertToAutomaticAtBlockLift !== null && revertToAutomaticAtBlockLift !== void 0 ? revertToAutomaticAtBlockLift : (_e = (_d = server_1.SettingsService.settings) === null || _d === void 0 ? void 0 : _d.blockAutomaticHandlerDefaults) === null || _e === void 0 ? void 0 : _e.revertToAutomaticAtBlockLift) !== null && _f !== void 0 ? _f : true;
27
27
  }
28
28
  get logMessage() {
29
- return `Block automatic until ${this.targetDate.toISOString()}, reason: ${this.reasonTrace}`;
29
+ return `Block automatic until ${this.targetDate.toLocaleString('de-DE')}, reason: ${this.reasonTrace}`;
30
30
  }
31
31
  }
32
32
  exports.BlockAutomaticUntilCommand = BlockAutomaticUntilCommand;
@@ -1,4 +1,5 @@
1
1
  export declare enum CommandType {
2
+ BatteryManagerLevelChangeAction = "BatteryManagerLevelChangeAction",
2
3
  BlockAutomaticLiftBlockCommand = "BlockAutomaticLiftBlockCommand",
3
4
  BlockAutomaticCommand = "BlockAutomaticCommand",
4
5
  BlockAutomaticUntilCommand = "BlockAutomaticUntilCommand",
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommandType = void 0;
4
4
  var CommandType;
5
5
  (function (CommandType) {
6
+ CommandType["BatteryManagerLevelChangeAction"] = "BatteryManagerLevelChangeAction";
6
7
  CommandType["BlockAutomaticLiftBlockCommand"] = "BlockAutomaticLiftBlockCommand";
7
8
  CommandType["BlockAutomaticCommand"] = "BlockAutomaticCommand";
8
9
  CommandType["BlockAutomaticUntilCommand"] = "BlockAutomaticUntilCommand";
@@ -4,6 +4,14 @@ export declare class DachsDeviceSettings extends ActuatorSettings {
4
4
  * The refresh interval in ms to pull the data from the device.
5
5
  */
6
6
  refreshInterval: number;
7
+ /**
8
+ * Defines the battery level at which the dachs should be turned on,
9
+ * to prevent a battery based island-system to be out of power.
10
+ * @default -1 --> No turn on for battery loading
11
+ *
12
+ * Uses {@link iBatteryDevice.addBatteryLevelCallback}
13
+ */
14
+ batteryLevelTurnOnThreshold: number;
7
15
  fromPartialObject(data: Partial<DachsDeviceSettings>): void;
8
16
  protected toJSON(): Partial<DachsDeviceSettings>;
9
17
  }
@@ -10,10 +10,19 @@ class DachsDeviceSettings extends actuatorSettings_1.ActuatorSettings {
10
10
  * The refresh interval in ms to pull the data from the device.
11
11
  */
12
12
  this.refreshInterval = 30000;
13
+ /**
14
+ * Defines the battery level at which the dachs should be turned on,
15
+ * to prevent a battery based island-system to be out of power.
16
+ * @default -1 --> No turn on for battery loading
17
+ *
18
+ * Uses {@link iBatteryDevice.addBatteryLevelCallback}
19
+ */
20
+ this.batteryLevelTurnOnThreshold = -1;
13
21
  }
14
22
  fromPartialObject(data) {
15
- var _a;
23
+ var _a, _b;
16
24
  this.refreshInterval = (_a = data.refreshInterval) !== null && _a !== void 0 ? _a : this.refreshInterval;
25
+ this.batteryLevelTurnOnThreshold = (_b = data.batteryLevelTurnOnThreshold) !== null && _b !== void 0 ? _b : this.batteryLevelTurnOnThreshold;
17
26
  super.fromPartialObject(data);
18
27
  }
19
28
  toJSON() {
@@ -1,21 +1,27 @@
1
- import { iRoomDevice } from './iRoomDevice';
1
+ import { BatteryLevelChangeAction } from '../../../models';
2
+ import { iBaseDevice } from './iBaseDevice';
2
3
  /**
3
4
  * Interface for Battery Devices.
4
5
  * A battery device can be any device that is powered by a battery e.g. a remote, a sensor, etc.
5
6
  *
6
7
  * For devices with {@link DeviceCapability.battery} capability.
7
8
  */
8
- export interface iBatteryDevice extends iRoomDevice {
9
+ export interface iBatteryDevice extends iBaseDevice {
9
10
  /**
10
11
  * The last time the battery was persisted (in milliseconds since 1970)
11
12
  */
12
13
  readonly lastBatteryPersist: number;
13
14
  /**
14
- * The battery status of the device in percentage
15
+ * The battery status of the device in percentage (0 empty - 100 full)
15
16
  */
16
17
  readonly battery: number;
17
18
  /**
18
19
  * Method to persist the battery status of the device to the persistence layer
19
20
  */
20
21
  persistBatteryDevice(): void;
22
+ /**
23
+ * Adds a callback for when the battery-level has Changed.
24
+ * @param pCallback - Function that accepts the new state as parameter
25
+ */
26
+ addBatteryLevelCallback(pCallback: (action: BatteryLevelChangeAction) => void): void;
21
27
  }
@@ -1,6 +1,5 @@
1
- import { DeviceInfo, DeviceType, iActuator, iBaseDevice } from '../../devices';
1
+ import { DeviceCapability, DeviceInfo, DeviceType, iActuator, iBaseDevice } from '../../devices';
2
2
  import { ActuatorSetStateCommand, ActuatorToggleCommand, ActuatorWriteStateToDeviceCommand, LogLevel, RestoreTargetAutomaticValueCommand, RoomBase } from '../../../models';
3
- import { DeviceCapability } from '../DeviceCapability';
4
3
  import { LogDebugType, OwnSonosDevice } from '../../services';
5
4
  import { iDachsSettings } from '../../config/iDachsSettings';
6
5
  import { DachsDeviceSettings } from '../../../models/deviceSettings/dachsSettings';
@@ -66,4 +65,9 @@ export declare class Dachs implements iBaseDevice, iActuator {
66
65
  toggleActuator(c: ActuatorToggleCommand): boolean;
67
66
  /** @inheritDoc */
68
67
  writeActuatorStateToDevice(c: ActuatorWriteStateToDeviceCommand): void;
68
+ /**
69
+ * Reacts on level Changes of a Energymanager with battery
70
+ * @param {BatteryLevelChangeAction} action - The action containing the new level
71
+ */
72
+ private onBatteryLevelChange;
69
73
  }
@@ -6,7 +6,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.Dachs = void 0;
7
7
  const devices_1 = require("../../devices");
8
8
  const models_1 = require("../../../models");
9
- const DeviceCapability_1 = require("../DeviceCapability");
10
9
  const services_1 = require("../../services");
11
10
  const lodash_1 = __importDefault(require("lodash"));
12
11
  const dachsSettings_1 = require("../../../models/deviceSettings/dachsSettings");
@@ -23,6 +22,7 @@ class Dachs {
23
22
  return this._dachsOn;
24
23
  }
25
24
  constructor(options) {
25
+ var _a, _b;
26
26
  /** @inheritDoc */
27
27
  this.settings = new dachsSettings_1.DachsDeviceSettings();
28
28
  /** @inheritDoc */
@@ -36,7 +36,7 @@ class Dachs {
36
36
  this._dachsOn = false;
37
37
  this._tempWarmWater = 0;
38
38
  this._tempHeatStorage = 0;
39
- this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.actuator);
39
+ this.deviceCapabilities.push(devices_1.DeviceCapability.actuator);
40
40
  this._info = new devices_1.DeviceInfo();
41
41
  this._info.fullName = 'Dachs';
42
42
  this._info.customName = `Dachs ${options.roomName}`;
@@ -58,6 +58,10 @@ class Dachs {
58
58
  this.heatStorageTempSensor = new dachsTemperatureSensor_1.DachsTemperatureSensor(this.config.roomName, 'hs', 'Heat Storage Temperature');
59
59
  services_1.Utils.guardedInterval(this.loadData, this.config.refreshInterval, this);
60
60
  this.blockAutomationHandler = new blockAutomaticHandler_1.BlockAutomaticHandler(this.restoreTargetAutomaticValue.bind(this), this.log.bind(this));
61
+ if ((_b = (_a = devices_1.Devices.energymanager) === null || _a === void 0 ? void 0 : _a.deviceCapabilities) === null || _b === void 0 ? void 0 : _b.includes(devices_1.DeviceCapability.batteryDriven)) {
62
+ const energyManager = devices_1.Devices.energymanager;
63
+ energyManager.addBatteryLevelCallback(this.onBatteryLevelChange.bind(this));
64
+ }
61
65
  }
62
66
  /** @inheritDoc */
63
67
  get info() {
@@ -177,5 +181,18 @@ class Dachs {
177
181
  this.log(models_1.LogLevel.Error, `Error while turning on Dachs: ${error}`);
178
182
  });
179
183
  }
184
+ /**
185
+ * Reacts on level Changes of a Energymanager with battery
186
+ * @param {BatteryLevelChangeAction} action - The action containing the new level
187
+ */
188
+ onBatteryLevelChange(action) {
189
+ if (this._dachsOn || this.settings.batteryLevelTurnOnThreshold < action.newLevel) {
190
+ // We are already running, or battery level is high enough.
191
+ return;
192
+ }
193
+ const setStateCommand = new models_1.ActuatorSetStateCommand(action, true, 'Energy Level of battery dropped to critical level', null);
194
+ setStateCommand.overrideCommandSource = models_1.CommandSource.Force;
195
+ this.setActuator(setStateCommand);
196
+ }
180
197
  }
181
198
  exports.Dachs = Dachs;
@@ -58,7 +58,6 @@ class LightGroup extends base_group_1.BaseGroup {
58
58
  });
59
59
  }
60
60
  switchTimeConditional(c) {
61
- const darkOutside = services_1.TimeCallbackService.darkOutsideOrNight(c.time);
62
61
  let resultLampen = false;
63
62
  let resultSteckdosen = false;
64
63
  let activatedGroups = 0;
@@ -80,11 +79,11 @@ class LightGroup extends base_group_1.BaseGroup {
80
79
  if (this.getOutlets().length > 0) {
81
80
  activatedGroups++;
82
81
  this.log(models_1.LogLevel.Trace, `Set outlets time based for time "${models_1.TimeOfDay[c.time]}"`);
83
- resultSteckdosen = darkOutside;
82
+ resultSteckdosen = true;
84
83
  }
85
84
  if (activatedGroups === 0 || this.getRoom().settings.includeLampsInNormalMovementLightning) {
86
85
  this.log(models_1.LogLevel.Trace, `Set Lamps time based for time "${models_1.TimeOfDay[c.time]}"`);
87
- resultLampen = darkOutside;
86
+ resultLampen = true;
88
87
  }
89
88
  if (resultLampen) {
90
89
  this.setAllLampenTimeBased(new models_1.LampSetTimeBasedCommand(c, c.time));
@@ -22,19 +22,21 @@ class PresenceGroup extends base_group_1.BaseGroup {
22
22
  initCallbacks() {
23
23
  this.getMotionDetector().forEach((b) => {
24
24
  b.addMovementCallback((action) => {
25
- if (action.motionDetected) {
26
- this.motionSensorOnAnyMovement(action);
25
+ if (!action.motionDetected && !this.anyPresent()) {
26
+ this.motionSensorOnLastLeft(action);
27
+ return;
27
28
  }
28
- if (action.motionDetected || this.anyPresent()) {
29
- // TODO: Possible Edge Case, if the other motion sensor doesn't fire motion end event this will never be called
29
+ if (!action.motionDetected && this.anyPresent()) {
30
30
  this.resetLastLeftTimeout();
31
+ return;
31
32
  }
32
- else if (!action.motionDetected && !this.anyPresent()) {
33
- this.motionSensorOnLastLeft(action);
34
- }
35
- if (action.motionDetected && this.presentAmount() === 1 && this._lastLeftTimeout === null) {
33
+ // At this Point we can be certain about motion being detected.
34
+ this.log(models_1.LogLevel.Debug, `New Motion detected, present Amount: ${this.presentAmount()}`, services_1.LogDebugType.NewMovementState);
35
+ this.motionSensorOnAnyMovement(action);
36
+ if (this.presentAmount() === 1 && this._lastLeftTimeout === null) {
36
37
  this.fireFistEnterCBs(action);
37
38
  }
39
+ this.resetLastLeftTimeout();
38
40
  });
39
41
  });
40
42
  this.addLastLeftCallback((action) => {
@@ -110,9 +112,11 @@ class PresenceGroup extends base_group_1.BaseGroup {
110
112
  * In case of an existing delayed last left callback timeout, this removes it.
111
113
  */
112
114
  resetLastLeftTimeout() {
113
- if (this._lastLeftTimeout !== null) {
114
- clearTimeout(this._lastLeftTimeout);
115
+ if (this._lastLeftTimeout === null) {
116
+ return;
115
117
  }
118
+ clearTimeout(this._lastLeftTimeout);
119
+ this._lastLeftTimeout = null;
116
120
  }
117
121
  executeLastLeftCbs(action) {
118
122
  for (const cb of this._lastLeftCbs) {
@@ -1,6 +1,7 @@
1
1
  import { iDisposable } from '../../services';
2
2
  import { WindowPosition } from '../models';
3
3
  import { Window } from '../groups';
4
+ import { BatteryLevelChangeAction } from '../../../models';
4
5
  import { IoBrokerBaseDevice } from '../IoBrokerBaseDevice';
5
6
  import { IoBrokerDeviceInfo } from '../IoBrokerDeviceInfo';
6
7
  import { HmIPDevice } from './hmIpDevice';
@@ -22,6 +23,8 @@ export declare class HmIpGriff extends HmIPDevice implements iHandleSensor, iBat
22
23
  private _iOpenTimeout;
23
24
  private _window;
24
25
  private _helpingRoomTemp;
26
+ private _lastBatteryLevel;
27
+ private _batteryLevelCallbacks;
25
28
  /**
26
29
  * Creates an instance of {@link DeviceType.HmIpGriff}.
27
30
  * @param pInfo - Device creation information
@@ -36,6 +39,8 @@ export declare class HmIpGriff extends HmIPDevice implements iHandleSensor, iBat
36
39
  */
37
40
  set window(value: Window);
38
41
  /** @inheritDoc */
42
+ addBatteryLevelCallback(pCallback: (action: BatteryLevelChangeAction) => void): void;
43
+ /** @inheritDoc */
39
44
  addOffenCallback(pCallback: (pValue: boolean) => void): void;
40
45
  /** @inheritDoc */
41
46
  addKippCallback(pCallback: (pValue: boolean) => void): void;
@@ -54,4 +59,8 @@ export declare class HmIpGriff extends HmIPDevice implements iHandleSensor, iBat
54
59
  /** @inheritDoc */
55
60
  toJSON(): Partial<IoBrokerBaseDevice>;
56
61
  private updatePosition;
62
+ /**
63
+ * Checks whether the battery level did change and if so fires the callbacks
64
+ */
65
+ private checkForBatteryChange;
57
66
  }
@@ -33,6 +33,8 @@ class HmIpGriff extends hmIpDevice_1.HmIPDevice {
33
33
  this._offenCallback = [];
34
34
  this._window = undefined;
35
35
  this._helpingRoomTemp = false;
36
+ this._lastBatteryLevel = -1;
37
+ this._batteryLevelCallbacks = [];
36
38
  this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.handleSensor);
37
39
  this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.batteryDriven);
38
40
  }
@@ -51,6 +53,10 @@ class HmIpGriff extends hmIpDevice_1.HmIPDevice {
51
53
  this._window = value;
52
54
  }
53
55
  /** @inheritDoc */
56
+ addBatteryLevelCallback(pCallback) {
57
+ this._batteryLevelCallbacks.push(pCallback);
58
+ }
59
+ /** @inheritDoc */
54
60
  addOffenCallback(pCallback) {
55
61
  this._offenCallback.push(pCallback);
56
62
  }
@@ -71,6 +77,7 @@ class HmIpGriff extends hmIpDevice_1.HmIPDevice {
71
77
  switch (idSplit[4]) {
72
78
  case 'OPERATING_VOLTAGE':
73
79
  this._battery = 100 * ((state.val - 0.9) / 0.6);
80
+ this.checkForBatteryChange();
74
81
  this.persistBatteryDevice();
75
82
  break;
76
83
  }
@@ -82,6 +89,7 @@ class HmIpGriff extends hmIpDevice_1.HmIPDevice {
82
89
  break;
83
90
  case 'OPERATING_VOLTAGE':
84
91
  this._battery = 100 * ((state.val - 0.9) / 0.6);
92
+ this.checkForBatteryChange();
85
93
  this.persistBatteryDevice();
86
94
  break;
87
95
  }
@@ -205,5 +213,18 @@ class HmIpGriff extends hmIpDevice_1.HmIPDevice {
205
213
  }
206
214
  }, 60000, this);
207
215
  }
216
+ /**
217
+ * Checks whether the battery level did change and if so fires the callbacks
218
+ */
219
+ checkForBatteryChange() {
220
+ const newLevel = this.battery;
221
+ if (newLevel == -1 || newLevel == this._lastBatteryLevel) {
222
+ return;
223
+ }
224
+ for (const cb of this._batteryLevelCallbacks) {
225
+ cb(new models_2.BatteryLevelChangeAction(this));
226
+ }
227
+ this._lastBatteryLevel = newLevel;
228
+ }
208
229
  }
209
230
  exports.HmIpGriff = HmIpGriff;
@@ -1,3 +1,4 @@
1
+ import { BatteryLevelChangeAction } from '../../../models';
1
2
  import { HmIPDevice } from './hmIpDevice';
2
3
  import { IoBrokerDeviceInfo } from '../IoBrokerDeviceInfo';
3
4
  import { iBatteryDevice } from '../baseDeviceInterfaces';
@@ -7,15 +8,23 @@ export declare class HmIpHeizung extends HmIPDevice implements iBatteryDevice {
7
8
  private _level;
8
9
  private _adaptionState;
9
10
  private _lastBatteryPersist;
11
+ private _lastBatteryLevel;
12
+ private _batteryLevelCallbacks;
13
+ private _desiredTemperatur;
14
+ constructor(pInfo: IoBrokerDeviceInfo);
10
15
  get lastBatteryPersist(): number;
11
16
  get battery(): number;
12
- constructor(pInfo: IoBrokerDeviceInfo);
13
- private _desiredTemperatur;
14
17
  get desiredTemperatur(): number;
15
18
  get iLevel(): number;
16
19
  get iTemperatur(): number;
17
20
  /** @inheritDoc */
21
+ addBatteryLevelCallback(pCallback: (action: BatteryLevelChangeAction) => void): void;
22
+ /** @inheritDoc */
18
23
  update(idSplit: string[], state: ioBroker.State, initial?: boolean): void;
19
- private updateBaseInformation;
20
24
  persistBatteryDevice(): void;
25
+ private updateBaseInformation;
26
+ /**
27
+ * Checks whether the battery level did change and if so fires the callbacks
28
+ */
29
+ private checkForBatteryChange;
21
30
  }
@@ -19,21 +19,23 @@ var HmIpHeizungAdaptionStates;
19
19
  HmIpHeizungAdaptionStates[HmIpHeizungAdaptionStates["ErrorPosition"] = 8] = "ErrorPosition";
20
20
  })(HmIpHeizungAdaptionStates || (HmIpHeizungAdaptionStates = {}));
21
21
  class HmIpHeizung extends hmIpDevice_1.HmIPDevice {
22
- get lastBatteryPersist() {
23
- return this._lastBatteryPersist;
24
- }
25
- get battery() {
26
- return this._battery;
27
- }
28
22
  constructor(pInfo) {
29
23
  super(pInfo, deviceType_1.DeviceType.HmIpHeizung);
30
24
  this._battery = -99;
31
25
  this._temperatur = 0;
32
26
  this._level = 0;
33
27
  this._lastBatteryPersist = 0;
28
+ this._lastBatteryLevel = -1;
29
+ this._batteryLevelCallbacks = [];
34
30
  this._desiredTemperatur = 0;
35
31
  this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.batteryDriven);
36
32
  }
33
+ get lastBatteryPersist() {
34
+ return this._lastBatteryPersist;
35
+ }
36
+ get battery() {
37
+ return this._battery;
38
+ }
37
39
  get desiredTemperatur() {
38
40
  return this._desiredTemperatur;
39
41
  }
@@ -44,6 +46,10 @@ class HmIpHeizung extends hmIpDevice_1.HmIPDevice {
44
46
  return this._temperatur;
45
47
  }
46
48
  /** @inheritDoc */
49
+ addBatteryLevelCallback(pCallback) {
50
+ this._batteryLevelCallbacks.push(pCallback);
51
+ }
52
+ /** @inheritDoc */
47
53
  update(idSplit, state, initial = false) {
48
54
  this.log(models_1.LogLevel.DeepTrace, `Heizung Update: ID: ${idSplit.join('.')} JSON: ${JSON.stringify(state)}`);
49
55
  super.update(idSplit, state, initial, true);
@@ -52,6 +58,7 @@ class HmIpHeizung extends hmIpDevice_1.HmIPDevice {
52
58
  switch (idSplit[4]) {
53
59
  case 'OPERATING_VOLTAGE':
54
60
  this._battery = 100 * ((state.val - 1.8) / 1.2);
61
+ this.checkForBatteryChange();
55
62
  this.persistBatteryDevice();
56
63
  break;
57
64
  }
@@ -61,6 +68,15 @@ class HmIpHeizung extends hmIpDevice_1.HmIPDevice {
61
68
  break;
62
69
  }
63
70
  }
71
+ persistBatteryDevice() {
72
+ var _a;
73
+ const now = services_1.Utils.nowMS();
74
+ if (this._lastBatteryPersist + 60000 > now) {
75
+ return;
76
+ }
77
+ (_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistBatteryDevice(this);
78
+ this._lastBatteryPersist = now;
79
+ }
64
80
  updateBaseInformation(name, state) {
65
81
  switch (name) {
66
82
  case 'ACTUAL_TEMPERATURE':
@@ -82,14 +98,18 @@ class HmIpHeizung extends hmIpDevice_1.HmIPDevice {
82
98
  break;
83
99
  }
84
100
  }
85
- persistBatteryDevice() {
86
- var _a;
87
- const now = services_1.Utils.nowMS();
88
- if (this._lastBatteryPersist + 60000 > now) {
101
+ /**
102
+ * Checks whether the battery level did change and if so fires the callbacks
103
+ */
104
+ checkForBatteryChange() {
105
+ const newLevel = this.battery;
106
+ if (newLevel == -1 || newLevel == this._lastBatteryLevel) {
89
107
  return;
90
108
  }
91
- (_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistBatteryDevice(this);
92
- this._lastBatteryPersist = now;
109
+ for (const cb of this._batteryLevelCallbacks) {
110
+ cb(new models_1.BatteryLevelChangeAction(this));
111
+ }
112
+ this._lastBatteryLevel = newLevel;
93
113
  }
94
114
  }
95
115
  exports.HmIpHeizung = HmIpHeizung;
@@ -1,5 +1,5 @@
1
1
  import { HmIPDevice } from './hmIpDevice';
2
- import { MotionSensorAction, MotionSensorSettings } from '../../../models';
2
+ import { BatteryLevelChangeAction, MotionSensorAction, MotionSensorSettings } from '../../../models';
3
3
  import { iBatteryDevice, iIlluminationSensor, iMotionSensor } from '../baseDeviceInterfaces';
4
4
  import { IoBrokerDeviceInfo } from '../IoBrokerDeviceInfo';
5
5
  export declare class HmIpPraezenz extends HmIPDevice implements iIlluminationSensor, iBatteryDevice, iMotionSensor {
@@ -16,6 +16,8 @@ export declare class HmIpPraezenz extends HmIPDevice implements iIlluminationSen
16
16
  private _lastMotionTime;
17
17
  private _detectionsToday;
18
18
  private _currentIllumination;
19
+ private _lastBatteryLevel;
20
+ private _batteryLevelCallbacks;
19
21
  constructor(pInfo: IoBrokerDeviceInfo);
20
22
  get lastBatteryPersist(): number;
21
23
  get battery(): number;
@@ -24,10 +26,16 @@ export declare class HmIpPraezenz extends HmIPDevice implements iIlluminationSen
24
26
  set detectionsToday(pVal: number);
25
27
  get currentIllumination(): number;
26
28
  private set currentIllumination(value);
29
+ /** @inheritDoc */
30
+ addBatteryLevelCallback(pCallback: (action: BatteryLevelChangeAction) => void): void;
27
31
  addMovementCallback(pCallback: (action: MotionSensorAction) => void): void;
28
32
  /** @inheritDoc */
29
33
  update(idSplit: string[], state: ioBroker.State, initial?: boolean): void;
30
34
  updatePresence(pVal: boolean): void;
31
35
  persistMotionSensor(): void;
32
36
  persistBatteryDevice(): void;
37
+ /**
38
+ * Checks whether the battery level did change and if so fires the callbacks
39
+ */
40
+ private checkForBatteryChange;
33
41
  }
@@ -22,6 +22,8 @@ class HmIpPraezenz extends hmIpDevice_1.HmIPDevice {
22
22
  this._lastMotionTime = 0;
23
23
  this._detectionsToday = 0;
24
24
  this._currentIllumination = -1;
25
+ this._lastBatteryLevel = -1;
26
+ this._batteryLevelCallbacks = [];
25
27
  this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.illuminationSensor);
26
28
  this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.batteryDriven);
27
29
  this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.motionSensor);
@@ -63,6 +65,10 @@ class HmIpPraezenz extends hmIpDevice_1.HmIPDevice {
63
65
  this._currentIllumination = value;
64
66
  (_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistIlluminationSensor(this);
65
67
  }
68
+ /** @inheritDoc */
69
+ addBatteryLevelCallback(pCallback) {
70
+ this._batteryLevelCallbacks.push(pCallback);
71
+ }
66
72
  addMovementCallback(pCallback) {
67
73
  this._movementDetectedCallback.push(pCallback);
68
74
  }
@@ -75,6 +81,7 @@ class HmIpPraezenz extends hmIpDevice_1.HmIPDevice {
75
81
  switch (idSplit[4]) {
76
82
  case 'OPERATING_VOLTAGE':
77
83
  this._battery = 100 * ((state.val - 1.8) / 1.2);
84
+ this.checkForBatteryChange();
78
85
  this.persistBatteryDevice();
79
86
  break;
80
87
  }
@@ -128,6 +135,19 @@ class HmIpPraezenz extends hmIpDevice_1.HmIPDevice {
128
135
  (_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistBatteryDevice(this);
129
136
  this._lastBatteryPersist = now;
130
137
  }
138
+ /**
139
+ * Checks whether the battery level did change and if so fires the callbacks
140
+ */
141
+ checkForBatteryChange() {
142
+ const newLevel = this.battery;
143
+ if (newLevel == -1 || newLevel == this._lastBatteryLevel) {
144
+ return;
145
+ }
146
+ for (const cb of this._batteryLevelCallbacks) {
147
+ cb(new models_1.BatteryLevelChangeAction(this));
148
+ }
149
+ this._lastBatteryLevel = newLevel;
150
+ }
131
151
  }
132
152
  exports.HmIpPraezenz = HmIpPraezenz;
133
153
  // TODO: Add iPresenceSensor
@@ -1,11 +1,9 @@
1
1
  import { HmIPDevice } from './hmIpDevice';
2
2
  import { iBatteryDevice, iButtonSwitch } from '../baseDeviceInterfaces';
3
3
  import { Button, ButtonPosition, ButtonPressType } from '../button';
4
+ import { BatteryLevelChangeAction } from '../../../models';
4
5
  import { IoBrokerDeviceInfo } from '../IoBrokerDeviceInfo';
5
6
  export declare class HmIpTaster extends HmIPDevice implements iButtonSwitch, iBatteryDevice {
6
- private _battery;
7
- private _lastBatteryPersist;
8
- get lastBatteryPersist(): number;
9
7
  private static readonly BUTTON_CAPABILLITIES;
10
8
  /** @inheritDoc */
11
9
  buttonTopLeft: Button;
@@ -29,12 +27,23 @@ export declare class HmIpTaster extends HmIPDevice implements iButtonSwitch, iBa
29
27
  * @inheritDoc
30
28
  */
31
29
  buttonTop: undefined;
32
- get battery(): number;
30
+ private _battery;
31
+ private _lastBatteryPersist;
32
+ private _lastBatteryLevel;
33
+ private _batteryLevelCallbacks;
33
34
  constructor(pInfo: IoBrokerDeviceInfo);
35
+ get lastBatteryPersist(): number;
36
+ get battery(): number;
37
+ /** @inheritDoc */
38
+ addBatteryLevelCallback(pCallback: (action: BatteryLevelChangeAction) => void): void;
34
39
  persist(buttonName: string, pressType: ButtonPressType): void;
35
40
  /** @inheritDoc */
36
41
  update(idSplit: string[], state: ioBroker.State, initial?: boolean): void;
37
42
  getButtonAssignment(): string;
38
43
  persistBatteryDevice(): void;
39
44
  pressButton(position: ButtonPosition, pressType: ButtonPressType): Error | null;
45
+ /**
46
+ * Checks whether the battery level did change and if so fires the callbacks
47
+ */
48
+ private checkForBatteryChange;
40
49
  }