hoffmation-base 3.4.8 → 3.5.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 (37) hide show
  1. package/lib/api/api-service.d.ts +9 -12
  2. package/lib/api/api-service.js +13 -28
  3. package/lib/command/acPerformAutomaticCheckCommand.d.ts +18 -0
  4. package/lib/command/acPerformAutomaticCheckCommand.js +25 -0
  5. package/lib/command/acSetStateCommand.d.ts +34 -0
  6. package/lib/command/acSetStateCommand.js +40 -0
  7. package/lib/command/acWriteStateToDeviceCommand.d.ts +25 -0
  8. package/lib/command/acWriteStateToDeviceCommand.js +30 -0
  9. package/lib/command/excessEnergyConsumerSetStateCommand.d.ts +19 -0
  10. package/lib/command/excessEnergyConsumerSetStateCommand.js +26 -0
  11. package/lib/command/index.d.ts +4 -0
  12. package/lib/command/index.js +9 -1
  13. package/lib/devices/groups/heatGroup.d.ts +6 -3
  14. package/lib/devices/groups/heatGroup.js +10 -9
  15. package/lib/devices/groups/lightGroup.d.ts +13 -0
  16. package/lib/devices/groups/lightGroup.js +32 -2
  17. package/lib/devices/groups/tasterGroup.js +5 -2
  18. package/lib/devices/jsObject/jsObjectEnergyManager.js +3 -4
  19. package/lib/devices/tv/tvDevice.d.ts +2 -1
  20. package/lib/devices/tv/tvDevice.js +5 -1
  21. package/lib/devices/victron/victron-device.js +3 -4
  22. package/lib/devices/zigbee/zigbeeBlitzShp.d.ts +2 -3
  23. package/lib/devices/zigbee/zigbeeBlitzShp.js +5 -7
  24. package/lib/enums/commandType.d.ts +4 -0
  25. package/lib/enums/commandType.js +4 -0
  26. package/lib/interfaces/baseDevices/iAcDevice.d.ts +14 -4
  27. package/lib/interfaces/baseDevices/iExcessEnergyConsumer.d.ts +7 -6
  28. package/lib/interfaces/groups/iHeatGroup.d.ts +4 -3
  29. package/lib/services/ac/ac-device.d.ts +27 -13
  30. package/lib/services/ac/ac-device.js +69 -32
  31. package/lib/services/ac/daikin-service.d.ts +2 -1
  32. package/lib/services/ac/daikin-service.js +8 -13
  33. package/lib/services/ac/own-daikin-device.d.ts +4 -3
  34. package/lib/services/ac/own-daikin-device.js +6 -6
  35. package/lib/tsconfig.tsbuildinfo +1 -1
  36. package/lib/utils/ringStorage.js +7 -2
  37. package/package.json +1 -1
@@ -75,13 +75,11 @@ class ZigbeeBlitzShp extends BaseDevices_1.ZigbeeActuator {
75
75
  }
76
76
  }
77
77
  /** @inheritDoc */
