hoffmation-base 2.20.4 → 2.21.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 (26) hide show
  1. package/lib/models/iIdHolder.d.ts +2 -1
  2. package/lib/server/devices/baseDeviceInterfaces/iActuator.d.ts +7 -1
  3. package/lib/server/devices/dachs/dachs.d.ts +6 -1
  4. package/lib/server/devices/dachs/dachs.js +18 -1
  5. package/lib/server/devices/groups/presenceGroup.d.ts +5 -2
  6. package/lib/server/devices/groups/presenceGroup.js +33 -25
  7. package/lib/server/devices/hmIPDevices/hmIpLampe.d.ts +2 -2
  8. package/lib/server/devices/hmIPDevices/hmIpLampe.js +12 -33
  9. package/lib/server/devices/index.d.ts +1 -0
  10. package/lib/server/devices/index.js +1 -0
  11. package/lib/server/devices/sharedFunctions/index.d.ts +1 -0
  12. package/lib/server/devices/sharedFunctions/index.js +17 -0
  13. package/lib/server/devices/sharedFunctions/lampUtils.d.ts +10 -0
  14. package/lib/server/devices/sharedFunctions/lampUtils.js +67 -0
  15. package/lib/server/devices/wledDevice.d.ts +8 -5
  16. package/lib/server/devices/wledDevice.js +23 -16
  17. package/lib/server/devices/zigbee/BaseDevices/ZigbeeActuator.d.ts +4 -4
  18. package/lib/server/devices/zigbee/BaseDevices/ZigbeeActuator.js +6 -16
  19. package/lib/server/devices/zigbee/BaseDevices/zigbeeDimmer.d.ts +6 -6
  20. package/lib/server/devices/zigbee/BaseDevices/zigbeeDimmer.js +19 -38
  21. package/lib/server/devices/zigbee/zigbeeIlluLampe.js +5 -23
  22. package/lib/server/devices/zigbee/zigbeeUbisysLampe.js +5 -24
  23. package/lib/server/services/govee/own-govee-device.d.ts +9 -8
  24. package/lib/server/services/govee/own-govee-device.js +31 -47
  25. package/lib/tsconfig.tsbuildinfo +1 -1
  26. package/package.json +1 -1
@@ -1,6 +1,7 @@
1
1
  import { LogLevel } from './logLevel';
2
+ import { LogDebugType } from '../server';
2
3
  export interface iIdHolder {
3
4
  readonly id: string;
4
5
  readonly customName: string;
5
- log(level: LogLevel, message: string): void;
6
+ log(level: LogLevel, message: string, logDebugType?: LogDebugType): void;
6
7
  }
@@ -1,14 +1,20 @@
1
1
  import { ActuatorSettings } from '../../../models';
2
2
  import { iRoomDevice } from './iRoomDevice';
