hoffmation-base 3.0.0-alpha.16 → 3.0.0-alpha.17

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.
@@ -11,7 +11,7 @@ class ActuatorSetStateCommand extends baseCommand_1.BaseCommand {
11
11
  this._commandType = commandType_1.CommandType.ActuatorSetStateCommand;
12
12
  }
13
13
  get logMessage() {
14
- return `Actuator setState to ${this.on} for reason: ${this.reasonTrace}`;
14
+ return `Actuator setState to ${this.on} with timeout ${this.timeout} for reason: ${this.reasonTrace}`;
15
15
  }
16
16
  static byActuatorAndToggleCommand(device, c) {
17
17
  const newVal = device.queuedValue !== null ? !device.queuedValue : !device.actuatorOn;
@@ -20,7 +20,7 @@ class DimmerSetLightCommand extends lampSetLightCommand_1.LampSetLightCommand {
20
20
  this._commandType = commandType_1.CommandType.DimmerSetLightCommand;
21
21
  }
22
22
  get logMessage() {
23
- return `Dimmer setLight to ${this.on} for reason: ${this.reasonTrace}`;
23
+ return `Dimmer setLight to ${this.on} with Brightness ${this.brightness} with timeout ${this.timeout} for reason: ${this.reasonTrace}`;
24
24
  }
25
25
  static byTimeBased(s, c) {
26
26
  const manual = c.isForceAction;
@@ -9,7 +9,7 @@ class LampSetLightCommand extends actuatorSetStateCommand_1.ActuatorSetStateComm
9
9
  this._commandType = commandType_1.CommandType.LampSetLightCommand;
10
10
  }
11
11
  get logMessage() {
12
- return `Lamp setLight to ${this.on} for reason: ${this.reasonTrace}`;
12
+ return `Lamp setLight to ${this.on} with timeout ${this.timeout} for reason: ${this.reasonTrace}`;
13
13
  }
14
14
  }
15
15
  exports.LampSetLightCommand = LampSetLightCommand;
@@ -8,5 +8,6 @@ export declare class WledSetLightCommand extends DimmerSetLightCommand {
8
8
  preset?: number | undefined;
9
9
  _commandType: CommandType;
10
10
  constructor(source: CommandSource | BaseCommand, on: boolean, reason?: string, timeout?: number, brightness?: number, transitionTime?: number, preset?: number | undefined);
11
+ get logMessage(): string;
11
12
  static byTimeBased(settings: WledSettings, c: LampSetTimeBasedCommand): WledSetLightCommand;
12
13
  }
@@ -10,6 +10,9 @@ class WledSetLightCommand extends dimmerSetLightCommand_1.DimmerSetLightCommand
10
10
  this.preset = preset;
11
11
  this._commandType = commandType_1.CommandType.WledSetLightCommand;
12
12
  }