78
- turnOnForExcessEnergy() {
79
- this._activatedByExcessEnergy = true;
80
- this.setActuator(new command_1.ActuatorSetStateCommand(enums_1.CommandSource.Automatic, true, 'Turn on for excess energy'));
81
- }
82
- /** @inheritDoc */
83
- turnOffDueToMissingEnergy() {
84
- this.setActuator(new command_1.ActuatorSetStateCommand(enums_1.CommandSource.Automatic, false, 'Turn off due to missing energy'));
78
+ setExcessEnergyState(c) {
79
+ if (c.on) {
80
+ this._activatedByExcessEnergy = true;
81
+ }
82
+ this.setActuator(new command_1.ActuatorSetStateCommand(c, c.on, c.on ? 'Turn on for excess energy' : 'Turn off due to missing energy'));
85
83
  }
86
84
  /** @inheritDoc */
87
85
  wasActivatedByExcessEnergy() {
@@ -1,4 +1,8 @@
1
1
  export declare enum CommandType {
2
+ AcPerformAutomaticCheckCommand = "AcPerformAutomaticCheckCommand",
3
+ ExcessEnergyConsumerSetStateCommand = "ExcessEnergyConsumerSetStateCommand",
4
+ AcSetStateCommand = "AcSetStateCommand",
5
+ AcWriteStateToDeviceCommand = "AcWriteStateToDeviceCommand",
2
6
  ActuatorChangeAction = "ActuatorChangeAction",
3
7
  BatteryManagerLevelChangeAction = "BatteryManagerLevelChangeAction",
4
8
  BlockAutomaticLiftBlockCommand = "BlockAutomaticLiftBlockCommand",
@@ -3,6 +3,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.CommandType = void 0;
4
4
  var CommandType;
5
5
  (function (CommandType) {
6
+ CommandType["AcPerformAutomaticCheckCommand"] = "AcPerformAutomaticCheckCommand";
7
+ CommandType["ExcessEnergyConsumerSetStateCommand"] = "ExcessEnergyConsumerSetStateCommand";
8
+ CommandType["AcSetStateCommand"] = "AcSetStateCommand";
9
+ CommandType["AcWriteStateToDeviceCommand"] = "AcWriteStateToDeviceCommand";
6
10
  CommandType["ActuatorChangeAction"] = "ActuatorChangeAction";
7
11
  CommandType["BatteryManagerLevelChangeAction"] = "BatteryManagerLevelChangeAction";
8
12
  CommandType["BlockAutomaticLiftBlockCommand"] = "BlockAutomaticLiftBlockCommand";
@@ -1,11 +1,11 @@
1
1
  import { iAcSettings } from '../deviceSettings';
2
2
  import { iBaseDevice } from './iBaseDevice';
3
3
  import { AcMode } from '../../enums';
4
+ import { AcSetStateCommand, AcWriteStateToDeviceCommand } from '../../command';
4
5
  /**
5
6
  * Interface for normal air-conditioning devices
6
7
  *
7
8
  * For devices with {@link DeviceCapability.ac} capability.
8
- * TODO: Migrate to new Command-Based System
9
9
  * TODO: Extend from iActuator
10
10
  */
11
11
  export interface iAcDevice extends iBaseDevice {
@@ -48,21 +48,31 @@ export interface iAcDevice extends iBaseDevice {
48
48
  * @param writeToDevice - Whether to write the new mode to the device
49
49
  */
50
50
  setDesiredMode(mode: AcMode, writeToDevice: boolean): void;
51
+ /**
52
+ * Performs a power write, applying any automatic block the command carries
53
+ * @param c - The command to execute
54
+ */
55
+ writeStateToDevice(c: AcWriteStateToDeviceCommand): void;
51
56
  /**
52
57
  * Turns the air-conditioning device on without changing the settings
58
+ * @param c - The command to execute
53
59
  */
54
- turnOn(): void;
60
+ turnOn(c: AcWriteStateToDeviceCommand): void;
55
61
  /**
56
62
  * Turns the air-conditioning device off
63
+ * @param c - The command to execute
57
64
  */
58
- turnOff(): void;
65
+ turnOff(c: AcWriteStateToDeviceCommand): void;
59
66
  /**
60
67
  * Calculates the desired mode based on the current settings and the room temperature
61
68
  * @returns The desired mode
62
69
  */
63
70
  calculateDesiredMode(): AcMode;
64
71
  /**
72
+ * Sets the state of the air-conditioning device.
65
73
  *
74
+ * Single entry point for every state change, so each one is recorded in the command log.
75
+ * @param c - The command to execute
66
76
  */
67
- setState(desiredMode: AcMode, desiredTemperature: number | undefined, forceTime: number): void;
77
+ setAcState(c: AcSetStateCommand): void;
68
78
  }
@@ -1,5 +1,6 @@
1
1
  import { iBaseDevice } from './iBaseDevice';
2
2
  import { iExcessEnergyConsumerSettings } from '../settings';
3
+ import { ExcessEnergyConsumerSetStateCommand } from '../../command';
3
4
  /**
4
5
  * This interface represents a device that can consume excess energy.
5
6
  *
@@ -25,13 +26,13 @@ export interface iExcessEnergyConsumer extends iBaseDevice {
25
26
  */
26
27
  isAvailableForExcessEnergy(): boolean;
27
28
  /**
28
- * Turn on this device to consume excess energy
29
+ * Start or stop this device following an energy-manager decision.
30
+ *
31
+ * One entry point rather than separate turn-on/turn-off methods, so the desired state can
32
+ * only come from the command and cannot contradict the method that was called.
33
+ * @param c - The decision this results from, carrying the measurement it was based on
29
34
  */
30
- turnOnForExcessEnergy(): void;
31
- /**
32
- * Turn off this device as we don't have enough excess energy to power it
33
- */
34
- turnOffDueToMissingEnergy(): void;
35
+ setExcessEnergyState(c: ExcessEnergyConsumerSetStateCommand): void;
35
36
  /**
36
37
  * Check if this device was activated by excess energy
37
38
  * @returns Whether this device was activated by excess energy
@@ -2,6 +2,8 @@ import { iBaseGroup } from './iBaseGroup';
2
2
  import { iAcDevice, iHeater, iHumidityCollector, iTemperatureCollector } from '../baseDevices';
3
3
  import { iTemperatureSettings } from '../settings';
4
4
  import { iHeatGroupSettings } from './iHeatGroupSettings';
5
+ import { CommandSource } from '../../enums';
6
+ import { iBaseCommand } from '../../command';
5
7
  /**
6
8
  *
7
9
  */
@@ -44,11 +46,10 @@ export interface iHeatGroup extends iBaseGroup {
44
46
  initialize(): void;
45
47
  /**
46
48
  * Sets all ACs to new desired Value
47
- * TODO: Migrate to new Command System
48
49
  * @param newDesiredState - The new desired (on/off) state
49
- * @param force - Whether this was a manual trigger, thus blocking automatic changes for 1 hour
50
+ * @param source - The event this results from, so the device command can be traced back to it
50
51
  */
51
- setAc(newDesiredState: boolean, force: boolean): void;
52
+ setAc(newDesiredState: boolean, source: CommandSource | iBaseCommand): void;
52
53
  /**
53
54
  *
54
55
  */
@@ -2,6 +2,7 @@ import { AcSettings, RoomBaseDevice } from '../../devices';
2
2
  import { iAcDevice, iExcessEnergyConsumer, iTemporaryDisableAutomatic } from '../../interfaces';
3
3
  import { AcDeviceType, AcMode, DeviceType } from '../../enums';
4
4
  import { BlockAutomaticHandler } from '../blockAutomaticHandler';
5
+ import { AcPerformAutomaticCheckCommand, AcSetStateCommand, AcWriteStateToDeviceCommand, ExcessEnergyConsumerSetStateCommand, RestoreTargetAutomaticValueCommand } from '../../command';
5
6
  import { ExcessEnergyConsumerSettings } from '../../settingsObjects';
6
7
  export declare abstract class AcDevice extends RoomBaseDevice implements iExcessEnergyConsumer, iAcDevice, iTemporaryDisableAutomatic {
7
8
  ip: string;
@@ -49,13 +50,22 @@ export declare abstract class AcDevice extends RoomBaseDevice implements iExcess
49
50
  abstract get on(): boolean;
50
51
  initializeRoomCbs(): void;
51
52
  /** @inheritDoc */
52
- restoreTargetAutomaticValue(): void;
53
+ restoreTargetAutomaticValue(c: RestoreTargetAutomaticValueCommand): void;
53
54
  /** @inheritDoc */
54
55
  isAvailableForExcessEnergy(): boolean;
55
56
  /** @inheritDoc */
56
57
  calculateDesiredMode(): AcMode;
57
58
  abstract setDesiredMode(mode: AcMode, writeToDevice: boolean, temp?: number): void;
58
- abstract turnOn(): void;
59
+ /**
60
+ * Performs a power write, applying any automatic block the command carries.
61
+ *
62
+ * Single place where a block from a write command is honoured, so callers never have to
63
+ * follow up with a separate disableAutomatic call. A block is not a device setting, so it
64
+ * belongs on a pure power write just as much as on a state change.
65
+ * @param c - The command to execute
66
+ */
67
+ writeStateToDevice(c: AcWriteStateToDeviceCommand): void;
68
+ abstract turnOn(c: AcWriteStateToDeviceCommand): void;
59
69
  /** @inheritDoc */
60
70
  onTemperaturChange(newTemperatur: number): void;
61
71
  /**
@@ -63,21 +73,25 @@ export declare abstract class AcDevice extends RoomBaseDevice implements iExcess
63
73
  */
64
74
  persist(): void;
65
75
  /** @inheritDoc */
66
- turnOnForExcessEnergy(): void;
67
- abstract turnOff(): void;
68
- /** @inheritDoc */
69
- turnOffDueToMissingEnergy(): void;
76
+ setExcessEnergyState(c: ExcessEnergyConsumerSetStateCommand): void;
77
+ abstract turnOff(c: AcWriteStateToDeviceCommand): void;
70
78
  /**
71
- * Sets the state of the AC
72
- * TODO: Migrate to new command system
73
- * @param mode - The desired mode
74
- * @param desiredTemp - The desired temperature (if unset it will be calculated)
75
- * @param forceTime - The time in ms to force the AC to stay in this state (default 1h)
79
+ * Sets the state of the AC.
80
+ *
81
+ * Single entry point for every state change, so each one lands in the command log and
82
+ * the reason a unit switched can be reconstructed afterwards. Callers that represent an
83
+ * automatic decision pass no disableAutomaticCommand, so they do not block themselves.
84
+ * @param c - The command to execute
76
85
  */
77
- setState(mode: AcMode, desiredTemp?: number, forceTime?: number): void;
86
+ setAcState(c: AcSetStateCommand): void;
78
87
  /** @inheritDoc */
79
88
  wasActivatedByExcessEnergy(): boolean;
80
- protected automaticCheck(): void;
89
+ /**
90
+ * Re-evaluates what the state should be and applies it.
91
+ * @param c - The command asking for the re-evaluation; the resulting device command chains
92
+ * from it, so the log shows what triggered the change
93
+ */
94
+ protected automaticCheck(c: AcPerformAutomaticCheckCommand): void;
81
95
  private onRoomAnyMovement;
82
96
  private onRoomLastLeave;
83
97
  /** @inheritDoc */
@@ -67,7 +67,7 @@ class AcDevice extends devices_1.RoomBaseDevice {
67
67
  this.deviceCapabilities.push(enums_1.DeviceCapability.ac);
68
68
  this.deviceCapabilities.push(enums_1.DeviceCapability.blockAutomatic);
69
69
  this.deviceCapabilities.push(enums_1.DeviceCapability.excessEnergyConsumer);
70
- utils_1.Utils.guardedInterval(this.automaticCheck, 5 * 60 * 1000, this, false);
70
+ utils_1.Utils.guardedInterval(() => this.automaticCheck(new command_1.AcPerformAutomaticCheckCommand(enums_1.CommandSource.Automatic, 'Time interval check')), 5 * 60 * 1000, this, false);
71
71
  utils_1.Utils.guardedInterval(this.persist, 15 * 60 * 1000, this, true);
72
72
  this.blockAutomationHandler = new blockAutomaticHandler_1.BlockAutomaticHandler(this.restoreTargetAutomaticValue.bind(this), this.log.bind(this));
73
73
  }
@@ -107,9 +107,8 @@ class AcDevice extends devices_1.RoomBaseDevice {
107
107
  }, this);
108
108
  }
109
109
  /** @inheritDoc */
110
- restoreTargetAutomaticValue() {
111
- this.log(enums_1.LogLevel.Debug, 'Restore Target Automatic value');
112
- this.automaticCheck();
110
+ restoreTargetAutomaticValue(c) {
111
+ this.automaticCheck(new command_1.AcPerformAutomaticCheckCommand(c, 'Restore automatic value'));
113
112
  }
114
113
  /** @inheritDoc */
115
114
  isAvailableForExcessEnergy() {
@@ -222,6 +221,24 @@ class AcDevice extends devices_1.RoomBaseDevice {
222
221
  }
223
222
  return desiredMode;
224
223
  }
224
+ /**
225
+ * Performs a power write, applying any automatic block the command carries.
226
+ *
227
+ * Single place where a block from a write command is honoured, so callers never have to
228
+ * follow up with a separate disableAutomatic call. A block is not a device setting, so it
229
+ * belongs on a pure power write just as much as on a state change.
230
+ * @param c - The command to execute
231
+ */
232
+ writeStateToDevice(c) {
233
+ if (c.disableAutomaticCommand) {
234
+ this.blockAutomationHandler.disableAutomatic(c.disableAutomaticCommand);
235
+ }
236
+ if (c.on) {
237
+ this.turnOn(c);
238
+ return;
239
+ }
240
+ this.turnOff(c);
241
+ }
225
242
  /** @inheritDoc */
226
243
  onTemperaturChange(newTemperatur) {
227
244
  this.roomTemperatur = newTemperatur;
@@ -237,47 +254,67 @@ class AcDevice extends devices_1.RoomBaseDevice {
237
254
  (_a = dbo_1.Persistence.dbo) === null || _a === void 0 ? void 0 : _a.persistAC(this);
238
255
  }
239
256
  /** @inheritDoc */
240
- turnOnForExcessEnergy() {
257
+ setExcessEnergyState(c) {
241
258
  var _a, _b;
259
+ if (!c.on) {
260
+ this.setAcState(new command_1.AcSetStateCommand(c, enums_1.AcMode.Off, undefined, 'Missing excess energy'));
261
+ return;
262
+ }
242
263
  if (this.blockAutomationHandler.automaticBlockActive) {
243
264
  return;
244
265
  }
245
- this._activatedByExcessEnergy = true;
246
266
  const desiredMode = this.calculateDesiredMode();
267
+ if (desiredMode === enums_1.AcMode.Off) {
268
+ // isAvailableForExcessEnergy does not cover manualDisabled or an ac-blocking energy
269
+ // manager, so the device can still say it wants to stay off. Leave it alone rather than
270
+ // forcing it on, and do not claim it was activated by excess energy.
271
+ this.logCommand(c, 'Excess energy offered, but the device wants to stay off', enums_1.LogDebugType.SkipUnchangedActuatorCommand);
272
+ return;
273
+ }
247
274
  if (desiredMode === enums_1.AcMode.Cooling &&
248
275
  this.settings.noCoolingOnMovement &&
249
276
  ((_b = (_a = this.room) === null || _a === void 0 ? void 0 : _a.PraesenzGroup) === null || _b === void 0 ? void 0 : _b.anyPresent(true))) {
250
277
  return;
251
278
  }
252
- this.setDesiredMode(this.calculateDesiredMode(), false);
253
- this.turnOn();
254
- }
255
- /** @inheritDoc */
256
- turnOffDueToMissingEnergy() {
257
- this.turnOff();
279
+ this._activatedByExcessEnergy = true;
280
+ this.setAcState(new command_1.AcSetStateCommand(c, desiredMode, undefined, 'Excess energy available'));
258
281
  }
259
282
  /**
260
- * Sets the state of the AC
261
- * TODO: Migrate to new command system
262
- * @param mode - The desired mode
263
- * @param desiredTemp - The desired temperature (if unset it will be calculated)
264
- * @param forceTime - The time in ms to force the AC to stay in this state (default 1h)
283
+ * Sets the state of the AC.
284
+ *
285
+ * Single entry point for every state change, so each one lands in the command log and
286
+ * the reason a unit switched can be reconstructed afterwards. Callers that represent an
287
+ * automatic decision pass no disableAutomaticCommand, so they do not block themselves.
288
+ * @param c - The command to execute
265
289
  */
266
- setState(mode, desiredTemp, forceTime = 60 * 60 * 1000) {
267
- this.blockAutomationHandler.disableAutomatic(new command_1.BlockAutomaticCommand(enums_1.CommandSource.Unknown, forceTime));
290
+ setAcState(c) {
291
+ var _a;
292
+ this.logCommand(c);
293
+ if (c.disableAutomaticCommand) {
294
+ this.blockAutomationHandler.disableAutomatic(c.disableAutomaticCommand);
295
+ }
296
+ // An unset mode means "just switch it on" - which mode that is depends on season and
297
+ // settings, so the device resolves it rather than the caller.
298
+ const mode = (_a = c.mode) !== null && _a !== void 0 ? _a : (this.heatingAllowed ? enums_1.AcMode.Heating : enums_1.AcMode.Cooling);
268
299
  this._mode = mode;
269
- if (mode == enums_1.AcMode.Off) {
270
- this.turnOff();
271
- return;
300
+ // The write command chains back to this one, so the device log shows both the
301
+ // intent and the actual power write, mirroring the actuator path.
302
+ const writeCommand = new command_1.AcWriteStateToDeviceCommand(c, c.on);
303
+ if (c.on) {
304
+ this.setDesiredMode(mode, false, c.desiredTemperature);
272
305
  }
273
- this.setDesiredMode(mode, false, desiredTemp);
274
- this.turnOn();
306
+ this.writeStateToDevice(writeCommand);
275
307
  }
276
308
  /** @inheritDoc */
277
309
  wasActivatedByExcessEnergy() {
278
310
  return this._activatedByExcessEnergy;
279
311
  }
280
- automaticCheck() {
312
+ /**
313
+ * Re-evaluates what the state should be and applies it.
314
+ * @param c - The command asking for the re-evaluation; the resulting device command chains
315
+ * from it, so the log shows what triggered the change
316
+ */
317
+ automaticCheck(c) {
281
318
  var _a, _b;
282
319
  if (this.blockAutomationHandler.automaticBlockActive) {
283
320
  // We aren't allowed to turn on or off anyway --> exit
@@ -288,29 +325,29 @@ class AcDevice extends devices_1.RoomBaseDevice {
288
325
  // Device already in desired state --> do nothing
289
326
  return;
290
327
  }
328
+ // Kept ahead of the branch as before: turning off still reports the mode we would
329
+ // otherwise have wanted, which setDesiredInfo sends alongside the power state.
291
330
  this.setDesiredMode(desiredMode, false);
292
331
  if (desiredMode == enums_1.AcMode.Off ||
293
332
  (desiredMode === enums_1.AcMode.Cooling &&
294
333
  this.settings.noCoolingOnMovement &&
295
334
  ((_b = (_a = this.room) === null || _a === void 0 ? void 0 : _a.PraesenzGroup) === null || _b === void 0 ? void 0 : _b.anyPresent(true)))) {
296
- this.turnOff();
335
+ this.setAcState(new command_1.AcSetStateCommand(c, enums_1.AcMode.Off, undefined, 'No cooling wanted'));
297
336
  return;
298
337
  }
299
- this.turnOn();
338
+ this.setAcState(new command_1.AcSetStateCommand(c, desiredMode, undefined, 'Desired mode reached'));
300
339
  }
301
- onRoomAnyMovement(_action) {
340
+ onRoomAnyMovement(action) {
302
341
  if (!this.settings.noCoolingOnMovement || !this.on || this.mode === enums_1.AcMode.Heating) {
303
342
  return;
304
343
  }
305
- this.log(enums_1.LogLevel.Info, 'Something moved in the room. Turning off AC');
306
- this.turnOff();
344
+ this.setAcState(new command_1.AcSetStateCommand(action, enums_1.AcMode.Off, undefined, 'Something moved in the room and noCoolingOnMovement is set.'));
307
345
  }
308
346
  onRoomLastLeave(action) {
309
347
  if (!this.settings.noCoolingOnMovement) {
310
348
  return;
311
349
  }
312
- this.log(enums_1.LogLevel.Info, `Last person left the room (${action.reasonTrace}). Checking if we should turn on AC`);
313
- this.restoreTargetAutomaticValue();
350
+ this.restoreTargetAutomaticValue(new command_1.RestoreTargetAutomaticValueCommand(action, 'Last person left the room, whilst noCoolingOnMovement is set'));
314
351
  }
315
352
  /** @inheritDoc */
316
353
  toJSON() {
@@ -1,5 +1,6 @@
1
1
  import { DaikinAC, DaikinManager } from 'daikin-controller';
2
2
  import { AcDevice } from './ac-device';
3
+ import { AcWriteStateToDeviceCommand } from '../../command';
3
4
  export declare class DaikinService {
4
5
  private static _ownDevices;
5
6
  private static _daikinManager;
@@ -11,7 +12,7 @@ export declare class DaikinService {
11
12
  }): void;
12
13
  static getDevice(name: string): DaikinAC | undefined;
13
14
  static initialize(): Promise<void>;
14
- static setAll(on: boolean, force?: boolean): void;
15
+ static setAll(c: AcWriteStateToDeviceCommand, force?: boolean): void;
15
16
  static reconnect(name: string, ip: string, mac?: string): Promise<DaikinAC | undefined>;
16
17
  private static reconstructDaikinAc;
17
18
  private static initializeDevice;
@@ -38,14 +38,14 @@ class DaikinService {
38
38
  Telegram_1.TelegramService.addMessageCallback(new Telegram_1.TelegramMessageCallback('AcOn', /\/ac_on/, async (m) => {
39
39
  if (m.from === undefined)
40
40
  return false;
41
- DaikinService.setAll(true);
41
+ DaikinService.setAll(new command_1.AcWriteStateToDeviceCommand(enums_1.CommandSource.Manual, true, `Telegram /ac_on by ${m.from.id}`));
42
42
  Telegram_1.TelegramService.sendMessage([m.chat.id], 'Command executed');
43
43
  return true;
44
44
  }, "Turns all Ac's on without changing any settings"));
45
45
  Telegram_1.TelegramService.addMessageCallback(new Telegram_1.TelegramMessageCallback('AcOff', /\/ac_off/, async (m) => {
46
46
  if (m.from === undefined)
47
47
  return false;
48
- DaikinService.setAll(false, true);
48
+ DaikinService.setAll(new command_1.AcWriteStateToDeviceCommand(enums_1.CommandSource.Manual, false, `Telegram /ac_off by ${m.from.id}`), true);
49
49
  Telegram_1.TelegramService.sendMessage([m.chat.id], 'Command executed');
50
50
  return true;
51
51
  }, "Turns all Ac's off without changing any settings"));
@@ -68,22 +68,17 @@ class DaikinService {
68
68
  });
69
69
  });
70
70
  }
71
- // TODO: Migrate to new command system
72
- static setAll(on, force = false) {
71
+ static setAll(c, force = false) {
73
72
  if (!this.isInitialized) {
74
73
  return;
75
74
  }
76
75
  for (const deviceName in this._ownDevices) {
77
76
  const dev = this._ownDevices[deviceName];
78
- if (on) {
79
- dev.turnOn();
80
- }
81
- else {
82
- dev.turnOff();
83
- }
84
- if (force) {
85
- dev.blockAutomationHandler.disableAutomatic(new command_1.BlockAutomaticCommand(enums_1.CommandSource.Unknown, 180 * 60 * 1000));
86
- }
77
+ // Contract of this method is to switch power without touching any settings, so it
78
+ // addresses the write layer rather than setAcState, which would resolve and apply a mode.
79
+ // The block is not a setting, so it travels in the command like everywhere else.
80
+ c.disableAutomaticCommand = force ? new command_1.BlockAutomaticCommand(c, 180 * 60 * 1000) : undefined;
81
+ dev.writeStateToDevice(c);
87
82
  }
88
83
  }
89
84
  static async reconnect(name, ip, mac) {
@@ -1,4 +1,5 @@
1
1
  import { AcDevice } from './ac-device';
2
+ import { AcPerformAutomaticCheckCommand, AcWriteStateToDeviceCommand } from '../../command';
2
3
  import { DaikinAC } from 'daikin-controller';
3
4
  import { AcMode, DeviceType } from '../../enums';
4
5
  export declare class OwnDaikinDevice extends AcDevice {
@@ -29,10 +30,10 @@ export declare class OwnDaikinDevice extends AcDevice {
29
30
  /** @inheritDoc */
30
31
  setDesiredMode(mode: AcMode, writeToDevice?: boolean, desiredTemp?: number): void;
31
32
  /** @inheritDoc */
32
- turnOn(): void;
33
+ turnOn(c: AcWriteStateToDeviceCommand): void;
33
34
  /** @inheritDoc */
34
- turnOff(): void;
35
- protected automaticCheck(): void;
35
+ turnOff(c: AcWriteStateToDeviceCommand): void;
36
+ protected automaticCheck(c: AcPerformAutomaticCheckCommand): void;
36
37
  private setDesiredInfo;
37
38
  private updateInfo;
38
39
  /**
@@ -77,23 +77,23 @@ class OwnDaikinDevice extends ac_device_1.AcDevice {
77
77
  }
78
78
  }
79
79
  /** @inheritDoc */
80
- turnOn() {
81
- this.log(enums_1.LogLevel.Info, 'Turning on');
80
+ turnOn(c) {
81
+ this.logCommand(c);
82
82
  this.desiredState = daikin_controller_1.Power.ON;
83
83
  this.setDesiredInfo();
84
84
  }
85
85
  /** @inheritDoc */
86
- turnOff() {
87
- this.log(enums_1.LogLevel.Info, 'Turning off');
86
+ turnOff(c) {
87
+ this.logCommand(c);
88
88
  this._activatedByExcessEnergy = false;
89
89
  this.desiredState = daikin_controller_1.Power.OFF;
90
90
  this._mode = enums_1.AcMode.Off;
91
91
  this.setDesiredInfo();
92
92
  }
93
- automaticCheck() {
93
+ automaticCheck(c) {
94
94
  // First Load Device Info, then perform check
95
95
  this.updateInfo().then((_on) => {
96
- super.automaticCheck();
96
+ super.automaticCheck(c);
97
97
  });
98
98
  }
99
99
  setDesiredInfo(retry = false, forceTemp) {