hoffmation-base 3.1.4 → 3.2.1-alpha.0

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 (82) hide show
  1. package/lib/action/baseAction.d.ts +1 -0
  2. package/lib/action/baseAction.js +3 -0
  3. package/lib/command/ShutterSetLevelCommand.d.ts +2 -1
  4. package/lib/command/WindowRestoreDesiredPositionCommand.d.ts +2 -1
  5. package/lib/command/WindowSetDesiredPositionCommand.d.ts +2 -1
  6. package/lib/command/WindowSetRolloByWeatherStatusCommand.d.ts +2 -1
  7. package/lib/command/actuatorSetStateCommand.d.ts +2 -1
  8. package/lib/command/actuatorToggleCommand.d.ts +2 -1
  9. package/lib/command/actuatorWriteStateToDeviceCommand.d.ts +2 -1
  10. package/lib/command/baseCommand.d.ts +10 -3
  11. package/lib/command/baseCommand.js +20 -1
  12. package/lib/command/blockAutomaticCommand.d.ts +2 -1
  13. package/lib/command/blockAutomaticLiftBlockCommand.d.ts +2 -1
  14. package/lib/command/blockAutomaticUntilCommand.d.ts +2 -1
  15. package/lib/command/dimmerSetLightCommand.d.ts +2 -2
  16. package/lib/command/floorSetAllShuttersCommand.d.ts +2 -1
  17. package/lib/command/iBaseCommand.d.ts +58 -0
  18. package/lib/command/iBaseCommand.js +2 -0
  19. package/lib/command/index.d.ts +1 -0
  20. package/lib/command/lampSetLightCommand.d.ts +2 -2
  21. package/lib/command/lampSetTimeBasedCommand.d.ts +2 -1
  22. package/lib/command/lampToggleLightCommand.d.ts +2 -2
  23. package/lib/command/ledSetLightCommand.d.ts +2 -2
  24. package/lib/command/lightGroupSwitchTimeConditionalCommand.d.ts +2 -1
  25. package/lib/command/restoreTargetAutomaticValueCommand.d.ts +2 -1
  26. package/lib/command/roomRestoreLightCommand.d.ts +2 -1
  27. package/lib/command/roomRestoreShutterPositionCommand.d.ts +2 -1
  28. package/lib/command/roomSetLightTimeBasedCommand.d.ts +2 -1
  29. package/lib/command/shutterSunriseUpCommand.d.ts +2 -1
  30. package/lib/command/shutterSunsetDownCommand.d.ts +2 -1
  31. package/lib/command/wledSetLightCommand.d.ts +2 -2
  32. package/lib/command/wledSetLightCommand.js +1 -1
  33. package/lib/devices/BaseDevice.d.ts +43 -0
  34. package/lib/devices/BaseDevice.js +92 -0
  35. package/lib/devices/CameraDevice.d.ts +6 -15
  36. package/lib/devices/CameraDevice.js +33 -51
  37. package/lib/devices/IoBrokerBaseDevice.d.ts +6 -34
  38. package/lib/devices/IoBrokerBaseDevice.js +5 -68
  39. package/lib/devices/RoomBaseDevice.d.ts +9 -0
  40. package/lib/devices/RoomBaseDevice.js +21 -0
  41. package/lib/devices/dachs/dachs.d.ts +4 -17
  42. package/lib/devices/dachs/dachs.js +12 -43
  43. package/lib/devices/dachs/dachsTemperatureSensor.d.ts +4 -19
  44. package/lib/devices/dachs/dachsTemperatureSensor.js +11 -37
  45. package/lib/devices/espresense/detectedBluetoothDevice.d.ts +5 -11
  46. package/lib/devices/espresense/detectedBluetoothDevice.js +15 -17
  47. package/lib/devices/espresense/espresenseDevice.d.ts +3 -19
  48. package/lib/devices/espresense/espresenseDevice.js +11 -45
  49. package/lib/devices/govee/own-govee-device.d.ts +5 -18
  50. package/lib/devices/govee/own-govee-device.js +30 -69
  51. package/lib/devices/groups/heatGroup.js +1 -1
  52. package/lib/devices/groups/lightGroup.js +1 -1
  53. package/lib/devices/hmIPDevices/hmIpLampe.js +1 -1
  54. package/lib/devices/hmIPDevices/hmIpRoll.js +2 -2
  55. package/lib/devices/index.d.ts +1 -0
  56. package/lib/devices/index.js +3 -1
  57. package/lib/devices/scene/room-scene.d.ts +2 -23
  58. package/lib/devices/scene/room-scene.js +12 -57
  59. package/lib/devices/sharedFunctions/lampUtils.js +4 -3
  60. package/lib/devices/shelly/shellyActuator.js +1 -1
  61. package/lib/devices/tv/tvDevice.d.ts +4 -16
  62. package/lib/devices/tv/tvDevice.js +12 -36
  63. package/lib/devices/velux/veluxShutter.js +1 -1
  64. package/lib/devices/victron/victron-device.d.ts +2 -15
  65. package/lib/devices/victron/victron-device.js +11 -43
  66. package/lib/devices/wledDevice.js +2 -2
  67. package/lib/devices/zigbee/BaseDevices/ZigbeeActuator.js +1 -1
  68. package/lib/devices/zigbee/BaseDevices/zigbeeShutter.d.ts +0 -3
  69. package/lib/devices/zigbee/BaseDevices/zigbeeShutter.js +4 -11
  70. package/lib/index.d.ts +2 -2
  71. package/lib/index.js +2 -2
  72. package/lib/interfaces/baseDevices/iAcDevice.d.ts +4 -0
  73. package/lib/interfaces/baseDevices/iBaseDevice.d.ts +11 -1
  74. package/lib/services/Sonos/own-sonos-device.d.ts +4 -14
  75. package/lib/services/Sonos/own-sonos-device.js +8 -46
  76. package/lib/services/ac/ac-device.d.ts +6 -22
  77. package/lib/services/ac/ac-device.js +23 -53
  78. package/lib/services/ac/own-daikin-device.js +2 -2
  79. package/lib/tsconfig.tsbuildinfo +1 -1
  80. package/lib/utils/utils.d.ts +2 -1
  81. package/lib/utils/utils.js +15 -2
  82. package/package.json +1 -1
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.BaseDevice = void 0;
4
+ const enums_1 = require("../enums");
5
+ const utils_1 = require("../utils");
6
+ const logging_1 = require("../logging");
7
+ const services_1 = require("../services");
8
+ class BaseDevice {
9
+ constructor(_info, deviceType) {
10
+ this._info = _info;
11
+ this.deviceType = deviceType;
12
+ /** @inheritDoc */
13
+ this.jsonOmitKeys = [];
14
+ /** @inheritDoc */
15
+ this.deviceCapabilities = [];
16
+ /**
17
+ * @inheritDoc
18
+ * @default undefined (no Settings)
19
+ */
20
+ this.settings = undefined;
21
+ /**
22
+ * The last actions this device performed
23
+ */
24
+ this.lastCommands = new utils_1.RingStorage(10);
25
+ this._lastWrite = 0;
26
+ utils_1.Utils.guardedTimeout(this.loadDeviceSettings, 300, this);
27
+ this.persistDeviceInfo();
28
+ }
29
+ /**
30
+ * Getter info
31
+ * @returns The device info
32
+ */
33
+ get info() {
34
+ return this._info;
35
+ }
36
+ /** @inheritDoc */
37
+ get customName() {
38
+ return this.info.customName;
39
+ }
40
+ /** @inheritDoc */
41
+ get id() {
42
+ const result = utils_1.Utils.guard(this.info.allDevicesKey);
43
+ if (result === '0' || result === '1') {
44
+ logging_1.ServerLogService.writeLog(enums_1.LogLevel.Warn, `Device "${this.info.fullName}" has an akward allDevicesKey of "${result}"`);
45
+ }
46
+ return result;
47
+ }
48
+ get dbo() {
49
+ return services_1.Persistence.dbo;
50
+ }
51
+ get anyDboActive() {
52
+ return services_1.Persistence.anyDboActive;
53
+ }
54
+ /** @inheritDoc */
55
+ loadDeviceSettings() {
56
+ utils_1.Utils.retryAction(() => {
57
+ var _a;
58
+ if (this.settings === undefined || services_1.Persistence.dbo === undefined) {
59
+ return false;
60
+ }
61
+ (_a = this.settings) === null || _a === void 0 ? void 0 : _a.initializeFromDb(this);
62
+ return true;
63
+ }, this);
64
+ }
65
+ log(level, message, logDebugType = enums_1.LogDebugType.None) {
66
+ logging_1.ServerLogService.writeLog(level, message, {
67
+ room: this.info.room,
68
+ deviceId: this.id,
69
+ deviceName: this.info.customName,
70
+ debugType: logDebugType,
71
+ });
72
+ }
73
+ logCommand(c, ignoreReason, logDebugType, level = enums_1.LogLevel.Info) {
74
+ if (ignoreReason) {
75
+ c.ignoreReason = ignoreReason;
76
+ }
77
+ this.lastCommands.add(c);
78
+ this.log(level, c.logMessage, logDebugType);
79
+ }
80
+ /** @inheritDoc */
81
+ persistDeviceInfo() {
82
+ utils_1.Utils.guardedTimeout(() => {
83
+ var _a;
84
+ (_a = services_1.Persistence.dbo) === null || _a === void 0 ? void 0 : _a.addDevice(this);
85
+ }, 5000, this);
86
+ }
87
+ /** @inheritDoc */
88
+ toJSON() {
89
+ return utils_1.Utils.jsonFilter(this, this.jsonOmitKeys);
90
+ }
91
+ }
92
+ exports.BaseDevice = BaseDevice;
@@ -1,14 +1,11 @@
1
- import { iBaseDevice, iCameraDevice, iCameraSettings, iDeviceInfo, iRoomBase, iRoomDevice } from '../interfaces';
2
- import { DeviceCapability, DeviceType, LogDebugType, LogLevel } from '../enums';
1
+ import { iBaseDevice, iCameraDevice, iCameraSettings, iRoomDevice } from '../interfaces';
2
+ import { LogDebugType, LogLevel } from '../enums';
3
3
  import { MotionSensorAction } from '../action';