3
- export interface iActuator extends iRoomDevice {
3
+ import { iTemporaryDisableAutomatic } from './iTemporaryDisableAutomatic';
4
+ export interface iActuator extends iRoomDevice, iTemporaryDisableAutomatic {
4
5
  /**
5
6
  * The settings for this Actuator primarily for controlling its automatic actions
6
7
  */
7
8
  settings: ActuatorSettings;
9
+ targetAutomaticState: boolean;
8
10
  /**
9
11
  * The state value of the device
10
12
  */
11
13
  readonly actuatorOn: boolean;
14
+ /**
15
+ * Queued value for the actuator
16
+ */
17
+ queuedValue: boolean | null;
12
18
  /**
13
19
  * Persisting the current states of this device to the database
14
20
  */
@@ -6,8 +6,10 @@ import { iDachsSettings } from '../../config/iDachsSettings';
6
6
  import { DachsDeviceSettings } from '../../../models/deviceSettings/dachsSettings';
7
7
  import { iFlattenedCompleteResponse } from './interfaces';
8
8
  import { DachsTemperatureSensor } from './dachsTemperatureSensor';
9
+ import { BlockAutomaticHandler } from '../../services/blockAutomaticHandler';
9
10
  export declare class Dachs implements iBaseDevice, iActuator {
10
11
  settings: DachsDeviceSettings;
12
+ readonly blockAutomationHandler: BlockAutomaticHandler;
11
13
  readonly deviceType: DeviceType;
12
14
  readonly deviceCapabilities: DeviceCapability[];
13
15
  readonly warmWaterSensor: DachsTemperatureSensor;
@@ -15,15 +17,18 @@ export declare class Dachs implements iBaseDevice, iActuator {
15
17
  private readonly client;
16
18
  private readonly config;
17
19
  fetchedData: iFlattenedCompleteResponse | undefined;
20
+ queuedValue: boolean | null;
18
21
  private readonly _influxClient;
19
22
  private _dachsOn;
20
23
  private _tempWarmWater;
21
24
  private _tempHeatStorage;
25
+ targetAutomaticState: boolean;
22
26
  get customName(): string;
23
27
  get actuatorOn(): boolean;
24
28
  get tempWarmWater(): number;
25
29
  get tempHeatStorage(): number;
26
30
  constructor(options: iDachsSettings);
31
+ restoreTargetAutomaticValue(): void;
27
32
  protected _info: DeviceInfo;
28
33
  get info(): DeviceInfo;
29
34
  set info(info: DeviceInfo);
@@ -36,6 +41,6 @@ export declare class Dachs implements iBaseDevice, iActuator {
36
41
  loadDeviceSettings(): void;
37
42
  private loadData;
38
43
  persist(): void;
39
- setActuator(pValue: boolean, _timeout?: number, _force?: boolean): void;
44
+ setActuator(pValue: boolean, timeout?: number, force?: boolean): void;
40
45
  toggleActuator(_force: boolean): boolean;
41
46
  }
@@ -12,6 +12,7 @@ const lodash_1 = __importDefault(require("lodash"));
12
12
  const dachsSettings_1 = require("../../../models/deviceSettings/dachsSettings");
13
13
  const lib_1 = require("./lib");
14
14
  const dachsTemperatureSensor_1 = require("./dachsTemperatureSensor");
15
+ const blockAutomaticHandler_1 = require("../../services/blockAutomaticHandler");
15
16
  class Dachs {
16
17
  get customName() {
17
18
  return this.info.customName;
@@ -29,9 +30,11 @@ class Dachs {
29
30
  this.settings = new dachsSettings_1.DachsDeviceSettings();
30
31
  this.deviceType = devices_1.DeviceType.Dachs;
31
32
  this.deviceCapabilities = [];
33
+ this.queuedValue = null;
32
34
  this._dachsOn = false;
33
35
  this._tempWarmWater = 0;
34
36
  this._tempHeatStorage = 0;
37
+ this.targetAutomaticState = false;
35
38
  this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.actuator);
36
39
  this._info = new devices_1.DeviceInfo();
37
40
  this._info.fullName = `Dachs`;
@@ -53,6 +56,11 @@ class Dachs {
53
56
  this.warmWaterSensor = new dachsTemperatureSensor_1.DachsTemperatureSensor(this.config.roomName, 'ww', 'Water Temperature');
54
57
  this.heatStorageTempSensor = new dachsTemperatureSensor_1.DachsTemperatureSensor(this.config.roomName, 'hs', 'Heat Storage Temperature');
55
58
  services_1.Utils.guardedInterval(this.loadData, this.config.refreshInterval, this);
59
+ this.blockAutomationHandler = new blockAutomaticHandler_1.BlockAutomaticHandler(this.restoreTargetAutomaticValue.bind(this));
60
+ }
61
+ restoreTargetAutomaticValue() {
62
+ this.log(models_1.LogLevel.Debug, `Restore Target Automatic value`);
63
+ this.setActuator(this.targetAutomaticState);
56
64
  }
57
65
  get info() {
58
66
  return this._info;
@@ -93,6 +101,7 @@ class Dachs {
93
101
  loadData() {
94
102
  this.client.fetchAllKeys().then((data) => {
95
103
  var _a, _b;
104
+ this.queuedValue = null;
96
105
  this.fetchedData = data;
97
106
  if (this._influxClient === undefined) {
98
107
  return;
@@ -118,12 +127,17 @@ class Dachs {
118
127
  var _a;
119
128
  (_a = services_1.Utils.dbo) === null || _a === void 0 ? void 0 : _a.persistActuator(this);
120
129
  }
121
- setActuator(pValue, _timeout, _force) {
130
+ setActuator(pValue, timeout, force) {
122
131
  if (!pValue || this._dachsOn) {
123
132
  // Dachs can only be turned on, not off
124
133
  return;
125
134
  }
135
+ const dontBlock = devices_1.LampUtils.checkUnBlock(this, force, pValue);
136
+ if (devices_1.LampUtils.checkBlockActive(this, force, pValue)) {
137
+ return;
138
+ }
126
139
  this.log(models_1.LogLevel.Debug, `Starting Dachs`);
140
+ this.queuedValue = pValue;
127
141
  this.client
128
142
  .setKeys({
129
143
  'Stromf_Ew.Anforderung_GLT.bAktiv': '1',
@@ -145,6 +159,9 @@ class Dachs {
145
159
  .catch((error) => {
146
160
  this.log(models_1.LogLevel.Error, `Error while turning on Dachs: ${error}`);
147
161
  });
162
+ if (timeout !== undefined && timeout > -1 && !dontBlock) {
163
+ this.blockAutomationHandler.disableAutomatic(timeout, models_1.CollisionSolving.overrideIfGreater);
164
+ }
148
165
  }
149
166
  toggleActuator(_force) {
150
167
  if (!this._dachsOn) {
@@ -3,18 +3,21 @@ import { iMotionSensor } from '../baseDeviceInterfaces';
3
3
  export declare class PresenceGroup extends BaseGroup {
4
4
  private _lastMovement;
5
5
  private _lastLeftTimeout;
6
+ private _lastLeftCbs;
7
+ private _firstEnterCbs;
6
8
  constructor(roomName: string, motionSensorIds: string[]);
7
9
  getMotionDetector(): Array<iMotionSensor>;
8
10
  initCallbacks(): void;
9
11
  presentAmount(): number;
10
12
  anyPresent(): boolean;
11
- lastLeftCB(val: boolean, cb: () => void): void;
12
13
  addLastLeftCallback(cb: () => void): void;
13
14
  addFirstEnterCallback(cb: () => void): void;
15
+ private motionSensorOnLastLeft;
14
16
  /**
15
17
  * In case of an existing delayed last left callback timeout, this removes it.
16
18
  * @private
17
19
  */
18
20
  private resetLastLeftTimeout;
19
- private firstEnterCallback;
21
+ private motionSensorOnFirstEnter;
22
+ private executeLastLeftCbs;
20
23
  }
@@ -12,6 +12,8 @@ class PresenceGroup extends base_group_1.BaseGroup {
12
12
  super(roomName, group_type_1.GroupType.Presence);
13
13
  this._lastMovement = new Date(0);
14
14
  this._lastLeftTimeout = null;
15
+ this._lastLeftCbs = [];
16
+ this._firstEnterCbs = [];
15
17
  this.deviceCluster.deviceMap.set(device_cluster_type_1.DeviceClusterType.MotionDetection, new device_list_1.DeviceList(motionSensorIds));
16
18
  }
17
19
  getMotionDetector() {
@@ -34,8 +36,9 @@ class PresenceGroup extends base_group_1.BaseGroup {
34
36
  });
35
37
  });
36
38
  this.addLastLeftCallback(() => {
37
- var _a;
38
- (_a = this.getRoom().LightGroup) === null || _a === void 0 ? void 0 : _a.switchAll(false);
39
+ var _a, _b;
40
+ (_a = this.getRoom().WindowGroup) === null || _a === void 0 ? void 0 : _a.changeVibrationMotionBlock(false);
41
+ (_b = this.getRoom().LightGroup) === null || _b === void 0 ? void 0 : _b.switchAll(false);
39
42
  });
40
43
  this.addFirstEnterCallback(() => {
41
44
  if (!this.getRoom().settings.lampenBeiBewegung) {
@@ -44,6 +47,16 @@ class PresenceGroup extends base_group_1.BaseGroup {
44
47
  this.log(models_1.LogLevel.DeepTrace, `Bewegung im Raum ${this.roomName} festgestellt --> Licht einschalten`);
45
48
  this.getRoom().setLightTimeBased();
46
49
  });
50
+ this.getMotionDetector().forEach((b) => {
51
+ b.addMovementCallback((val) => {
52
+ this.motionSensorOnFirstEnter(val);
53
+ });
54
+ });
55
+ this.getMotionDetector().forEach((b) => {
56
+ b.addMovementCallback((val) => {
57
+ this.motionSensorOnLastLeft(val);
58
+ });
59
+ });
47
60
  }
48
61
  presentAmount() {
49
62
  let count = 0;
@@ -62,8 +75,13 @@ class PresenceGroup extends base_group_1.BaseGroup {
62
75
  }
63
76
  return false;
64
77
  }
65
- lastLeftCB(val, cb) {
66
- var _a;
78
+ addLastLeftCallback(cb) {
79
+ this._lastLeftCbs.push(cb);
80
+ }
81
+ addFirstEnterCallback(cb) {
82
+ this._firstEnterCbs.push(cb);
83
+ }
84
+ motionSensorOnLastLeft(val) {
67
85
  if (val || this.anyPresent()) {
68
86
  this.resetLastLeftTimeout();
69
87
  return;
@@ -71,38 +89,21 @@ class PresenceGroup extends base_group_1.BaseGroup {
71
89
  let timeAfterReset = services_1.Utils.nowMS() - this._lastMovement.getTime() - this.getRoom().settings.movementResetTimer * 1000;
72
90
  if (timeAfterReset > 0) {
73
91
  this.log(models_1.LogLevel.Debug, `Movement reset. Active Motions: ${this.presentAmount()}\tTime after Last Movement including Reset: ${timeAfterReset}`);
74
- (_a = this.getRoom().WindowGroup) === null || _a === void 0 ? void 0 : _a.changeVibrationMotionBlock(false);
75
- cb();
92
+ this.executeLastLeftCbs();
76
93
  return;
77
94
  }
78
95
  this.log(models_1.LogLevel.Debug, `Movement reset in ${this.roomName} delayed.`);
79
96
  this.resetLastLeftTimeout();
80
97
  this._lastLeftTimeout = services_1.Utils.guardedTimeout(() => {
81
- var _a;
82
98
  timeAfterReset =
83
99
  services_1.Utils.nowMS() - this._lastMovement.getTime() - this.getRoom().settings.movementResetTimer * 1000;
84
100
  const presentAmount = this.presentAmount();
85
101
  this.log(models_1.LogLevel.Debug, `Delayed Movement reset. Active Motions: ${this.presentAmount()}\tTime after Last Movement including Reset: ${timeAfterReset}`);
86
102
  if (presentAmount <= 0 && timeAfterReset > 0) {
87
- (_a = this.getRoom().WindowGroup) === null || _a === void 0 ? void 0 : _a.changeVibrationMotionBlock(false);
88
- cb();
103
+ this.executeLastLeftCbs();
89
104
  }
90
105
  }, Math.abs(timeAfterReset) + 500, this);
91
106
  }
92
- addLastLeftCallback(cb) {
93
- this.getMotionDetector().forEach((b) => {
94
- b.addMovementCallback((val) => {
95
- this.lastLeftCB(val, cb);
96
- });
97
- });
98
- }
99
- addFirstEnterCallback(cb) {
100
- this.getMotionDetector().forEach((b) => {
101
- b.addMovementCallback((val) => {
102
- this.firstEnterCallback(val, cb);
103
- });
104
- });
105
- }
106
107
  /**
107
108
  * In case of an existing delayed last left callback timeout, this removes it.
108
109
  * @private
@@ -112,7 +113,7 @@ class PresenceGroup extends base_group_1.BaseGroup {
112
113
  clearTimeout(this._lastLeftTimeout);
113
114
  }
114
115
  }
115
- firstEnterCallback(val, cb) {
116
+ motionSensorOnFirstEnter(val) {
116
117
  if (!val) {
117
118
  return;
118
119
  }
@@ -120,7 +121,14 @@ class PresenceGroup extends base_group_1.BaseGroup {
120
121
  if (this.presentAmount() > 1) {
121
122
  return;
122
123
  }
123
- cb();
124
+ for (const cb of this._firstEnterCbs) {
125
+ cb();
126
+ }
127
+ }
128
+ executeLastLeftCbs() {
129
+ for (const cb of this._lastLeftCbs) {
130
+ cb();
131
+ }
124
132
  }
125
133
  }
126
134
  exports.PresenceGroup = PresenceGroup;
@@ -5,11 +5,11 @@ import { IoBrokerDeviceInfo } from '../IoBrokerDeviceInfo';
5
5
  import { BlockAutomaticHandler } from '../../services/blockAutomaticHandler';
6
6
  export declare class HmIpLampe extends HmIPDevice implements iLamp, iTemporaryDisableAutomatic {
7
7
  lightOn: boolean;
8
- queuedLightValue: boolean | null;
9
8
  settings: ActuatorSettings;
10
9
  private lightOnSwitchID;
11
10
  readonly blockAutomationHandler: BlockAutomaticHandler;
12
- private _targetAutomaticState;
11
+ queuedValue: boolean | null;
12
+ targetAutomaticState: boolean;
13
13
  constructor(pInfo: IoBrokerDeviceInfo);
14
14
  get actuatorOn(): boolean;
15
15
  restoreTargetAutomaticValue(): void;
@@ -7,14 +7,15 @@ const services_1 = require("../../services");
7
7
  const models_1 = require("../../../models");
8
8
  const DeviceCapability_1 = require("../DeviceCapability");
9
9
  const blockAutomaticHandler_1 = require("../../services/blockAutomaticHandler");
10
+ const sharedFunctions_1 = require("../sharedFunctions");
10
11
  class HmIpLampe extends hmIpDevice_1.HmIPDevice {
11
12
  constructor(pInfo) {
12
13
  super(pInfo, deviceType_1.DeviceType.HmIpLampe);
13
14
  this.lightOn = false;
14
- this.queuedLightValue = null;
15
15
  this.settings = new models_1.ActuatorSettings();
16
16
  this.lightOnSwitchID = '';
17
- this._targetAutomaticState = false;
17
+ this.queuedValue = null;
18
+ this.targetAutomaticState = false;
18
19
  this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.lamp);
19
20
  this.deviceCapabilities.push(DeviceCapability_1.DeviceCapability.blockAutomatic);
20
21
  this.lightOnSwitchID = `${this.info.fullID}.2.STATE`;
@@ -25,12 +26,12 @@ class HmIpLampe extends hmIpDevice_1.HmIPDevice {
25
26
  }
26
27
  restoreTargetAutomaticValue() {
27
28
  this.log(models_1.LogLevel.Debug, `Restore Target Automatic value`);
28
- this.setActuator(this._targetAutomaticState);
29
+ this.setActuator(this.targetAutomaticState);
29
30
  }
30
31
  update(idSplit, state, initial = false) {
31
32
  this.log(models_1.LogLevel.DeepTrace, `Lampen Update : ID: ${idSplit.join('.')} JSON: ${JSON.stringify(state)}`);
33
+ this.queuedValue = null;
32
34
  super.update(idSplit, state, initial, true);
33
- this.queuedLightValue = null;
34
35
  switch (idSplit[3]) {
35
36
  case '1':
36
37
  if (idSplit[4] === 'STATE') {
@@ -48,13 +49,10 @@ class HmIpLampe extends hmIpDevice_1.HmIPDevice {
48
49
  }
49
50
  /** @inheritdoc */
50
51
  setLight(pValue, timeout = -1, force = false) {
51
- if (!force && this.blockAutomationHandler.automaticBlockActive) {
52
- this.log(models_1.LogLevel.Debug, `Skip automatic command to ${pValue} as it is locked until ${new Date(this.blockAutomationHandler.automaticBlockedUntil).toLocaleTimeString()}`);
53
- this._targetAutomaticState = pValue;
52
+ if (sharedFunctions_1.LampUtils.checkBlockActive(this, force, pValue)) {
54
53
  return;
55
54
  }
56
- if (!force && pValue === this.lightOn && this.queuedLightValue === null) {
57
- this.log(models_1.LogLevel.DeepTrace, `Skip light command as it is already ${pValue}`, services_1.LogDebugType.SkipUnchangedActuatorCommand);
55
+ if (sharedFunctions_1.LampUtils.checkUnchanged(this, force, pValue)) {
58
56
  return;
59
57
  }
60
58
  if (this.lightOnSwitchID === '') {
@@ -62,18 +60,13 @@ class HmIpLampe extends hmIpDevice_1.HmIPDevice {
62
60
  return;
63
61
  }
64
62
  this.log(models_1.LogLevel.Debug, `Set Light Acutator to "${pValue}"`, services_1.LogDebugType.SetActuator);
63
+ this.queuedValue = pValue;
65
64
  this.setState(this.lightOnSwitchID, pValue, undefined, (err) => {
66
65
  this.log(models_1.LogLevel.Error, `Lampe schalten ergab Fehler: ${err}`);
67
66
  });
68
- this.queuedLightValue = pValue;
69
- if (this.settings.isStromStoss) {
67
+ if (this.settings.isStromStoss && pValue) {
70
68
  timeout = 3000;
71
- services_1.Utils.guardedTimeout(() => {
72
- var _a;
73
- if ((_a = this.room.PraesenzGroup) === null || _a === void 0 ? void 0 : _a.anyPresent()) {
74
- this.setLight(true, -1, true);
75
- }
76
- }, this.settings.stromStossResendTime * 1000, this);
69
+ sharedFunctions_1.LampUtils.stromStossOn(this);
77
70
  }
78
71
  if (timeout < 0 || !pValue) {
79
72
  return;
@@ -83,24 +76,10 @@ class HmIpLampe extends hmIpDevice_1.HmIPDevice {
83
76
  }
84
77
  }
85
78
  toggleLight(time, force = false, calculateTime = false) {
86
- const newVal = this.queuedLightValue !== null ? !this.queuedLightValue : !this.lightOn;
87
- const timeout = newVal && force ? 30 * 60 * 1000 : -1;
88
- if (newVal && time === undefined && calculateTime) {
89
- time = services_1.TimeCallbackService.dayType(this.room.settings.lampOffset);
90
- }
91
- if (newVal && time !== undefined) {
92
- this.setTimeBased(time, timeout, force);
93
- return true;
94
- }
95
- this.setLight(newVal, timeout, force);
96
- return newVal;
79
+ return sharedFunctions_1.LampUtils.toggleLight(this, time, force, calculateTime);
97
80
  }
98
81
  setTimeBased(time, timeout = -1, force = false) {
99
- if ((time === models_1.TimeOfDay.Night && this.settings.nightOn) ||
100
- (time === models_1.TimeOfDay.BeforeSunrise && this.settings.dawnOn) ||
101
- (time === models_1.TimeOfDay.AfterSunset && this.settings.duskOn)) {
102
- this.setLight(true, timeout, force);
103
- }
82
+ sharedFunctions_1.LampUtils.setTimeBased(this, time, timeout, force);
104
83
  }
105
84
  persist() {
106
85
  var _a;
@@ -7,6 +7,7 @@ export * from './hmIPDevices/index';
7
7
  export * from './jsObject/index';
8
8
  export * from './models/index';
9
9
  export * from './scene/index';
10
+ export * from './sharedFunctions/index';
10
11
  export * from './shelly/index';
11
12
  export * from './tuya/index';
12
13
  export * from './zigbee/index';
@@ -23,6 +23,7 @@ __exportStar(require("./hmIPDevices/index"), exports);
23
23
  __exportStar(require("./jsObject/index"), exports);
24
24
  __exportStar(require("./models/index"), exports);
25
25
  __exportStar(require("./scene/index"), exports);
26
+ __exportStar(require("./sharedFunctions/index"), exports);
26
27
  __exportStar(require("./shelly/index"), exports);
27
28
  __exportStar(require("./tuya/index"), exports);
28
29
  __exportStar(require("./zigbee/index"), exports);
@@ -0,0 +1 @@
1
+ export * from './lampUtils';
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./lampUtils"), exports);
@@ -0,0 +1,10 @@
1
+ import { iActuator, iLamp } from '../baseDeviceInterfaces';
2
+ import { TimeOfDay } from '../../../models';
3
+ export declare class LampUtils {
4
+ static stromStossOn(lamp: iLamp): void;
5
+ static setTimeBased(device: iLamp, time: TimeOfDay, timeout: number, force: boolean): void;
6
+ static checkUnBlock(device: iActuator, force: boolean | undefined, pValue: boolean): boolean;
7
+ static toggleLight(device: iLamp, time: TimeOfDay | undefined, force: boolean, calculateTime: boolean): boolean;
8
+ static checkBlockActive(device: iActuator, force: boolean | undefined, pValue: boolean): boolean;
9
+ static checkUnchanged(device: iActuator, force: boolean, pValue: boolean): boolean;
10
+ }
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LampUtils = void 0;
4
+ const services_1 = require("../../services");
5
+ const models_1 = require("../../../models");
6
+ class LampUtils {
7
+ static stromStossOn(lamp) {
8
+ services_1.Utils.guardedTimeout(() => {
9
+ var _a, _b;
10
+ if ((_b = (_a = lamp.room) === null || _a === void 0 ? void 0 : _a.PraesenzGroup) === null || _b === void 0 ? void 0 : _b.anyPresent()) {
11
+ lamp.setLight(true, -1, true);
12
+ }
13
+ }, lamp.settings.stromStossResendTime * 1000, this);
14
+ services_1.Utils.guardedTimeout(() => {
15
+ lamp.setLight(false, -1, true);
16
+ }, 3000, this);
17
+ }
18
+ static setTimeBased(device, time, timeout, force) {
19
+ if ((time === models_1.TimeOfDay.Night && device.settings.nightOn) ||
20
+ (time === models_1.TimeOfDay.BeforeSunrise && device.settings.dawnOn) ||
21
+ (time === models_1.TimeOfDay.AfterSunset && device.settings.duskOn)) {
22
+ device.setLight(true, timeout, force);
23
+ }
24
+ }
25
+ static checkUnBlock(device, force, pValue) {
26
+ let dontBlock = false;
27
+ if (force &&
28
+ device.settings.resetToAutomaticOnForceOffAfterForceOn &&
29
+ !pValue &&
30
+ device.blockAutomationHandler.automaticBlockActive) {
31
+ dontBlock = true;
32
+ device.log(models_1.LogLevel.Debug, `Reset Automatic Block as we are turning off manually after a force on`);
33
+ device.blockAutomationHandler.liftAutomaticBlock();
34
+ }
35
+ return dontBlock;
36
+ }
37
+ static toggleLight(device, time, force, calculateTime) {
38
+ var _a;
39
+ const newVal = device.queuedValue !== null ? !device.queuedValue : !device.lightOn;
40
+ const timeout = newVal && force ? 30 * 60 * 1000 : -1;
41
+ if (newVal && time === undefined && calculateTime && device.room !== undefined) {
42
+ time = services_1.TimeCallbackService.dayType((_a = device.room) === null || _a === void 0 ? void 0 : _a.settings.lampOffset);
43
+ }
44
+ if (newVal && time !== undefined) {
45
+ device.setTimeBased(time, timeout, force);
46
+ return true;
47
+ }
48
+ device.setLight(newVal, timeout, force);
49
+ return newVal;
50
+ }
51
+ static checkBlockActive(device, force, pValue) {
52
+ if (!force && device.blockAutomationHandler.automaticBlockActive) {
53
+ device.log(models_1.LogLevel.Debug, `Skip automatic command to ${pValue} as it is locked until ${new Date(device.blockAutomationHandler.automaticBlockedUntil).toLocaleTimeString()}`);
54
+ device.targetAutomaticState = pValue;
55
+ return true;
56
+ }
57
+ return false;
58
+ }
59
+ static checkUnchanged(device, force, pValue) {
60
+ if (!force && pValue === device.actuatorOn && device.queuedValue === null) {
61
+ device.log(models_1.LogLevel.DeepTrace, `Skip light command as it is already ${pValue}`, services_1.LogDebugType.SkipUnchangedActuatorCommand);
62
+ return true;
63
+ }
64
+ return false;
65
+ }
66
+ }
67
+ exports.LampUtils = LampUtils;
@@ -2,25 +2,28 @@ import { IoBrokerBaseDevice } from './IoBrokerBaseDevice';
2
2
  import { TimeOfDay, WledSettings } from '../../models';
3
3
  import { IoBrokerDeviceInfo } from './IoBrokerDeviceInfo';
4
4
  import { iDimmableLamp } from './baseDeviceInterfaces/iDimmableLamp';
5
+ import { BlockAutomaticHandler } from '../services/blockAutomaticHandler';
5
6
  export declare class WledDevice extends IoBrokerBaseDevice implements iDimmableLamp {
6
7
  on: boolean;
7
8
  brightness: number;
8
- linkQuality: number;
9
9
  battery: number;
10
- voltage: string;
10
+ queuedValue: boolean | null;
11
11
  settings: WledSettings;
12
+ readonly blockAutomationHandler: BlockAutomaticHandler;
13
+ targetAutomaticState: boolean;
12
14
  private readonly _onID;
13
15
  private readonly _presetID;
14
16
  private readonly _brightnessID;
15
17
  constructor(pInfo: IoBrokerDeviceInfo);
16
18
  get actuatorOn(): boolean;
17
19
  get lightOn(): boolean;
20
+ restoreTargetAutomaticValue(): void;
18
21
  update(idSplit: string[], state: ioBroker.State, initial?: boolean, _pOverride?: boolean): void;
19
- setLight(pValue: boolean, _timeout?: number, _force?: boolean, brightness?: number, _transitionTime?: number): void;
20
- setWled(pValue: boolean, brightness?: number, preset?: number): void;
22
+ setLight(pValue: boolean, timeout?: number, force?: boolean, brightness?: number, _transitionTime?: number): void;
23
+ setWled(pValue: boolean, brightness?: number, preset?: number, timeout?: number, force?: boolean): void;
21
24
  setTimeBased(time: TimeOfDay): void;
22
25
  persist(): void;
23
26
  setActuator(pValue: boolean, _timeout?: number, _force?: boolean): void;
24
27
  toggleActuator(_force: boolean): boolean;
25
- toggleLight(time?: TimeOfDay, _force?: boolean, calculateTime?: boolean): boolean;
28
+ toggleLight(time?: TimeOfDay, force?: boolean, calculateTime?: boolean): boolean;
26
29
  }
@@ -5,18 +5,21 @@ const IoBrokerBaseDevice_1 = require("./IoBrokerBaseDevice");
5
5
  const deviceType_1 = require("./deviceType");
6
6
  const services_1 = require("../services");
7
7
  const models_1 = require("../../models");
8
+ const blockAutomaticHandler_1 = require("../services/blockAutomaticHandler");
9
+ const sharedFunctions_1 = require("./sharedFunctions");
8
10
  class WledDevice extends IoBrokerBaseDevice_1.IoBrokerBaseDevice {
9
11
  constructor(pInfo) {
10
12
  super(pInfo, deviceType_1.DeviceType.WledDevice);
11
13
  this.on = false;
12
14
  this.brightness = -1;
13
- this.linkQuality = 0;
14
15
  this.battery = -1;
15
- this.voltage = '';
16
+ this.queuedValue = null;
16
17
  this.settings = new models_1.WledSettings();
18
+ this.targetAutomaticState = false;
17
19
  this._onID = `${this.info.fullID}.on`;
18
20
  this._presetID = `${this.info.fullID}.ps`;
19
21
  this._brightnessID = `${this.info.fullID}.bri`;
22
+ this.blockAutomationHandler = new blockAutomaticHandler_1.BlockAutomaticHandler(this.restoreTargetAutomaticValue.bind(this));
20
23
  }
21
24
  get actuatorOn() {
22
25
  return this.on;
@@ -24,7 +27,12 @@ class WledDevice extends IoBrokerBaseDevice_1.IoBrokerBaseDevice {
24
27
  get lightOn() {
25
28
  return this.on;
26
29
  }
30
+ restoreTargetAutomaticValue() {
31
+ this.log(models_1.LogLevel.Debug, `Restore Target Automatic value`);
32
+ this.setActuator(this.targetAutomaticState);
33
+ }
27
34
  update(idSplit, state, initial = false, _pOverride = false) {
35
+ this.queuedValue = null;
28
36
  services_1.ServerLogService.writeLog(models_1.LogLevel.DeepTrace, `Wled: ${initial ? 'Initiales ' : ''}Update für "${this.info.customName}": ID: ${idSplit.join('.')} JSON: ${JSON.stringify(state)}`);
29
37
  switch (idSplit[3]) {
30
38
  case 'on':
@@ -35,10 +43,10 @@ class WledDevice extends IoBrokerBaseDevice_1.IoBrokerBaseDevice {
35
43
  break;
36
44
  }
37
45
  }
38
- setLight(pValue, _timeout, _force, brightness, _transitionTime) {
39
- this.setWled(pValue, brightness);
46
+ setLight(pValue, timeout, force, brightness, _transitionTime) {
47
+ this.setWled(pValue, brightness, undefined, timeout, force);
40
48
  }
41
- setWled(pValue, brightness = -1, preset) {
49
+ setWled(pValue, brightness = -1, preset, timeout, force) {
42
50
  if (this._onID === '') {
43
51
  services_1.ServerLogService.writeLog(models_1.LogLevel.Error, `Keine On ID für "${this.info.customName}" bekannt.`);
44
52
  return;
@@ -47,10 +55,15 @@ class WledDevice extends IoBrokerBaseDevice_1.IoBrokerBaseDevice {
47
55
  services_1.ServerLogService.writeLog(models_1.LogLevel.Error, `Keine Connection für "${this.info.customName}" bekannt.`);
48
56
  return;
49
57
  }
58
+ const dontBlock = sharedFunctions_1.LampUtils.checkUnBlock(this, force, pValue);
59
+ if (sharedFunctions_1.LampUtils.checkBlockActive(this, force, pValue)) {
60
+ return;
61
+ }
50
62
  if (pValue && brightness !== -1 && this.brightness < 10) {
51
63
  brightness = 10;
52
64
  }
53
65
  services_1.ServerLogService.writeLog(models_1.LogLevel.Debug, `WLED Schalten: "${this.info.customName}" An: ${pValue}\tHelligkeit: ${brightness}%`);
66
+ this.queuedValue = pValue;
54
67
  this.setState(this._onID, pValue, undefined, (err) => {
55
68
  services_1.ServerLogService.writeLog(models_1.LogLevel.Error, `WLED schalten ergab Fehler: ${err}`);
56
69
  });
@@ -64,6 +77,9 @@ class WledDevice extends IoBrokerBaseDevice_1.IoBrokerBaseDevice {
64
77
  services_1.ServerLogService.writeLog(models_1.LogLevel.Error, `Dimmer Helligkeit schalten ergab Fehler: ${err}`);
65
78
  });
66
79
  }
80
+ if (timeout !== undefined && timeout > -1 && !dontBlock) {
81
+ this.blockAutomationHandler.disableAutomatic(timeout, models_1.CollisionSolving.overrideIfGreater);
82
+ }
67
83
  }
68
84
  setTimeBased(time) {
69
85
  this.log(models_1.LogLevel.Debug, `Wled setTimeBased ${time}`);
@@ -101,17 +117,8 @@ class WledDevice extends IoBrokerBaseDevice_1.IoBrokerBaseDevice {
101
117
  this.setLight(!this.on);
102
118
  return this.on;
103
119
  }
104
- toggleLight(time, _force = false, calculateTime = false) {
105
- const newVal = !this.lightOn;
106
- if (newVal && time === undefined && calculateTime) {
107
- time = services_1.TimeCallbackService.dayType(this.room.settings.lampOffset);
108
- }
109
- if (newVal && time !== undefined) {
110
- this.setTimeBased(time);
111
- return true;
112
- }
113
- this.setLight(newVal);
114
- return newVal;
120
+ toggleLight(time, force = false, calculateTime = false) {
121
+ return sharedFunctions_1.LampUtils.toggleLight(this, time, force, calculateTime);
115
122
  }
116
123
  }
117
124
  exports.WledDevice = WledDevice;