13
+ get logMessage() {
14
+ return `Dimmer setLight to ${this.on} with Brightness ${this.brightness}, timeout ${this.timeout} and preset ${this.preset} for reason: ${this.reasonTrace}`;
15
+ }
13
16
  static byTimeBased(settings, c) {
14
17
  switch (c.time) {
15
18
  case timeCallback_1.TimeOfDay.Daylight:
@@ -14,6 +14,8 @@ export declare abstract class IoBrokerBaseDevice implements iRoomDevice {
14
14
  };
15
15
  private _room;
16
16
  readonly deviceCapabilities: DeviceCapability[];
17
+ protected _debounceStateDelay: number;
18
+ protected _lastWrite: number;
17
19
  get customName(): string;
18
20
  get room(): RoomBase;
19
21
  protected readonly individualStateCallbacks: Map<string, Array<(val: ioBroker.StateValue) => void>>;
@@ -20,6 +20,9 @@ class IoBrokerBaseDevice {
20
20
  this.settings = undefined;
21
21
  this._room = undefined;
22
22
  this.deviceCapabilities = [];
23
+ // If configured > 0, this indicates the minimum time between state writes in ms
24
+ this._debounceStateDelay = 0;
25
+ this._lastWrite = 0;
23
26
  this.individualStateCallbacks = new Map();
24
27
  this.addToCorrectRoom();
25
28
  this.persistDeviceInfo();
@@ -152,13 +155,21 @@ class IoBrokerBaseDevice {
152
155
  if (!this.checkIoConnection(true)) {
153
156
  return;
154
157
  }
158
+ if (this._debounceStateDelay > 0 && services_1.Utils.nowMS() - this._lastWrite < this._debounceStateDelay) {
159
+ services_1.Utils.guardedTimeout(() => {
160
+ this.log(models_1.LogLevel.Trace, `Debounced write for ${pointId} to ${state}`);
161
+ this.setState(pointId, state, onSuccess, onError);
162
+ }, this._debounceStateDelay, this);
163
+ return;
164
+ }
165
+ this._lastWrite = services_1.Utils.nowMS();
155
166
  (_a = this.ioConn) === null || _a === void 0 ? void 0 : _a.setState(pointId, state, (err) => {
156
167
  if (err) {
157
168
  if (onError) {
158
169
  onError(err);
159
170
  }
160
171
  else {
161
- console.log(`Error occured while setting state "${pointId}" to "${state}": ${err}`);
172
+ this.log(models_1.LogLevel.Error, `Error occured while setting state "${pointId}" to "${state}": ${err}`);
162
173
  }
163
174
  return;
164
175
  }
@@ -11,6 +11,7 @@ export declare class WledDevice extends IoBrokerBaseDevice implements iDimmableL
11
11
  settings: WledSettings;
12
12
  readonly blockAutomationHandler: BlockAutomaticHandler;
13
13
  targetAutomaticState: boolean;
14
+ protected readonly _debounceStateDelay: number;
14
15
  private readonly _onID;
15
16
  private readonly _presetID;
16
17
  private readonly _brightnessID;
@@ -17,6 +17,7 @@ class WledDevice extends IoBrokerBaseDevice_1.IoBrokerBaseDevice {
17
17
  this.queuedValue = null;
18
18
  this.settings = new models_1.WledSettings();
19
19
  this.targetAutomaticState = false;
20
+ this._debounceStateDelay = 500;
20
21
  this._onID = `${this.info.fullID}.on`;
21
22
  this._presetID = `${this.info.fullID}.ps`;
22
23
  this._brightnessID = `${this.info.fullID}.bri`;
@@ -49,7 +50,6 @@ class WledDevice extends IoBrokerBaseDevice_1.IoBrokerBaseDevice {
49
50
  this.setWled(new models_1.WledSetLightCommand(c, c.on, 'Set Wled due to DimmerSetLightCommand', c.timeout, c.brightness, c.transitionTime, undefined));
50
51
  }
51
52
  setWled(c) {
52
- this.log(models_1.LogLevel.Debug, c.logMessage);
53
53
  if (this._onID === '') {
54
54
  services_1.ServerLogService.writeLog(models_1.LogLevel.Error, `Keine On ID für "${this.info.customName}" bekannt.`);
55
55
  return;
@@ -62,13 +62,13 @@ class WledDevice extends IoBrokerBaseDevice_1.IoBrokerBaseDevice {
62
62
  if (sharedFunctions_1.LampUtils.checkBlockActive(this, c)) {
63
63
  return;
64
64
  }
65
+ this.log(models_1.LogLevel.Debug, c.logMessage);
65
66
  if (c.on && c.brightness !== -1 && this.brightness < 10) {
66
67
  c.brightness = 10;
67
68
  }
68
- services_1.ServerLogService.writeLog(models_1.LogLevel.Debug, `WLED Schalten: "${this.info.customName}" An: ${c.on}\tHelligkeit: ${c.brightness}%`);
69
69
  this.queuedValue = c.on;
70
- this.writeActuatorStateToDevice(new models_1.ActuatorWriteStateToDeviceCommand(c, c.on, 'WLED Schalten'));
71
70
  if (c.preset !== undefined) {
71
+ // Warning: This also turns the device on
72
72
  this.setState(this._presetID, c.preset, undefined, (err) => {
73
73
  services_1.ServerLogService.writeLog(models_1.LogLevel.Error, `WLED schalten ergab Fehler: ${err}`);
74
74
  });
@@ -78,12 +78,12 @@ class WledDevice extends IoBrokerBaseDevice_1.IoBrokerBaseDevice {
78
78
  services_1.ServerLogService.writeLog(models_1.LogLevel.Error, `Dimmer Helligkeit schalten ergab Fehler: ${err}`);
79
79
  });
80
80
  }
81
+ this.writeActuatorStateToDevice(new models_1.ActuatorWriteStateToDeviceCommand(c, c.on, 'WLED Schalten'));
81
82
  if (c.timeout !== undefined && c.timeout > -1 && !dontBlock) {
82
83
  this.blockAutomationHandler.disableAutomatic(c.timeout, models_1.CollisionSolving.overrideIfGreater);
83
84
  }
84
85
  }
85
86
  setTimeBased(c) {
86
- this.log(models_1.LogLevel.Debug, `Wled setTimeBased ${c.time}`);
87
87
  this.setWled(models_1.WledSetLightCommand.byTimeBased(this.settings, c));
88
88
  }
89
89
  persist() {
@@ -6,8 +6,6 @@ import { iDisposable } from '../../../services';
6
6
  export declare class ZigbeeDevice extends IoBrokerBaseDevice implements iDisposable {
7
7
  protected _available: boolean;
8
8
  protected _dontSendOnUnavailable: boolean;
9
- protected _debounceStateDelay: number;
10
- private _lastWrite;
11
9
  private readonly _deviceQueryId;
12
10
  get available(): boolean;
13
11
  protected _linkQuality: number;
@@ -18,9 +18,6 @@ class ZigbeeDevice extends IoBrokerBaseDevice_1.IoBrokerBaseDevice {
18
18
  super(pInfo, pType);
19
19
  this._available = false;
20
20
  this._dontSendOnUnavailable = false;
21
- // If configured > 0, this indicates the minimum time between state writes in ms
22
- this._debounceStateDelay = 0;
23
- this._lastWrite = 0;
24
21
  this._linkQuality = 0;
25
22
  this.persistZigbeeInterval = services_1.Utils.guardedInterval(() => {
26
23
  this.persistZigbeeDevice();
@@ -78,15 +75,7 @@ class ZigbeeDevice extends IoBrokerBaseDevice_1.IoBrokerBaseDevice {
78
75
  this.log(models_1.LogLevel.Warn, `Device unavailable --> Not changing ${pointId} to ${state}`);
79
76
  return;
80
77
  }
81
- if (this._debounceStateDelay === 0 || services_1.Utils.nowMS() - this._lastWrite > this._debounceStateDelay) {
82
- this._lastWrite = services_1.Utils.nowMS();
83
- super.setState(pointId, state, onSuccess, onError);
84
- return;
85
- }
86
- services_1.Utils.guardedTimeout(() => {
87
- this.log(models_1.LogLevel.Trace, `Debounced write to ${pointId} to ${state}`);
88
- this.setState(pointId, state, onSuccess, onError);
89
- }, this._debounceStateDelay, this);
78
+ super.setState(pointId, state, onSuccess, onError);
90
79
  }
91
80
  }
92
81
  exports.ZigbeeDevice = ZigbeeDevice;