hoffmation-base 2.18.13 → 2.19.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.
@@ -1,9 +1,9 @@
1
1
  import { RoomBase } from '../RoomBase';
2
2
  export declare class RoomAddDeviceItem {
3
- setID: (value: string) => RoomBase;
3
+ setID: (value: string) => RoomBase | undefined;
4
4
  index: number;
5
5
  customName: string;
6
- constructor(setID: (value: string) => RoomBase, index: number, customName: string);
6
+ constructor(setID: (value: string) => RoomBase | undefined, index: number, customName: string);
7
7
  private _added;
8
8
  get added(): boolean;
9
9
  set added(value: boolean);
@@ -12,9 +12,10 @@ export declare abstract class IoBrokerBaseDevice implements iRoomDevice {
12
12
  static roomAddingSettings: {
13
13
  [id: string]: RoomDeviceAddingSettings;
14
14
  };
15
- room: RoomBase | undefined;
15
+ private _room;
16
16
  readonly deviceCapabilities: DeviceCapability[];
17
17
  get customName(): string;
18
+ get room(): RoomBase;
18
19
  protected readonly individualStateCallbacks: Map<string, Array<(val: ioBroker.StateValue) => void>>;
19
20
  protected constructor(_info: IoBrokerDeviceInfo, deviceType: DeviceType);
20
21
  get id(): string;
@@ -8,11 +8,17 @@ class IoBrokerBaseDevice {
8
8
  get customName() {
9
9
  return this.info.customName;
10
10
  }
11
+ get room() {
12
+ if (this._room === undefined) {
13
+ this._room = services_1.Utils.guard(services_1.API.getRoom(this.info.room));
14
+ }
15
+ return this._room;
16
+ }
11
17
  constructor(_info, deviceType) {
12
18
  this._info = _info;
13
19
  this.deviceType = deviceType;
14
20
  this.settings = undefined;
15
- this.room = undefined;
21
+ this._room = undefined;
16
22
  this.deviceCapabilities = [];
17
23
  this.individualStateCallbacks = new Map();
18
24
  this.addToCorrectRoom();
@@ -97,7 +103,7 @@ class IoBrokerBaseDevice {
97
103
  });
98
104
  }
99
105
  toJSON() {
100
- return services_1.Utils.jsonFilter(this, ['individualStateCallbacks']);
106
+ return services_1.Utils.jsonFilter(this, ['individualStateCallbacks'], ['_room']);
101
107
  }
102
108
  persistDeviceInfo() {
103
109
  services_1.Utils.guardedTimeout(() => {
@@ -124,7 +130,10 @@ class IoBrokerBaseDevice {
124
130
  services_1.ServerLogService.writeLog(models_1.LogLevel.Error, `AllDevicesKey for Device "${this.info.fullName}"/"${this.info.fullID}" missing.`);
125
131
  return;
126
132
  }
127
- this.room = deviceSettings.setID(this.info.allDevicesKey);
133
+ const room = deviceSettings.setID(this.info.allDevicesKey);
134
+ if (room !== undefined) {
135
+ this._room = room;
136
+ }
128
137
  deviceSettings.added = true;
129
138
  services_1.ServerLogService.addedDeviceToRoom(settings.RoomName, this.deviceType, this.info.deviceRoomIndex);
130
139
  return;
@@ -108,9 +108,6 @@ class HmIpHeizgruppe extends hmIpDevice_1.HmIPDevice {
108
108
  }
109
109
  }
110
110
  getBelongingHeizungen() {
111
- if (!this.room) {
112
- return [];
113
- }
114
111
  return this.room.deviceCluster.getDevicesByType(device_cluster_type_1.DeviceClusterType.Heater);
115
112
  }
116
113
  update(idSplit, state, initial = false) {
@@ -129,7 +126,7 @@ class HmIpHeizgruppe extends hmIpDevice_1.HmIPDevice {
129
126
  }
130
127
  }
131
128
  checkAutomaticChange() {
132
- var _a, _b, _c, _d, _e, _f, _g, _h;
129
+ var _a, _b, _c, _d;
133
130
  if (!this._initialSeasonCheckDone) {
134
131
  this.checkSeasonTurnOff();
135
132
  }
@@ -137,8 +134,7 @@ class HmIpHeizgruppe extends hmIpDevice_1.HmIPDevice {
137
134
  if (!this.settings.automaticMode || this.seasonTurnOff || (heatGroupSettings === null || heatGroupSettings === void 0 ? void 0 : heatGroupSettings.automaticMode) === false) {
138
135
  return;
139
136
  }
140
- const setting = models_1.TemperatureSettings.getActiveSetting((_f = (_e = (_d = (_c = this.room) === null || _c === void 0 ? void 0 : _c.HeatGroup) === null || _d === void 0 ? void 0 : _d.settings) === null || _e === void 0 ? void 0 : _e.automaticPoints) !== null && _f !== void 0 ? _f : [], new Date());
141
- const targetTemp = (_h = (_g = setting === null || setting === void 0 ? void 0 : setting.temperature) !== null && _g !== void 0 ? _g : heatGroupSettings === null || heatGroupSettings === void 0 ? void 0 : heatGroupSettings.automaticFallBackTemperatur) !== null && _h !== void 0 ? _h : 20;
137
+ const targetTemp = (_d = (_c = this.room.HeatGroup) === null || _c === void 0 ? void 0 : _c.desiredTemp) !== null && _d !== void 0 ? _d : 20;
142
138
  if (this._desiredTemperature !== targetTemp) {
143
139
  this.log(models_1.LogLevel.Debug, `Automatische Temperaturanpassung für ${this.info.customName} auf ${targetTemp}°C`);
144
140
  this.desiredTemperature = targetTemp;
@@ -70,7 +70,7 @@ class HmIpLampe extends hmIpDevice_1.HmIPDevice {
70
70
  timeout = 3000;
71
71
  services_1.Utils.guardedTimeout(() => {
72
72
  var _a;
73
- if (this.room && ((_a = this.room.PraesenzGroup) === null || _a === void 0 ? void 0 : _a.anyPresent())) {
73
+ if ((_a = this.room.PraesenzGroup) === null || _a === void 0 ? void 0 : _a.anyPresent()) {
74
74
  this.setLight(true, -1, true);
75
75
  }
76
76
  }, this.settings.stromStossResendTime * 1000, this);
@@ -83,11 +83,10 @@ class HmIpLampe extends hmIpDevice_1.HmIPDevice {
83
83
  }
84
84
  }
85
85
  toggleLight(time, force = false, calculateTime = false) {
86
- var _a;
87
86
  const newVal = this.queuedLightValue !== null ? !this.queuedLightValue : !this.lightOn;
88
87
  const timeout = newVal && force ? 30 * 60 * 1000 : -1;
89
- if (newVal && time === undefined && calculateTime && this.room !== undefined) {
90
- time = services_1.TimeCallbackService.dayType((_a = this.room) === null || _a === void 0 ? void 0 : _a.settings.lampOffset);
88
+ if (newVal && time === undefined && calculateTime) {
89
+ time = services_1.TimeCallbackService.dayType(this.room.settings.lampOffset);
91
90
  }
92
91
  if (newVal && time !== undefined) {
93
92
  this.setTimeBased(time, timeout, force);
@@ -122,7 +122,7 @@ class ShellyTrv extends shellyDevice_1.ShellyDevice {
122
122
  }
123
123
  }
124
124
  checkAutomaticChange() {
125
- var _a, _b;
125
+ var _a;
126
126
  if (!this._initialSeasonCheckDone) {
127
127
  this.checkSeasonTurnOff();
128
128
  }
@@ -135,7 +135,7 @@ class ShellyTrv extends shellyDevice_1.ShellyDevice {
135
135
  if (!this.settings.useOwnTemperatur && !this.settings.controlByPid) {
136
136
  this.setExternalTemperatureEnabled(true);
137
137
  }
138
- const heatGroup = (_a = this.room) === null || _a === void 0 ? void 0 : _a.HeatGroup;
138
+ const heatGroup = this.room.HeatGroup;
139
139
  if (heatGroup === undefined) {
140
140
  this.log(models_1.LogLevel.Warn, `HeatGroup is undefined for ${this.info.customName}`);
141
141
  return;
@@ -148,7 +148,7 @@ class ShellyTrv extends shellyDevice_1.ShellyDevice {
148
148
  if (!this.settings.automaticMode) {
149
149
  return;
150
150
  }
151
- const targetTemperature = (_b = heatGroup.desiredTemp) !== null && _b !== void 0 ? _b : 20;
151
+ const targetTemperature = (_a = heatGroup.desiredTemp) !== null && _a !== void 0 ? _a : 20;
152
152
  if (this._desiredTemperatur !== targetTemperature) {
153
153
  this.log(models_1.LogLevel.Debug, `Automatische Temperaturanpassung für ${this.info.customName} auf ${targetTemperature}°C`);
154
154
  this.desiredTemperature = targetTemperature;
@@ -102,10 +102,9 @@ class WledDevice extends IoBrokerBaseDevice_1.IoBrokerBaseDevice {
102
102
  return this.on;
103
103
  }
104
104
  toggleLight(time, _force = false, calculateTime = false) {
105
- var _a;
106
105
  const newVal = !this.lightOn;
107
- if (newVal && time === undefined && calculateTime && this.room !== undefined) {
108
- time = services_1.TimeCallbackService.dayType((_a = this.room) === null || _a === void 0 ? void 0 : _a.settings.lampOffset);
106
+ if (newVal && time === undefined && calculateTime) {
107
+ time = services_1.TimeCallbackService.dayType(this.room.settings.lampOffset);
109
108
  }
110
109
  if (newVal && time !== undefined) {
111
110
  this.setTimeBased(time);
@@ -151,11 +151,10 @@ class ZigbeeDimmer extends index_1.ZigbeeDevice {
151
151
  this._lastPersist = now;
152
152
  }
153
153
  toggleLight(time, force = false, calculateTime = false) {
154
- var _a;
155
154
  const newVal = this.queuedValue !== null ? !this.queuedValue : !this.lightOn;
156
155
  const timeout = newVal && force ? 30 * 60 * 1000 : -1;
157
- if (newVal && time === undefined && calculateTime && this.room !== undefined) {
158
- time = services_1.TimeCallbackService.dayType((_a = this.room) === null || _a === void 0 ? void 0 : _a.settings.lampOffset);
156
+ if (newVal && time === undefined && calculateTime && this.room) {
157
+ time = services_1.TimeCallbackService.dayType(this.room.settings.lampOffset);
159
158
  }
160
159
  if (newVal && time !== undefined) {
161
160
  this.setTimeBased(time, timeout, force);
@@ -91,16 +91,19 @@ class ZigbeeHeater extends zigbeeDevice_1.ZigbeeDevice {
91
91
  this._roomTemperature = val;
92
92
  }
93
93
  checkAutomaticChange() {
94
- var _a, _b, _c, _d, _e, _f, _g, _h;
94
+ var _a;
95
95
  if (!this._initialSeasonCheckDone) {
96
96
  this.checkSeasonTurnOff();
97
97
  }
98
- const heatGroupSettings = (_b = (_a = this.room) === null || _a === void 0 ? void 0 : _a.HeatGroup) === null || _b === void 0 ? void 0 : _b.settings;
99
- if (!this.settings.automaticMode || this.seasonTurnOff || (heatGroupSettings === null || heatGroupSettings === void 0 ? void 0 : heatGroupSettings.automaticMode) === false) {
98
+ const heatGroup = this.room.HeatGroup;
99
+ if (!this.settings.automaticMode || this.seasonTurnOff || ((_a = heatGroup === null || heatGroup === void 0 ? void 0 : heatGroup.settings) === null || _a === void 0 ? void 0 : _a.automaticMode) === false) {
100
+ return;
101
+ }
102
+ if (heatGroup === undefined) {
103
+ this.log(models_1.LogLevel.Warn, `Heat-Group is undefined for ${this.info.customName}.`);
100
104
  return;
101
105
  }
102
- const setting = models_1.TemperatureSettings.getActiveSetting((_f = (_e = (_d = (_c = this.room) === null || _c === void 0 ? void 0 : _c.HeatGroup) === null || _d === void 0 ? void 0 : _d.settings) === null || _e === void 0 ? void 0 : _e.automaticPoints) !== null && _f !== void 0 ? _f : [], new Date());
103
- const targetTemperature = (_h = (_g = setting === null || setting === void 0 ? void 0 : setting.temperature) !== null && _g !== void 0 ? _g : heatGroupSettings === null || heatGroupSettings === void 0 ? void 0 : heatGroupSettings.automaticFallBackTemperatur) !== null && _h !== void 0 ? _h : 20;
106
+ const targetTemperature = heatGroup.desiredTemp;
104
107
  if (this._desiredTemperatur !== targetTemperature) {
105
108
  this.log(models_1.LogLevel.Debug, `Automatische Temperaturanpassung für ${this.info.customName} auf ${targetTemperature}°C`);
106
109
  this.desiredTemperature = targetTemperature;
@@ -29,7 +29,7 @@ class ZigbeeIlluLampe extends zigbeeIlluActuator_1.ZigbeeIlluActuator {
29
29
  timeout = 3000;
30
30
  services_1.Utils.guardedTimeout(() => {
31
31
  var _a;
32
- if (this.room && ((_a = this.room.PraesenzGroup) === null || _a === void 0 ? void 0 : _a.anyPresent())) {
32
+ if ((_a = this.room.PraesenzGroup) === null || _a === void 0 ? void 0 : _a.anyPresent()) {
33
33
  this.setLight(true, -1, true);
34
34
  }
35
35
  }, this.settings.stromStossResendTime * 1000, this);
@@ -37,11 +37,10 @@ class ZigbeeIlluLampe extends zigbeeIlluActuator_1.ZigbeeIlluActuator {
37
37
  super.setActuator(pValue, timeout, force);
38
38
  }
39
39
  toggleLight(time, force = false, calculateTime = false) {
40
- var _a;
41
40
  const newVal = this.queuedValue !== null ? !this.queuedValue : !this.lightOn;
42
41
  const timeout = newVal && force ? 30 * 60 * 1000 : -1;
43
- if (newVal && time === undefined && calculateTime && this.room !== undefined) {
44
- time = services_1.TimeCallbackService.dayType((_a = this.room) === null || _a === void 0 ? void 0 : _a.settings.lampOffset);
42
+ if (newVal && time === undefined && calculateTime) {
43
+ time = services_1.TimeCallbackService.dayType(this.room.settings.lampOffset);
45
44
  }
46
45
  if (newVal && time !== undefined) {
47
46
  this.setTimeBased(time, timeout, force);
@@ -17,7 +17,7 @@ export declare class Utils {
17
17
  static guardedInterval(func: (...args: unknown[]) => void, time: number, thisContext?: unknown | undefined, fireImmediate?: boolean): NodeJS.Timeout;
18
18
  static nowString(): string;
19
19
  static guard<T>(object: T | undefined | null): T & {};
20
- static jsonFilter(object: object, additionalOmitKeys?: string[]): Partial<object>;
20
+ static jsonFilter(object: object, additionalOmitKeys?: string[], topLevelOmmitKeys?: string[]): Partial<object>;
21
21
  static testInitializeServices(): void;
22
22
  static kWh(wattage: number, durationInMs: number): number;
23
23
  static round(number: number, digits: number): number;
@@ -79,10 +79,12 @@ class Utils {
79
79
  }
80
80
  return object;
81
81
  }
82
- static jsonFilter(object, additionalOmitKeys = []) {
82
+ static jsonFilter(object, additionalOmitKeys = [], topLevelOmmitKeys = []) {
83
83
  const keysToOmit = ['timeout', 'interval', 'timeouts', 'callback', 'otaInfo'];
84
84
  keysToOmit.push(...additionalOmitKeys);
85
- return this.deepOmit(object, keysToOmit);
85
+ const loweredOmitKeys = keysToOmit.map((key) => key.toLowerCase());
86
+ const loweredTopLevelOmitKeys = topLevelOmmitKeys.map((key) => key.toLowerCase());
87
+ return this.deepOmit(object, loweredOmitKeys, loweredTopLevelOmitKeys);
86
88
  }
87
89
  static testInitializeServices() {
88
90
  log_service_1.ServerLogService.settings.logLevel = -1;
@@ -163,7 +165,7 @@ class Utils {
163
165
  const modToCheck = this.positiveMod(degreeToCheck, 360);
164
166
  return modMin < modMax ? modToCheck <= modMax && modToCheck >= modMin : modToCheck > modMin || modToCheck < modMax;
165
167
  }
166
- static deepOmit(obj, keysToOmit, level = 1, currentKey = '') {
168
+ static deepOmit(obj, keysToOmit, topLevelOmitKeys, level = 1, currentKey = '') {
167
169
  if (level > 10 && level < 20) {
168
170
  log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `DeepOmit Loop Level ${level} reached for ${currentKey}`);
169
171
  }
@@ -174,13 +176,16 @@ class Utils {
174
176
  }
175
177
  if (typeof key == 'string') {
176
178
  const lowerKey = key.toLowerCase();
177
- // transform to a new object
178
179
  for (const checkKey of keysToOmit) {
179
180
  // if the key is in the index skip it
180
- if (lowerKey.includes(checkKey.toLowerCase())) {
181
+ if (lowerKey.includes(checkKey)) {
181
182
  return;
182
183
  }
183
184
  }
185
+ // transform to a new object
186
+ if (level === 1 && topLevelOmitKeys.includes(lowerKey)) {
187
+ return;
188
+ }
184
189
  if (lowerKey.endsWith('map')) {
185
190
  const newKey = lowerKey.replace('map', 'dict');
186
191
  const dict = {};
@@ -191,7 +196,7 @@ class Utils {
191
196
  }
192
197
  for (const mapName of map.keys()) {
193
198
  dict[mapName] = lodash_1.default.isObject(map.get(mapName))
194
- ? this.deepOmit(map.get(mapName), keysToOmit, level + 1, `${currentKey}.${lowerKey}.${mapName}`)
199
+ ? this.deepOmit(map.get(mapName), keysToOmit, [], level + 1, `${currentKey}.${lowerKey}.${mapName}`)
195
200
  : map.get(mapName);
196
201
  }
197
202
  result[newKey] = dict;
@@ -203,7 +208,7 @@ class Utils {
203
208
  return;
204
209
  }
205
210
  // if the key is an object run it through the inner function - omitFromObject
206
- result[key] = lodash_1.default.isObject(value) ? this.deepOmit(value, keysToOmit, level + 1, `${currentKey}.${key}`) : value;
211
+ result[key] = lodash_1.default.isObject(value) ? this.deepOmit(value, keysToOmit, [], level + 1, `${currentKey}.${key}`) : value;
207
212
  });
208
213
  }
209
214
  static nextMatchingDate(hours = 0, minutes = 0, now = new Date()) {