hoffmation-base 1.3.1 → 1.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,7 @@
1
1
  import { DeviceSettings } from './deviceSettings';
2
+ import { ExcessEnergyConsumerSettings } from '../excessEnergyConsumerSettings';
2
3
  export declare class AcSettings extends DeviceSettings {
4
+ energySettings: ExcessEnergyConsumerSettings;
3
5
  minimumHours: number;
4
6
  minimumMinutes: number;
5
7
  maximumHours: number;
@@ -3,9 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.AcSettings = void 0;
4
4
  const deviceSettings_1 = require("./deviceSettings");
5
5
  const server_1 = require("../../server");
6
+ const excessEnergyConsumerSettings_1 = require("../excessEnergyConsumerSettings");
6
7
  class AcSettings extends deviceSettings_1.DeviceSettings {
7
8
  constructor() {
8
9
  super(...arguments);
10
+ this.energySettings = new excessEnergyConsumerSettings_1.ExcessEnergyConsumerSettings();
9
11
  this.minimumHours = 0;
10
12
  this.minimumMinutes = 0;
11
13
  this.maximumHours = 24;
@@ -1,5 +1,7 @@
1
1
  import { iBaseDevice } from '../../server';
2
+ import { ExcessEnergyConsumerSettings } from '../excessEnergyConsumerSettings';
2
3
  export declare abstract class DeviceSettings {
4
+ energySettings: ExcessEnergyConsumerSettings | undefined;
3
5
  persist(device: iBaseDevice): void;
4
6
  initializeFromDb(device: iBaseDevice): void;
5
7
  fromPartialObject(_obj: Partial<DeviceSettings>): void;
@@ -3,7 +3,11 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.DeviceSettings = void 0;
4
4
  const server_1 = require("../../server");
5
5
  const logLevel_1 = require("../logLevel");
6
+ const excessEnergyConsumerSettings_1 = require("../excessEnergyConsumerSettings");
6
7
  class DeviceSettings {
8
+ constructor() {
9
+ this.energySettings = undefined;
10
+ }
7
11
  persist(device) {
8
12
  var _a;
9
13
  (_a = server_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistDeviceSettings(device, JSON.stringify(this));
@@ -32,7 +36,12 @@ class DeviceSettings {
32
36
  });
33
37
  }
34
38
  fromPartialObject(_obj) {
35
- // Nothing
39
+ if (_obj.energySettings) {
40
+ if (this.energySettings === undefined) {
41
+ this.energySettings = new excessEnergyConsumerSettings_1.ExcessEnergyConsumerSettings();
42
+ }
43
+ this.energySettings.fromPartialObject(_obj.energySettings);
44
+ }
36
45
  }
37
46
  toJSON() {
38
47
  return server_1.Utils.jsonFilter(this);
@@ -5,7 +5,8 @@ const deviceSettings_1 = require("./deviceSettings");
5
5
  const server_1 = require("../../server");
6
6
  class SceneSettings extends deviceSettings_1.DeviceSettings {
7
7
  fromPartialObject(data) {
8
- this.defaultTurnOffTimeout = data.defaultTurnOffTimeout;
8
+ var _a;
9
+ this.defaultTurnOffTimeout = (_a = data.defaultTurnOffTimeout) !== null && _a !== void 0 ? _a : this.defaultTurnOffTimeout;
9
10
  super.fromPartialObject(data);
10
11
  }
11
12
  toJSON() {
@@ -14,4 +14,5 @@ export declare class ExcessEnergyConsumerSettings {
14
14
  * Devices with same prio try to share as good as possible.
15
15
  */
16
16
  priority?: number, rampUpOnSpareEnergy?: boolean, powerReactionTime?: number);
17
+ fromPartialObject(obj: Partial<ExcessEnergyConsumerSettings>): void;
17
18
  }
@@ -15,5 +15,11 @@ class ExcessEnergyConsumerSettings {
15
15
  this.rampUpOnSpareEnergy = rampUpOnSpareEnergy;
16
16
  this.powerReactionTime = powerReactionTime;
17
17
  }
18
+ fromPartialObject(obj) {
19
+ var _a, _b, _c;
20
+ this.priority = (_a = obj.priority) !== null && _a !== void 0 ? _a : this.priority;
21
+ this.rampUpOnSpareEnergy = (_b = obj.rampUpOnSpareEnergy) !== null && _b !== void 0 ? _b : this.rampUpOnSpareEnergy;
22
+ this.powerReactionTime = (_c = obj.powerReactionTime) !== null && _c !== void 0 ? _c : this.powerReactionTime;
23
+ }
18
24
  }
19
25
  exports.ExcessEnergyConsumerSettings = ExcessEnergyConsumerSettings;
@@ -1,6 +1,7 @@
1
1
  import { ExcessEnergyConsumerSettings, LogLevel } from '../../../models';
2
- export interface iExcessEnergyConsumer {
3
- energyConsumerSettings: ExcessEnergyConsumerSettings;
2
+ import { iBaseDevice } from './iBaseDevice';
3
+ export interface iExcessEnergyConsumer extends iBaseDevice {
4
+ readonly energySettings: ExcessEnergyConsumerSettings;
4
5
  currentConsumption: number;
5
6
  on: boolean;
6
7
  isAvailableForExcessEnergy(): boolean;
@@ -172,7 +172,7 @@ class JsObjectEnergyManager extends IoBrokerBaseDevice_1.IoBrokerBaseDevice {
172
172
  var _a;
173
173
  const potentialDevices = this._excessEnergyConsumer.filter((e) => {
174
174
  var _a;
175
- if (e.energyConsumerSettings.priority === -1 || e.on || !e.isAvailableForExcessEnergy()) {
175
+ if (e.energySettings.priority === -1 || e.on || !e.isAvailableForExcessEnergy()) {
176
176
  return false;
177
177
  }
178
178
  if (((_a = this._lastDeviceChange) === null || _a === void 0 ? void 0 : _a.newState) && e === this._lastDeviceChange.device) {
@@ -188,9 +188,9 @@ class JsObjectEnergyManager extends IoBrokerBaseDevice_1.IoBrokerBaseDevice {
188
188
  return;
189
189
  }
190
190
  potentialDevices.sort((a, b) => {
191
- return b.energyConsumerSettings.priority - a.energyConsumerSettings.priority;
191
+ return b.energySettings.priority - a.energySettings.priority;
192
192
  });
193
- this.blockDeviceChangeTime = services_1.Utils.nowMS() + potentialDevices[0].energyConsumerSettings.powerReactionTime;
193
+ this.blockDeviceChangeTime = services_1.Utils.nowMS() + potentialDevices[0].energySettings.powerReactionTime;
194
194
  potentialDevices[0].log(models_1.LogLevel.Info, `Turning on, as we have ${this.excessEnergy}W to spare...`);
195
195
  potentialDevices[0].turnOnForExcessEnergy();
196
196
  this._lastDeviceChange = { newState: true, device: potentialDevices[0] };
@@ -199,7 +199,7 @@ class JsObjectEnergyManager extends IoBrokerBaseDevice_1.IoBrokerBaseDevice {
199
199
  var _a;
200
200
  const potentialDevices = this._excessEnergyConsumer.filter((e) => {
201
201
  var _a;
202
- if (e.energyConsumerSettings.priority === -1 || !e.on) {
202
+ if (e.energySettings.priority === -1 || !e.on) {
203
203
  return false;
204
204
  }
205
205
  if (!e.wasActivatedByExcessEnergy()) {
@@ -219,10 +219,10 @@ class JsObjectEnergyManager extends IoBrokerBaseDevice_1.IoBrokerBaseDevice {
219
219
  return;
220
220
  }
221
221
  potentialDevices.sort((a, b) => {
222
- return a.energyConsumerSettings.priority - b.energyConsumerSettings.priority;
222
+ return a.energySettings.priority - b.energySettings.priority;
223
223
  });
224
224
  potentialDevices[0].log(models_1.LogLevel.Info, `Turning off, as we don't have energy to spare...`);
225
- this.blockDeviceChangeTime = services_1.Utils.nowMS() + potentialDevices[0].energyConsumerSettings.powerReactionTime;
225
+ this.blockDeviceChangeTime = services_1.Utils.nowMS() + potentialDevices[0].energySettings.powerReactionTime;
226
226
  potentialDevices[0].turnOffDueToMissingEnergy();
227
227
  this._lastDeviceChange = { newState: false, device: potentialDevices[0] };
228
228
  }
@@ -13,10 +13,10 @@ export declare class ZigbeeBlitzShp extends ZigbeeActuator implements iExcessEne
13
13
  private _loadPower;
14
14
  get loadPower(): number;
15
15
  settings: ActuatorSettings;
16
- energyConsumerSettings: ExcessEnergyConsumerSettings;
17
16
  private readonly _availableForExcessEnergy;
18
17
  private _activatedByExcessEnergy;
19
18
  constructor(pInfo: IoBrokerDeviceInfo);
19
+ get energySettings(): ExcessEnergyConsumerSettings;
20
20
  get currentConsumption(): number;
21
21
  get on(): boolean;
22
22
  isAvailableForExcessEnergy(): boolean;
@@ -13,9 +13,9 @@ class ZigbeeBlitzShp extends BaseDevices_1.ZigbeeActuator {
13
13
  this._energy = 0;
14
14
  this._loadPower = 0;
15
15
  this.settings = new models_1.ActuatorSettings();
16
- this.energyConsumerSettings = new models_1.ExcessEnergyConsumerSettings();
17
16
  this._availableForExcessEnergy = true;
18
17
  this._activatedByExcessEnergy = false;
18
+ this.settings.energySettings = new models_1.ExcessEnergyConsumerSettings();
19
19
  this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.excessEnergyConsumer);
20
20
  }
21
21
  get steckerOn() {
@@ -30,6 +30,9 @@ class ZigbeeBlitzShp extends BaseDevices_1.ZigbeeActuator {
30
30
  get loadPower() {
31
31
  return this._loadPower;
32
32
  }
33
+ get energySettings() {
34
+ return this.settings.energySettings;
35
+ }
33
36
  get currentConsumption() {
34
37
  return this._loadPower;
35
38
  }
@@ -8,13 +8,15 @@ export declare abstract class AcDevice implements iExcessEnergyConsumer, iRoomDe
8
8
  ip: string;
9
9
  acDeviceType: AcDeviceType;
10
10
  currentConsumption: number;
11
- energyConsumerSettings: ExcessEnergyConsumerSettings;
12
11
  settings: AcSettings;
13
12
  room: RoomBase | undefined;
14
13
  deviceCapabilities: DeviceCapability[];
14
+ protected _activatedByExcessEnergy: boolean;
15
+ protected _blockAutomaticChangeMS: number;
15
16
  protected _info: DeviceInfo;
16
17
  get temperature(): number;
17
18
  protected constructor(name: string, roomName: string, ip: string, acDeviceType: AcDeviceType);
19
+ get energySettings(): ExcessEnergyConsumerSettings;
18
20
  private _roomTemperature;
19
21
  get roomTemperature(): number;
20
22
  get info(): DeviceInfo;
@@ -22,14 +24,12 @@ export declare abstract class AcDevice implements iExcessEnergyConsumer, iRoomDe
22
24
  set info(info: DeviceInfo);
23
25
  abstract get deviceType(): DeviceType;
24
26
  get name(): string;
25
- protected _activatedByExcessEnergy: boolean;
26
- protected _blockAutomaticTurnOnMS: number;
27
27
  get id(): string;
28
28
  abstract get on(): boolean;
29
29
  isAvailableForExcessEnergy(): boolean;
30
30
  calculateDesiredMode(): AcMode;
31
31
  /**
32
- * Disable automatic Turn-On for given amount of ms and turn off immediately.
32
+ * Disable automatic Turn-On and Turn-Off for given amount of ms.
33
33
  * @param {number} timeout
34
34
  */
35
35
  deactivateAutomaticChange(timeout?: number): void;
@@ -40,6 +40,7 @@ export declare abstract class AcDevice implements iExcessEnergyConsumer, iRoomDe
40
40
  turnOnForExcessEnergy(): void;
41
41
  abstract turnOff(): void;
42
42
  turnOffDueToMissingEnergy(): void;
43
+ setState(mode: AcMode, forceTime?: number): void;
43
44
  log(level: LogLevel, message: string, debugType?: LogDebugType): void;
44
45
  wasActivatedByExcessEnergy(): boolean;
45
46
  loadDeviceSettings(): void;
@@ -18,12 +18,11 @@ class AcDevice {
18
18
  this.ip = ip;
19
19
  this.acDeviceType = acDeviceType;
20
20
  this.currentConsumption = -1;
21
- this.energyConsumerSettings = new models_1.ExcessEnergyConsumerSettings();
22
21
  this.settings = new models_1.AcSettings();
23
22
  this.deviceCapabilities = [DeviceCapability_1.DeviceCapability.ac];
24
- this._roomTemperature = 0;
25
23
  this._activatedByExcessEnergy = false;
26
- this._blockAutomaticTurnOnMS = -1;
24
+ this._blockAutomaticChangeMS = -1;
25
+ this._roomTemperature = 0;
27
26
  this._info = new devices_1.DeviceInfo();
28
27
  this._info.fullName = `AC ${name}`;
29
28
  this._info.customName = `${roomName} ${name}`;
@@ -37,6 +36,9 @@ class AcDevice {
37
36
  get temperature() {
38
37
  return this._roomTemperature;
39
38
  }
39
+ get energySettings() {
40
+ return this.settings.energySettings;
41
+ }
40
42
  get roomTemperature() {
41
43
  return this._roomTemperature;
42
44
  }
@@ -57,7 +59,7 @@ class AcDevice {
57
59
  return (_a = this.info.allDevicesKey) !== null && _a !== void 0 ? _a : `ac-${this.info.room}-${this.info.customName}`;
58
60
  }
59
61
  isAvailableForExcessEnergy() {
60
- if (utils_1.Utils.nowMS() < this._blockAutomaticTurnOnMS) {
62
+ if (utils_1.Utils.nowMS() < this._blockAutomaticChangeMS) {
61
63
  return false;
62
64
  }
63
65
  const minimumStart = utils_1.Utils.dateByTimeSpan(this.settings.minimumHours, this.settings.minimumMinutes);
@@ -76,6 +78,14 @@ class AcDevice {
76
78
  return ac_mode_1.AcMode.Off;
77
79
  }
78
80
  const acOn = this.on;
81
+ // Check Turn Off Time
82
+ const maximumEnd = utils_1.Utils.dateByTimeSpan(this.settings.maximumHours, this.settings.maximumMinutes);
83
+ const minimumStart = utils_1.Utils.dateByTimeSpan(this.settings.minimumHours, this.settings.minimumMinutes);
84
+ const now = new Date();
85
+ if (acOn && (now > maximumEnd || now < minimumStart)) {
86
+ this.log(models_1.LogLevel.Info, `We should turn off now, to respect night settings.`);
87
+ return ac_mode_1.AcMode.Off;
88
+ }
79
89
  let threshold = acOn ? 0 : 1;
80
90
  let desiredMode = ac_mode_1.AcMode.Off;
81
91
  const excessEnergy = (_b = (_a = devices_1.Devices.energymanager) === null || _a === void 0 ? void 0 : _a.excessEnergy) !== null && _b !== void 0 ? _b : -1;
@@ -97,11 +107,11 @@ class AcDevice {
97
107
  return desiredMode;
98
108
  }
99
109
  /**
100
- * Disable automatic Turn-On for given amount of ms and turn off immediately.
110
+ * Disable automatic Turn-On and Turn-Off for given amount of ms.
101
111
  * @param {number} timeout
102
112
  */
103
113
  deactivateAutomaticChange(timeout = 60 * 60 * 1000) {
104
- this._blockAutomaticTurnOnMS = utils_1.Utils.nowMS() + timeout;
114
+ this._blockAutomaticChangeMS = utils_1.Utils.nowMS() + timeout;
105
115
  }
106
116
  onTemperaturChange(newTemperatur) {
107
117
  this.roomTemperatur = newTemperatur;
@@ -114,7 +124,7 @@ class AcDevice {
114
124
  (_a = utils_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistAC(this);
115
125
  }
116
126
  turnOnForExcessEnergy() {
117
- if (this._blockAutomaticTurnOnMS > utils_1.Utils.nowMS()) {
127
+ if (this._blockAutomaticChangeMS > utils_1.Utils.nowMS()) {
118
128
  return;
119
129
  }
120
130
  this._activatedByExcessEnergy = true;
@@ -124,6 +134,15 @@ class AcDevice {
124
134
  turnOffDueToMissingEnergy() {
125
135
  this.turnOff();
126
136
  }
137
+ setState(mode, forceTime = 60 * 60 * 1000) {
138
+ this._blockAutomaticChangeMS = utils_1.Utils.nowMS() + forceTime;
139
+ if (mode == ac_mode_1.AcMode.Off) {
140
+ this.turnOff();
141
+ return;
142
+ }
143
+ this.setDesiredMode(mode, false);
144
+ this.turnOn();
145
+ }
127
146
  log(level, message, debugType = log_service_1.LogDebugType.None) {
128
147
  var _a, _b;
129
148
  log_service_1.ServerLogService.writeLog(level, `${this.name}: ${message}`, {
@@ -147,8 +166,8 @@ class AcDevice {
147
166
  }
148
167
  automaticCheck() {
149
168
  var _a;
150
- if (!this.on && utils_1.Utils.nowMS() < this._blockAutomaticTurnOnMS) {
151
- // We aren't allowed to trun on anyway --> exit
169
+ if (utils_1.Utils.nowMS() < this._blockAutomaticChangeMS) {
170
+ // We aren't allowed to turn on or off anyway --> exit
152
171
  return;
153
172
  }
154
173
  const desiredMode = this.calculateDesiredMode();
@@ -165,13 +184,6 @@ class AcDevice {
165
184
  this.turnOff();
166
185
  return;
167
186
  }
168
- // Check Cooling Turn Off
169
- const maximumEnd = utils_1.Utils.dateByTimeSpan(this.settings.maximumHours, this.settings.maximumMinutes);
170
- const now = new Date();
171
- if (now > maximumEnd) {
172
- this.turnOff();
173
- return;
174
- }
175
187
  }
176
188
  toJSON() {
177
189
  // eslint-disable-next-line
@@ -20,7 +20,6 @@ class OwnDaikinDevice extends ac_device_1.AcDevice {
20
20
  this.desiredMode = daikin_controller_1.Mode.COLD;
21
21
  this.deviceType = devices_1.DeviceType.Daikin;
22
22
  this._on = false;
23
- this.energyConsumerSettings.priority = 50;
24
23
  this._device = device;
25
24
  }
26
25
  get device() {
@@ -27,8 +27,9 @@ export declare class API {
27
27
  * @param id The id of the device, if wrong false will be returned
28
28
  * @param {boolean} desiredState
29
29
  * @param {AcMode} desiredMode
30
+ * @param forceTime The time in ms this should not change before automatic change is allowed again
30
31
  */
31
- static setAc(id: string, desiredState: boolean, desiredMode?: AcMode): boolean;
32
+ static setAc(id: string, desiredState: boolean, desiredMode?: AcMode, forceTime?: number): boolean;
32
33
  /**
33
34
  * Turns on/off all AC´s in the home
34
35
  * @param {boolean} desiredState
@@ -64,8 +64,9 @@ class API {
64
64
  * @param id The id of the device, if wrong false will be returned
65
65
  * @param {boolean} desiredState
66
66
  * @param {AcMode} desiredMode
67
+ * @param forceTime The time in ms this should not change before automatic change is allowed again
67
68
  */
68
- static setAc(id, desiredState, desiredMode) {
69
+ static setAc(id, desiredState, desiredMode, forceTime = 60 * 60 * 1000) {
69
70
  const d = this.getAc(id);
70
71
  if (!d) {
71
72
  log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `AC Device for id ${id} not found`);
@@ -75,14 +76,15 @@ class API {
75
76
  log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `Device for id ${id} is not an ac`);
76
77
  return false;
77
78
  }
78
- if (desiredState) {
79
- d.setDesiredMode((desiredMode !== null && desiredMode !== void 0 ? desiredMode : settings_service_1.SettingsService.heatMode == config_1.HeatingMode.Winter) ? ac_1.AcMode.Heating : ac_1.AcMode.Cooling, false);
80
- d.turnOn();
79
+ if (desiredMode === undefined) {
80
+ if (!desiredState) {
81
+ desiredMode = ac_1.AcMode.Off;
82
+ }
83
+ else {
84
+ desiredMode = settings_service_1.SettingsService.heatMode == config_1.HeatingMode.Winter ? ac_1.AcMode.Heating : ac_1.AcMode.Cooling;
85
+ }
81
86
  }
82
- else {
83
- d.turnOff();
84
- }
85
- d.deactivateAutomaticChange(60 * 60 * 1000);
87
+ d.setState(desiredMode, forceTime);
86
88
  return true;
87
89
  }
88
90
  /**