4
4
  import { DeviceInfo } from './DeviceInfo';
5
- export declare abstract class CameraDevice implements iCameraDevice {
5
+ import { RoomBaseDevice } from './RoomBaseDevice';
6
+ export declare abstract class CameraDevice extends RoomBaseDevice implements iCameraDevice {
6
7
  /** @inheritDoc */
7
8
  settings: iCameraSettings;
8
- /** @inheritDoc */
9
- readonly deviceCapabilities: DeviceCapability[];
10
- /** @inheritDoc */
11
- deviceType: DeviceType;
12
9
  /**
13
10
  * The human readable name of this device
14
11
  */
@@ -31,13 +28,13 @@ export declare abstract class CameraDevice implements iCameraDevice {
31
28
  protected _dogDetected: boolean;
32
29
  protected _devicesBlockingAlarmMap: Map<string, iBaseDevice>;
33
30
  protected _movementDetected: boolean;
34
- protected _info: iDeviceInfo;
35
31
  private _personDetectFallbackTimeout;
36
32
  private _movementDetectFallbackTimeout;
37
33
  private _dogDetectFallbackTimeout;
38
34
  protected _lastUpdate: Date;
39
35
  get lastUpdate(): Date;
40
36
  protected constructor(name: string, roomName: string);
37
+ toJSON(): Partial<iRoomDevice>;
41
38
  /** @inheritDoc */
42
39
  get lastImage(): string;
43
40
  /** @inheritDoc */
@@ -53,21 +50,15 @@ export declare abstract class CameraDevice implements iCameraDevice {
53
50
  /** @inheritDoc */
54
51
  get timeSinceLastMotion(): number;
55
52
  /** @inheritDoc */
56
- get customName(): string;
57
- /** @inheritDoc */
58
53
  get id(): string;
59
54
  /** @inheritDoc */
60
- get room(): iRoomBase | undefined;
61
- /** @inheritDoc */
62
55
  addMovementCallback(pCallback: (action: MotionSensorAction) => void): void;
63
56
  /** @inheritDoc */
64
57
  blockForDevice(device: iBaseDevice, block: boolean): void;
65
58
  /** @inheritDoc */
66
59
  persistMotionSensor(): void;
67
60
  log(level: LogLevel, message: string, debugType?: LogDebugType): void;
68
- toJSON(): Partial<iRoomDevice>;
69
- persistDeviceInfo(): void;
70
- loadDeviceSettings(): void;
61
+ private initializeMovementCounter;
71
62
  protected onNewMotionDetectedValue(newValue: boolean): void;
72
63
  protected onNewPersonDetectedValue(newValue: boolean): void;
73
64
  protected onNewImageSnapshot(image: string): void;
@@ -13,21 +13,23 @@ const DeviceInfo_1 = require("./DeviceInfo");
13
13
  const devices_1 = require("./devices");
14
14
  const services_1 = require("../services");
15
15
  const utils_1 = require("../utils");
16
- const api_1 = require("../api");
17
16
  const logging_1 = require("../logging");
18
- class CameraDevice {
17
+ const RoomBaseDevice_1 = require("./RoomBaseDevice");
18
+ class CameraDevice extends RoomBaseDevice_1.RoomBaseDevice {
19
19
  get lastUpdate() {
20
20
  return this._lastUpdate;
21
21
  }
22
22
  constructor(name, roomName) {
23
- var _a;
23
+ const info = new DeviceInfo_1.DeviceInfo();
24
+ info.fullName = `Camera ${roomName} ${name}`;
25
+ info.customName = `Camera ${name}`;
26
+ info.room = roomName;
27
+ const allDevicesKey = `camera-${roomName}-${name}`;
28
+ info.allDevicesKey = allDevicesKey;
29
+ super(info, enums_1.DeviceType.Camera);
24
30
  /** @inheritDoc */
25
31
  this.settings = new settingsObjects_1.CameraSettings();
26
32
  /** @inheritDoc */
27
- this.deviceCapabilities = [enums_1.DeviceCapability.camera, enums_1.DeviceCapability.motionSensor];
28
- /** @inheritDoc */
29
- this.deviceType = enums_1.DeviceType.Camera;
30
- /** @inheritDoc */
31
33
  this.detectionsToday = 0;
32
34
  this._lastMotion = 0;
33
35
  this._initialized = false;
@@ -41,29 +43,17 @@ class CameraDevice {
41
43
  this._movementDetectFallbackTimeout = null;
42
44
  this._dogDetectFallbackTimeout = null;
43
45
  this._lastUpdate = new Date(0);
46
+ this.deviceCapabilities.push(enums_1.DeviceCapability.camera);
47
+ this.deviceCapabilities.push(enums_1.DeviceCapability.motionSensor);
44
48
  this.name = name;
45
- this._info = new DeviceInfo_1.DeviceInfo();
46
- this._info.fullName = `Camera ${roomName} ${name}`;
47
- this._info.customName = `Camera ${name}`;
48
- this._info.room = roomName;
49
- this._info.allDevicesKey = `camera-${roomName}-${name}`;
50
- devices_1.Devices.alLDevices[this._info.allDevicesKey] = this;
51
- this.persistDeviceInfo();
52
- this.loadDeviceSettings();
53
- if (!services_1.Persistence.anyDboActive) {
54
- this._initialized = true;
55
- }
56
- else {
57
- (_a = services_1.Persistence.dbo) === null || _a === void 0 ? void 0 : _a.motionSensorTodayCount(this).then((todayCount) => {
58
- var _a;
59
- this.detectionsToday = (_a = todayCount.count) !== null && _a !== void 0 ? _a : 0;
60
- this.log(enums_1.LogLevel.Debug, `Reinitialized movement counter with ${this.detectionsToday}`);
61
- this._initialized = true;
62
- }).catch((err) => {
63
- var _a;
64
- this.log(enums_1.LogLevel.Warn, `Failed to initialize movement counter, err ${(_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : err}`);
65
- });
66
- }
49
+ devices_1.Devices.alLDevices[allDevicesKey] = this;
50
+ utils_1.Utils.guardedTimeout(this.initializeMovementCounter, 4000, this);
51
+ }
52
+ toJSON() {
53
+ return utils_1.Utils.jsonFilter(lodash_1.default.omit(super.toJSON(), [
54
+ // To reduce Byte-size on cyclic update
55
+ '_lastImage',
56
+ ]));
67
57
  }
68
58
  /** @inheritDoc */
69
59
  get lastImage() {
@@ -94,19 +84,11 @@ class CameraDevice {
94
84
  return Math.round((utils_1.Utils.nowMS() - this._lastMotion) / 1000);
95
85
  }
96
86
  /** @inheritDoc */
97
- get customName() {
98
- return this.info.customName;
99
- }
100
- /** @inheritDoc */
101
87
  get id() {
102
88
  var _a;
103
89
  return (_a = this.info.allDevicesKey) !== null && _a !== void 0 ? _a : `camera-${this.info.room}-${this.info.customName}`;
104
90
  }
105
91
  /** @inheritDoc */
106
- get room() {
107
- return api_1.API.getRoom(this.info.room);
108
- }
109
- /** @inheritDoc */
110
92
  addMovementCallback(pCallback) {
111
93
  this._movementDetectedCallback.push(pCallback);
112
94
  }
@@ -134,21 +116,21 @@ class CameraDevice {
134
116
  deviceName: this.name,
135
117
  });
136
118
  }
137
- toJSON() {
138
- return utils_1.Utils.jsonFilter(lodash_1.default.omit(this, [
139
- // To reduce Byte-size on cyclic update
140
- '_lastImage',
141
- ]));
142
- }
143
- persistDeviceInfo() {
144
- utils_1.Utils.guardedTimeout(() => {
145
- var _a;
146
- (_a = services_1.Persistence.dbo) === null || _a === void 0 ? void 0 : _a.addDevice(this);
147
- }, 5000, this);
148
- }
149
- loadDeviceSettings() {
119
+ initializeMovementCounter() {
150
120
  var _a;
151
- (_a = this.settings) === null || _a === void 0 ? void 0 : _a.initializeFromDb(this);
121
+ if (!services_1.Persistence.anyDboActive) {
122
+ this._initialized = true;
123
+ return;
124
+ }
125
+ (_a = services_1.Persistence.dbo) === null || _a === void 0 ? void 0 : _a.motionSensorTodayCount(this).then((todayCount) => {
126
+ var _a;
127
+ this.detectionsToday = (_a = todayCount.count) !== null && _a !== void 0 ? _a : 0;
128
+ this.log(enums_1.LogLevel.Debug, `Reinitialized movement counter with ${this.detectionsToday}`);
129
+ this._initialized = true;
130
+ }).catch((err) => {
131
+ var _a;
132
+ this.log(enums_1.LogLevel.Warn, `Failed to initialize movement counter, err ${(_a = err === null || err === void 0 ? void 0 : err.message) !== null && _a !== void 0 ? _a : err}`);
133
+ });
152
134
  }
153
135
  onNewMotionDetectedValue(newValue) {
154
136
  if (this.settings.movementDetectionOnPersonOnly) {
@@ -1,49 +1,26 @@
1
- import { iIoBrokerBaseDevice, iIOBrokerConnection, iJsonOmitKeys, iPersist, iRoomBase, iRoomDeviceAddingSettings } from '../interfaces';
2
- import { DeviceSettings } from '../settingsObjects';
3
- import { DeviceCapability, DeviceType, LogDebugType, LogLevel } from '../enums';
1
+ import { iIoBrokerBaseDevice, iIOBrokerConnection, iIoBrokerDeviceInfo, iJsonOmitKeys, iRoomDeviceAddingSettings } from '../interfaces';
2
+ import { DeviceType } from '../enums';
4
3
  import { IoBrokerDeviceInfo } from './IoBrokerDeviceInfo';
5
- export declare abstract class IoBrokerBaseDevice implements iJsonOmitKeys, iIoBrokerBaseDevice {
6
- protected _info: IoBrokerDeviceInfo;
7
- deviceType: DeviceType;
8
- /** @inheritDoc */
9
- readonly jsonOmitKeys: string[];
4
+ import { RoomBaseDevice } from './RoomBaseDevice';
5
+ export declare abstract class IoBrokerBaseDevice extends RoomBaseDevice implements iJsonOmitKeys, iIoBrokerBaseDevice {
10
6
  /**
11
7
  * The settings for adding devices to Rooms
12
8
  */
13
9
  static roomAddingSettings: {
14
10
  [id: string]: iRoomDeviceAddingSettings;
15
11
  };
16
- /**
17
- * @inheritDoc
18
- * @default undefined (no Settings)
19
- */
20
- settings: DeviceSettings | undefined;
21
- private _room;
22
- /** @inheritDoc */
23
- readonly deviceCapabilities: DeviceCapability[];
24
12
  protected _debounceStateDelay: number;
25
- protected _lastWrite: number;
26
13
  protected stateMap: Map<string, ioBroker.State>;
27
- /** @inheritDoc */
28
- get room(): iRoomBase;
29
- protected get dbo(): iPersist | undefined;
30
- /** @inheritDoc */
31
- get customName(): string;
32
- protected get anyDboActive(): boolean;
33
14
  protected readonly individualStateCallbacks: Map<string, Array<(val: ioBroker.StateValue) => void>>;
34
- protected constructor(_info: IoBrokerDeviceInfo, deviceType: DeviceType);
35
- /** @inheritDoc */
36
- get id(): string;
15
+ protected constructor(info: IoBrokerDeviceInfo, deviceType: DeviceType);
37
16
  /**
38
17
  * Getter info
39
18
  * @returns The device info
40
19
  */
41
- get info(): IoBrokerDeviceInfo;
20
+ get info(): iIoBrokerDeviceInfo;
42
21
  get ioConn(): iIOBrokerConnection | undefined;
43
22
  static addRoom(shortName: string, settings: iRoomDeviceAddingSettings): void;
44
23
  static checkMissing(): void;
45
- /** @inheritDoc */
46
- loadDeviceSettings(): void;
47
24
  /**
48
25
  * Allows to react on the state change of a given state with the passed cb
49
26
  * @param stateName - Last part of the id e.g. "available" not "zigbee.0.00158d00053d3e4b.available"
@@ -64,11 +41,6 @@ export declare abstract class IoBrokerBaseDevice implements iJsonOmitKeys, iIoBr
64
41
  * @param {boolean} pOverride - Whether the child class did override this method
65
42
  */
66
43
  abstract update(idSplit: string[], state: ioBroker.State, initial: boolean, pOverride: boolean): void;
67
- log(level: LogLevel, message: string, logDebugType?: LogDebugType): void;
68
- /** @inheritDoc */
69
- toJSON(): Partial<IoBrokerBaseDevice>;
70
- /** @inheritDoc */
71
- persistDeviceInfo(): void;
72
44
  addToCorrectRoom(): void;
73
45
  /**
74
46
  * Sets the state of a given data point and returns true if that was successful.
@@ -1,59 +1,20 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.IoBrokerBaseDevice = void 0;
4
- const services_1 = require("../services");
5
4
  const enums_1 = require("../enums");
6
5
  const utils_1 = require("../utils");
7
- const api_1 = require("../api");
8
6
  const logging_1 = require("../logging");
9
7
  const ioBroker_1 = require("../ioBroker");
10
- class IoBrokerBaseDevice {
11
- /** @inheritDoc */
12
- get room() {
13
- if (this._room === undefined) {
14
- this._room = utils_1.Utils.guard(api_1.API.getRoom(this.info.room));
15
- }
16
- return this._room;
17
- }
18
- get dbo() {
19
- return services_1.Persistence.dbo;
20
- }
21
- /** @inheritDoc */
22
- get customName() {
23
- return this.info.customName;
24
- }
25
- get anyDboActive() {
26
- return services_1.Persistence.anyDboActive;
27
- }
28
- constructor(_info, deviceType) {
29
- this._info = _info;
30
- this.deviceType = deviceType;
31
- /** @inheritDoc */
32
- this.jsonOmitKeys = ['individualStateCallbacks'];
33
- /**
34
- * @inheritDoc
35
- * @default undefined (no Settings)
36
- */
37
- this.settings = undefined;
38
- this._room = undefined;
39
- /** @inheritDoc */
40
- this.deviceCapabilities = [];
8
+ const RoomBaseDevice_1 = require("./RoomBaseDevice");
9
+ class IoBrokerBaseDevice extends RoomBaseDevice_1.RoomBaseDevice {
10
+ constructor(info, deviceType) {
11
+ super(info, deviceType);
41
12
  // If configured > 0, this indicates the minimum time between state writes in ms
42
13
  this._debounceStateDelay = 0;
43
- this._lastWrite = 0;
44
14
  this.stateMap = new Map();
45
15
  this.individualStateCallbacks = new Map();
16
+ this.jsonOmitKeys.push('individualStateCallbacks');
46
17
  this.addToCorrectRoom();
47
- this.persistDeviceInfo();
48
- utils_1.Utils.guardedTimeout(this.loadDeviceSettings, 300, this);
49
- }
50
- /** @inheritDoc */
51
- get id() {
52
- const result = utils_1.Utils.guard(this.info.allDevicesKey);
53
- if (result === '0' || result === '1') {
54
- logging_1.ServerLogService.writeLog(enums_1.LogLevel.Warn, `Device "${this.info.fullName}" has an akward allDevicesKey of "${result}"`);
55
- }
56
- return result;
57
18
  }
58
19
  /**
59
20
  * Getter info
@@ -77,11 +38,6 @@ class IoBrokerBaseDevice {
77
38
  this.roomAddingSettings[rName].checkMissing();
78
39
  }
79
40
  }
80
- /** @inheritDoc */
81
- loadDeviceSettings() {
82
- var _a;
83
- (_a = this.settings) === null || _a === void 0 ? void 0 : _a.initializeFromDb(this);
84
- }
85
41
  /**
86
42
  * Allows to react on the state change of a given state with the passed cb
87
43
  * @param stateName - Last part of the id e.g. "available" not "zigbee.0.00158d00053d3e4b.available"
@@ -108,25 +64,6 @@ class IoBrokerBaseDevice {
108
64
  }
109
65
  return this.ioConn !== undefined;
110
66
  }
111
- log(level, message, logDebugType = enums_1.LogDebugType.None) {
112
- logging_1.ServerLogService.writeLog(level, message, {
113
- room: this.info.room,
114
- deviceId: this.id,
115
- deviceName: this.info.customName,
116
- debugType: logDebugType,
117
- });
118
- }
119
- /** @inheritDoc */
120
- toJSON() {
121
- return utils_1.Utils.jsonFilter(this, this.jsonOmitKeys, ['_room']);
122
- }
123
- /** @inheritDoc */
124
- persistDeviceInfo() {
125
- utils_1.Utils.guardedTimeout(() => {
126
- var _a;
127
- (_a = services_1.Persistence.dbo) === null || _a === void 0 ? void 0 : _a.addDevice(this);
128
- }, 5000, this);
129
- }
130
67
  addToCorrectRoom() {
131
68
  const settings = IoBrokerBaseDevice.roomAddingSettings[this.info.room];
132
69
  if (settings !== undefined) {
@@ -0,0 +1,9 @@
1
+ import { iDeviceInfo, iRoomBase, iRoomDevice } from '../interfaces';
2
+ import { DeviceType } from '../enums';
3
+ import { BaseDevice } from './BaseDevice';
4
+ export declare abstract class RoomBaseDevice extends BaseDevice implements iRoomDevice {
5
+ protected _room: iRoomBase | undefined;
6
+ protected constructor(info: iDeviceInfo, type: DeviceType);
7
+ /** @inheritDoc */
8
+ get room(): iRoomBase;
9
+ }
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.RoomBaseDevice = void 0;
4
+ const utils_1 = require("../utils");
5
+ const api_1 = require("../api");
6
+ const BaseDevice_1 = require("./BaseDevice");
7
+ class RoomBaseDevice extends BaseDevice_1.BaseDevice {
8
+ constructor(info, type) {
9
+ super(info, type);
10
+ this._room = undefined;
11
+ this.jsonOmitKeys.push('_room');
12
+ }
13
+ /** @inheritDoc */
14
+ get room() {
15
+ if (this._room === undefined) {
16
+ this._room = utils_1.Utils.guard(api_1.API.getRoom(this.info.room));
17
+ }
18
+ return this._room;
19
+ }
20
+ }
21
+ exports.RoomBaseDevice = RoomBaseDevice;
@@ -1,17 +1,15 @@
1
- import { iActuator, iBaseDevice, iDachsDeviceSettings, iDachsSettings, iRoomBase } from '../../interfaces';
2
- import { DeviceCapability, DeviceType, LogDebugType, LogLevel } from '../../enums';
1
+ import { iActuator, iBaseDevice, iDachsDeviceSettings, iDachsSettings } from '../../interfaces';
2
+ import { DeviceCapability } from '../../enums';
3
3
  import { DachsTemperatureSensor } from './dachsTemperatureSensor';
4
- import { DeviceInfo } from '../DeviceInfo';
5
4
  import { ActuatorSetStateCommand, ActuatorToggleCommand, ActuatorWriteStateToDeviceCommand, RestoreTargetAutomaticValueCommand } from '../../command';
6
5
  import { BlockAutomaticHandler } from '../../services';
7
- export declare class Dachs implements iBaseDevice, iActuator {
6
+ import { RoomBaseDevice } from '../RoomBaseDevice';
7
+ export declare class Dachs extends RoomBaseDevice implements iBaseDevice, iActuator {
8
8
  /** @inheritDoc */
9
9
  settings: iDachsDeviceSettings;
10
10
  /** @inheritDoc */
11
11
  readonly blockAutomationHandler: BlockAutomaticHandler;
12
12
  /** @inheritDoc */
13
- readonly deviceType: DeviceType;
14
- /** @inheritDoc */
15
13
  readonly deviceCapabilities: DeviceCapability[];
16
14
  /**
17
15
  * A reference to the Temperature measuring warm water temperature
@@ -54,24 +52,13 @@ export declare class Dachs implements iBaseDevice, iActuator {
54
52
  get actuatorOn(): boolean;
55
53
  constructor(options: iDachsSettings);
56
54
  /** @inheritDoc */
57
- get info(): DeviceInfo;
58
- protected _info: DeviceInfo;
59
- /** @inheritDoc */
60
55
  get id(): string;
61
- /** @inheritDoc */
62
- get room(): iRoomBase | undefined;
63
56
  get name(): string;
64
57
  /** @inheritDoc */
65
58
  restoreTargetAutomaticValue(c: RestoreTargetAutomaticValueCommand): void;
66
59
  /** @inheritDoc */
67
- log(level: LogLevel, message: string, debugType?: LogDebugType): void;
68
- /** @inheritDoc */
69
60
  toJSON(): Partial<Dachs>;
70
61
  /** @inheritDoc */
71
- persistDeviceInfo(): void;
72
- /** @inheritDoc */
73
- loadDeviceSettings(): void;
74
- /** @inheritDoc */
75
62
  persist(): void;
76
63
  private loadData;
77
64
  /** @inheritDoc */
@@ -13,14 +13,13 @@ const lib_1 = require("./lib");
13
13
  const DeviceInfo_1 = require("../DeviceInfo");
14
14
  const devices_1 = require("../devices");
15
15
  const utils_1 = require("../../utils");
16
- const api_1 = require("../../api");
17
- const logging_1 = require("../../logging");
18
16
  const sharedFunctions_1 = require("../sharedFunctions");
19
17
  const sun_time_offsets_1 = require("../../models/sun-time-offsets");
20
18
  const command_1 = require("../../command");
21
19
  const services_1 = require("../../services");
22
20
  const settings_service_1 = require("../../settings-service");
23
- class Dachs {
21
+ const RoomBaseDevice_1 = require("../RoomBaseDevice");
22
+ class Dachs extends RoomBaseDevice_1.RoomBaseDevice {
24
23
  /** @inheritDoc */
25
24
  get customName() {
26
25
  return this.info.customName;
@@ -31,11 +30,16 @@ class Dachs {
31
30
  }
32
31
  constructor(options) {
33
32
  var _a, _b;
33
+ const info = new DeviceInfo_1.DeviceInfo();
34
+ info.fullName = 'Dachs';
35
+ info.customName = `Dachs ${options.roomName}`;
36
+ const allDevicesKey = `dachs-${options.roomName}`;
37
+ info.allDevicesKey = allDevicesKey;
38
+ info.room = options.roomName;
39
+ super(info, enums_1.DeviceType.Dachs);
34
40
  /** @inheritDoc */
35
41
  this.settings = new settingsObjects_1.DachsDeviceSettings();
36
42
  /** @inheritDoc */
37
- this.deviceType = enums_1.DeviceType.Dachs;
38
- /** @inheritDoc */
39
43
  this.deviceCapabilities = [];
40
44
  /** @inheritDoc */
41
45
  this.queuedValue = null;
@@ -44,18 +48,11 @@ class Dachs {
44
48
  this._dachsOn = false;
45
49
  this._tempWarmWater = 0;
46
50
  this._tempHeatStorage = 0;
51
+ devices_1.Devices.alLDevices[allDevicesKey] = this;
47
52
  this.deviceCapabilities.push(enums_1.DeviceCapability.actuator);
48
- this._info = new DeviceInfo_1.DeviceInfo();
49
- this._info.fullName = 'Dachs';
50
- this._info.customName = `Dachs ${options.roomName}`;
51
- this._info.allDevicesKey = `dachs-${options.roomName}`;
52
- this._info.room = options.roomName;
53
- devices_1.Devices.alLDevices[this._info.allDevicesKey] = this;
54
53
  if (options.influxDb) {
55
54
  this._influxClient = new lib_1.DachsInfluxClient(options.influxDb);
56
55
  }
57
- this.persistDeviceInfo();
58
- this.loadDeviceSettings();
59
56
  const modifiedOptions = lodash_1.default.cloneDeep(options);
60
57
  modifiedOptions.connectionOptions.resultConfig = {
61
58
  flatten: true,
@@ -74,18 +71,10 @@ class Dachs {
74
71
  this.heatStorageTempSensor.addTempChangeCallback(this.onHeatStorageTempChange.bind(this));
75
72
  }
76
73
  /** @inheritDoc */
77
- get info() {
78
- return this._info;
79
- }
80
- /** @inheritDoc */
81
74
  get id() {
82
75
  var _a;
83
76
  return (_a = this.info.allDevicesKey) !== null && _a !== void 0 ? _a : `sonos-${this.info.room}-${this.info.customName}`;
84
77
  }
85
- /** @inheritDoc */
86
- get room() {
87
- return api_1.API.getRoom(this.info.room);
88
- }
89
78
  get name() {
90
79
  return this.info.customName;
91
80
  }
@@ -95,17 +84,8 @@ class Dachs {
95
84
  this.setActuator(new command_1.ActuatorSetStateCommand(c, this.targetAutomaticState, 'Restore Target Automatic value'));
96
85
  }
97
86
  /** @inheritDoc */
98
- log(level, message, debugType = enums_1.LogDebugType.None) {
99
- logging_1.ServerLogService.writeLog(level, `${this.name}: ${message}`, {
100
- debugType: debugType,
101
- deviceId: this.name,
102
- room: this._info.room,
103
- deviceName: this.name,
104
- });
105
- }
106
- /** @inheritDoc */
107
87
  toJSON() {
108
- return utils_1.Utils.jsonFilter(lodash_1.default.omit(this, [
88
+ return utils_1.Utils.jsonFilter(lodash_1.default.omit(super.toJSON(), [
109
89
  'room',
110
90
  'client',
111
91
  'config',
@@ -119,17 +99,6 @@ class Dachs {
119
99
  ]));
120
100
  }
121
101
  /** @inheritDoc */
122
- persistDeviceInfo() {
123
- utils_1.Utils.guardedTimeout(() => {
124
- var _a;
125
- (_a = services_1.Persistence.dbo) === null || _a === void 0 ? void 0 : _a.addDevice(this);
126
- }, 5000, this);
127
- }
128
- /** @inheritDoc */
129
- loadDeviceSettings() {
130
- this.settings.initializeFromDb(this);
131
- }
132
- /** @inheritDoc */
133
102
  persist() {
134
103
  var _a;
135
104
  (_a = services_1.Persistence.dbo) === null || _a === void 0 ? void 0 : _a.persistActuator(this);
@@ -190,7 +159,7 @@ class Dachs {
190
159
  }
191
160
  /** @inheritDoc */
192
161
  writeActuatorStateToDevice(c) {
193
- this.log(enums_1.LogLevel.Debug, c.logMessage, enums_1.LogDebugType.SetActuator);
162
+ this.logCommand(c, undefined, enums_1.LogDebugType.SetActuator);
194
163
  if (!c.stateValue) {
195
164
  return;
196
165
  }