hoffmation-base 1.0.5 → 1.0.8

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.
@@ -43,6 +43,11 @@ export interface iConfig {
43
43
  export interface iLogSettings {
44
44
  logLevel: number;
45
45
  useTimestamp: boolean;
46
+ debugNewMovementState?: boolean;
47
+ debugShutterPositionChange?: boolean;
48
+ debugActuatorChange?: boolean;
49
+ debugUchangedShutterPosition?: boolean;
50
+ debugUnchangedActuator?: boolean;
46
51
  }
47
52
  export interface iTimePair {
48
53
  hours: number;
@@ -1,5 +1,6 @@
1
1
  /// <reference types="iobroker" />
2
2
  import { IBaseDevice } from './baseDeviceInterfaces';
3
+ import { LogDebugType } from '../services';
3
4
  import { DeviceInfo } from './DeviceInfo';
4
5
  import { LogLevel, RoomBase, RoomDeviceAddingSettings } from '../../models';
5
6
  import { IOBrokerConnection } from '../ioBroker';
@@ -37,7 +38,7 @@ export declare abstract class IoBrokerBaseDevice implements IBaseDevice {
37
38
  */
38
39
  checkIoConnection(showError?: boolean): boolean;
39
40
  abstract update(idSplit: string[], state: ioBroker.State, initial: boolean, pOverride: boolean): void;
40
- log(level: LogLevel, message: string): void;
41
+ log(level: LogLevel, message: string, logDebugType?: LogDebugType): void;
41
42
  toJSON(): Partial<IoBrokerBaseDevice>;
42
43
  protected addToCorrectRoom(): void;
43
44
  /**
@@ -61,11 +61,12 @@ class IoBrokerBaseDevice {
61
61
  }
62
62
  return this.ioConn !== undefined;
63
63
  }
64
- log(level, message) {
64
+ log(level, message, logDebugType = services_1.LogDebugType.None) {
65
65
  services_1.ServerLogService.writeLog(level, message, {
66
66
  room: this.info.room,
67
67
  deviceId: this.id,
68
68
  deviceName: this.info.customName,
69
+ debugType: logDebugType,
69
70
  });
70
71
  }
71
72
  toJSON() {
@@ -31,7 +31,7 @@ class HmIpLampe extends hmIpDevice_1.HmIPDevice {
31
31
  /** @inheritdoc */
32
32
  setLight(pValue, timeout = -1, force = false) {
33
33
  if (!force && pValue === this.lightOn && this.queuedLightValue === null) {
34
- this.log(models_1.LogLevel.DeepTrace, `Skip light command as it is already ${pValue}`);
34
+ this.log(models_1.LogLevel.DeepTrace, `Skip light command as it is already ${pValue}`, services_1.LogDebugType.SkipUnchangedActuatorCommand);
35
35
  return;
36
36
  }
37
37
  if (this.lightOnSwitchID === '') {
@@ -42,7 +42,7 @@ class HmIpLampe extends hmIpDevice_1.HmIPDevice {
42
42
  this.log(models_1.LogLevel.Debug, `Skip automatic command to ${pValue} as it is locked until ${new Date(this.turnOffTime).toLocaleString()}`);
43
43
  return;
44
44
  }
45
- this.log(models_1.LogLevel.Debug, `Lampe schalten Wert: ${pValue}`);
45
+ this.log(models_1.LogLevel.Debug, `Set Light Acutator to "${pValue}"`, services_1.LogDebugType.SetActuator);
46
46
  this.setState(this.lightOnSwitchID, pValue, undefined, (err) => {
47
47
  this.log(models_1.LogLevel.Error, `Lampe schalten ergab Fehler: ${err}`);
48
48
  });
@@ -69,7 +69,7 @@ class HmIpRoll extends hmIpDevice_1.HmIPDevice {
69
69
  return;
70
70
  }
71
71
  if (this.currentLevel === pPosition) {
72
- this.log(models_2.LogLevel.Debug, `Skip Rollo command to Position ${pPosition} as this is the current one`);
72
+ this.log(models_2.LogLevel.Debug, `Skip Rollo command to Position ${pPosition} as this is the current one`, services_1.LogDebugType.SkipUnchangedRolloPosition);
73
73
  return;
74
74
  }
75
75
  if (this._setLevelSwitchID === '') {
@@ -37,10 +37,10 @@ class ZigbeeActuator extends zigbeeDevice_1.ZigbeeDevice {
37
37
  return;
38
38
  }
39
39
  if (!force && pValue === this.actuatorOn && this.queuedValue === null) {
40
- this.log(models_1.LogLevel.Debug, `Skip actuator command as it is already ${pValue}`);
40
+ this.log(models_1.LogLevel.Debug, `Skip actuator command as it is already ${pValue}`, services_1.LogDebugType.SkipUnchangedActuatorCommand);
41
41
  return;
42
42
  }
43
- this.log(models_1.LogLevel.Debug, `Switch actuator to: ${pValue}`);
43
+ this.log(models_1.LogLevel.Debug, `Set outlet Acutator to "${pValue}"`, services_1.LogDebugType.SetActuator);
44
44
  this.setState(this.actuatorOnSwitchID, pValue, undefined, (err) => {
45
45
  this.log(models_1.LogLevel.Error, `Switching actuator resulted in error: ${err}`);
46
46
  });
@@ -70,7 +70,7 @@ class ZigbeeShutter extends zigbeeDevice_1.ZigbeeDevice {
70
70
  return;
71
71
  }
72
72
  if (this.currentLevel === pPosition) {
73
- this.log(models_1.LogLevel.Debug, `Skip Rollo command to Position ${pPosition} as this is the current one`);
73
+ this.log(models_1.LogLevel.Debug, `Skip Rollo command to Position ${pPosition} as this is the current one`, services_1.LogDebugType.SkipUnchangedRolloPosition);
74
74
  return;
75
75
  }
76
76
  if (this._fenster !== undefined) {
@@ -88,7 +88,7 @@ class ZigbeeIlluDimmer extends BaseDevices_1.ZigbeeDevice {
88
88
  if (pValue && brightness === -1 && this.brightness < 10) {
89
89
  brightness = 10;
90
90
  }
91
- this.log(models_1.LogLevel.Debug, `Dimmer Schalten An: ${pValue} \t Helligkeit: ${brightness}%`);
91
+ this.log(models_1.LogLevel.Debug, `Set Light Acutator to "${pValue}" with brightness ${brightness}`, services_1.LogDebugType.SetActuator);
92
92
  this.setState(this.stateID, pValue);
93
93
  this.queuedValue = pValue;
94
94
  if (brightness > -1) {
@@ -22,7 +22,7 @@ class ZigbeeIlluLampe extends zigbeeIlluActuator_1.ZigbeeIlluActuator {
22
22
  }
23
23
  /** @inheritdoc */
24
24
  setLight(pValue, timeout = -1, force = false) {
25
- this.log(models_1.LogLevel.Debug, `Lampenaktor schalten Wert: ${pValue}`);
25
+ this.log(models_1.LogLevel.Debug, `Set Light Acutator to "${pValue}"`, services_1.LogDebugType.SetActuator);
26
26
  if (this.settings.isStromStoss) {
27
27
  timeout = 3000;
28
28
  services_1.Utils.guardedTimeout(() => {
@@ -53,7 +53,7 @@ class ZigbeeMotionSensor extends BaseDevices_1.ZigbeeDevice {
53
53
  return;
54
54
  }
55
55
  if (newState === this.movementDetected) {
56
- this.log(models_1.LogLevel.Debug, `Skip movement because state is already ${newState}`);
56
+ this.log(models_1.LogLevel.Debug, `Skip movement because state is already ${newState}`, services_1.LogDebugType.SkipUnchangedMovementState);
57
57
  if (newState) {
58
58
  // Wenn ein Sensor sich nicht von alleine zurücksetzt, hier erzwingen.
59
59
  this.resetFallbackTimeout();
@@ -63,7 +63,7 @@ class ZigbeeMotionSensor extends BaseDevices_1.ZigbeeDevice {
63
63
  }
64
64
  this.resetFallbackTimeout();
65
65
  this.movementDetected = newState;
66
- this.log(models_1.LogLevel.Debug, `New movement state: ${newState}`);
66
+ this.log(models_1.LogLevel.Debug, `New movement state: ${newState}`, services_1.LogDebugType.NewMovementState);
67
67
  if (newState) {
68
68
  this.startFallbackTimeout();
69
69
  this.detectionsToday++;
@@ -96,7 +96,7 @@ class TelegramService {
96
96
  }
97
97
  static checkAuthorized(msg) {
98
98
  var _a;
99
- if (msg.from !== undefined && this.allowedIDs.includes((_a = msg.from) === null || _a === void 0 ? void 0 : _a.id)) {
99
+ if ((msg.from !== undefined && this.allowedIDs.includes((_a = msg.from) === null || _a === void 0 ? void 0 : _a.id)) || this.allowedIDs.includes(msg.chat.id)) {
100
100
  log_service_1.ServerLogService.writeLog(models_1.LogLevel.Debug, `Authorisierte Telegram Message erhalten: ${JSON.stringify(msg)}`);
101
101
  return true;
102
102
  }
@@ -61,6 +61,9 @@ class DaikinService {
61
61
  });
62
62
  }
63
63
  static setAll(on, force = false) {
64
+ if (!this.isInitialized) {
65
+ return;
66
+ }
64
67
  for (const deviceName in this._ownDevices) {
65
68
  const dev = this._ownDevices[deviceName];
66
69
  if (on) {
@@ -1,7 +1,14 @@
1
1
  import { IBaseDevice } from '../../devices';
2
2
  import { RoomBase } from '../../../models';
3
3
  import { LogObject } from '../log-service';
4
+ import { OwnDaikinDevice } from '../ac';
4
5
  export declare class API {
6
+ /**
7
+ * Gets the instance of an Daikin Device identified by name
8
+ * @param {string} name
9
+ * @returns {OwnDaikinDevice | undefined}
10
+ */
11
+ static getAc(name: string): OwnDaikinDevice | undefined;
5
12
  static getDevices(): {
6
13
  [id: string]: IBaseDevice;
7
14
  };
@@ -9,4 +16,22 @@ export declare class API {
9
16
  static getRooms(): Map<string, RoomBase>;
10
17
  static getRoom(id: string): RoomBase | undefined;
11
18
  static getLog(): LogObject[];
19
+ /**
20
+ * Turns on/off one AC identified by it's name
21
+ * @param name The name of the device, if wrong false will be returned
22
+ * @param {boolean} desiredState
23
+ */
24
+ static setAc(name: string, desiredState: boolean): boolean;
25
+ /**
26
+ * Turns on/off all AC´s in the home
27
+ * @param {boolean} desiredState
28
+ */
29
+ static setAllAc(desiredState: boolean): void;
30
+ /**
31
+ * Changes the status of a given Lamp
32
+ * @param {string} deviceId The device Id of the lamp
33
+ * @param {boolean} state The desired new state
34
+ * @returns {Error | null} In case it failed the Error containing the reason
35
+ */
36
+ static setLight(deviceId: string, state: boolean): Error | null;
12
37
  }
@@ -5,7 +5,16 @@ const devices_1 = require("../../devices");
5
5
  const models_1 = require("../../../models");
6
6
  const room_service_1 = require("../room-service");
7
7
  const log_service_1 = require("../log-service");
8
+ const ac_1 = require("../ac");
8
9
  class API {
10
+ /**
11
+ * Gets the instance of an Daikin Device identified by name
12
+ * @param {string} name
13
+ * @returns {OwnDaikinDevice | undefined}
14
+ */
15
+ static getAc(name) {
16
+ return ac_1.OwnDaikinDevices.ownDevices[name];
17
+ }
9
18
  static getDevices() {
10
19
  // console.log(inspect(Devices.alLDevices, false, 3));
11
20
  return devices_1.Devices.alLDevices;
@@ -27,5 +36,48 @@ class API {
27
36
  static getLog() {
28
37
  return log_service_1.ServerLogService.getLog();
29
38
  }
39
+ /**
40
+ * Turns on/off one AC identified by it's name
41
+ * @param name The name of the device, if wrong false will be returned
42
+ * @param {boolean} desiredState
43
+ */
44
+ static setAc(name, desiredState) {
45
+ const d = this.getAc(name);
46
+ if (!d) {
47
+ log_service_1.ServerLogService.writeLog(models_1.LogLevel.Warn, `Daikin Device for name ${name} not found`);
48
+ return false;
49
+ }
50
+ if (desiredState) {
51
+ d.turnOn();
52
+ }
53
+ else {
54
+ d.deactivateAutomaticTurnOn(60 * 60 * 1000);
55
+ }
56
+ return true;
57
+ }
58
+ /**
59
+ * Turns on/off all AC´s in the home
60
+ * @param {boolean} desiredState
61
+ */
62
+ static setAllAc(desiredState) {
63
+ ac_1.DaikinService.setAll(desiredState, true);
64
+ }
65
+ /**
66
+ * Changes the status of a given Lamp
67
+ * @param {string} deviceId The device Id of the lamp
68
+ * @param {boolean} state The desired new state
69
+ * @returns {Error | null} In case it failed the Error containing the reason
70
+ */
71
+ static setLight(deviceId, state) {
72
+ const d = this.getDevice(deviceId);
73
+ if (d === undefined) {
74
+ return new Error(`Device with ID ${deviceId} not found`);
75
+ }
76
+ if (typeof d.setLight !== 'function') {
77
+ return new Error(`Device with ID ${deviceId} is no Lamp`);
78
+ }
79
+ d.setLight(state, 60 * 60 * 1000, true);
80
+ return null;
81
+ }
30
82
  }
31
83
  exports.API = API;
@@ -1,8 +1,18 @@
1
1
  import { LogSource } from '../../../models/logSource';
2
+ export declare enum LogDebugType {
3
+ None = 0,
4
+ SkipUnchangedActuatorCommand = 1,
5
+ SkipUnchangedRolloPosition = 2,
6
+ SetActuator = 3,
7
+ ShutterPositionChange = 4,
8
+ NewMovementState = 5,
9
+ SkipUnchangedMovementState = 6
10
+ }
2
11
  export declare class LogFilterData {
3
12
  room?: string;
4
13
  deviceId?: string;
5
14
  deviceName?: string;
6
15
  groupType?: string;
7
16
  source?: LogSource;
17
+ debugType?: LogDebugType;
8
18
  }
@@ -1,6 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LogFilterData = void 0;
3
+ exports.LogFilterData = exports.LogDebugType = void 0;
4
+ var LogDebugType;
5
+ (function (LogDebugType) {
6
+ LogDebugType[LogDebugType["None"] = 0] = "None";
7
+ LogDebugType[LogDebugType["SkipUnchangedActuatorCommand"] = 1] = "SkipUnchangedActuatorCommand";
8
+ LogDebugType[LogDebugType["SkipUnchangedRolloPosition"] = 2] = "SkipUnchangedRolloPosition";
9
+ LogDebugType[LogDebugType["SetActuator"] = 3] = "SetActuator";
10
+ LogDebugType[LogDebugType["ShutterPositionChange"] = 4] = "ShutterPositionChange";
11
+ LogDebugType[LogDebugType["NewMovementState"] = 5] = "NewMovementState";
12
+ LogDebugType[LogDebugType["SkipUnchangedMovementState"] = 6] = "SkipUnchangedMovementState";
13
+ })(LogDebugType = exports.LogDebugType || (exports.LogDebugType = {}));
4
14
  class LogFilterData {
15
+ constructor() {
16
+ this.debugType = LogDebugType.None;
17
+ }
5
18
  }
6
19
  exports.LogFilterData = LogFilterData;
@@ -15,4 +15,10 @@ export declare class ServerLogService {
15
15
  static addedDeviceToRoom(pRoomName: string, pDeviceType: DeviceType, pRoomIndex: number, forceDebug?: boolean): void;
16
16
  static missingRoomHandling(pRoomName: string, pDeviceType: DeviceType): void;
17
17
  static missingRoomIndexHandling(pRoomName: string, pIndex: number, pDeviceType: DeviceType): void;
18
+ /**
19
+ * Checks if this message is of a debugtype which should be skipped according to settings
20
+ * @param {LogDebugType} debugType
21
+ * @returns {boolean} If the Message should be skipped
22
+ */
23
+ private static checkDebugLogSkip;
18
24
  }
@@ -6,7 +6,9 @@ const models_1 = require("../../../models");
6
6
  const devices_1 = require("../../devices");
7
7
  const utils_1 = require("../utils");
8
8
  const log_object_1 = require("./log-object");
9
+ const log_filter_data_1 = require("./log-filter-data");
9
10
  const logSource_1 = require("../../../models/logSource");
11
+ const settings_service_1 = require("../settings-service");
10
12
  class ServerLogService {
11
13
  static getLog(amount = 5000) {
12
14
  return this.storage.readAmount(amount);
@@ -17,6 +19,9 @@ class ServerLogService {
17
19
  static writeLog(pLevel, pMessage, additionalLogInfo) {
18
20
  var _a;
19
21
  const now = Date.now();
22
+ if ((additionalLogInfo === null || additionalLogInfo === void 0 ? void 0 : additionalLogInfo.debugType) !== undefined && ServerLogService.checkDebugLogSkip(additionalLogInfo.debugType)) {
23
+ return;
24
+ }
20
25
  if (pLevel > this.storageLevel && pLevel > ServerLogService.settings.logLevel) {
21
26
  return;
22
27
  }
@@ -53,6 +58,46 @@ class ServerLogService {
53
58
  static missingRoomIndexHandling(pRoomName, pIndex, pDeviceType) {
54
59
  ServerLogService.writeLog(models_1.LogLevel.Warn, `Raum "${pRoomName}" hat keine Definition für den Typ "${devices_1.DeviceType[pDeviceType]} mit Index ${pIndex}"`);
55
60
  }
61
+ /**
62
+ * Checks if this message is of a debugtype which should be skipped according to settings
63
+ * @param {LogDebugType} debugType
64
+ * @returns {boolean} If the Message should be skipped
65
+ */
66
+ static checkDebugLogSkip(debugType) {
67
+ var _a, _b, _c, _d, _e;
68
+ switch (debugType) {
69
+ case log_filter_data_1.LogDebugType.None:
70
+ return false;
71
+ case log_filter_data_1.LogDebugType.SkipUnchangedActuatorCommand:
72
+ if (((_a = settings_service_1.SettingsService.settings.logSettings) === null || _a === void 0 ? void 0 : _a.debugUnchangedActuator) === true) {
73
+ return false;
74
+ }
75
+ break;
76
+ case log_filter_data_1.LogDebugType.SkipUnchangedRolloPosition:
77
+ if (((_b = settings_service_1.SettingsService.settings.logSettings) === null || _b === void 0 ? void 0 : _b.debugUchangedShutterPosition) === true) {
78
+ return false;
79
+ }
80
+ break;
81
+ case log_filter_data_1.LogDebugType.SetActuator:
82
+ if (((_c = settings_service_1.SettingsService.settings.logSettings) === null || _c === void 0 ? void 0 : _c.debugActuatorChange) === true) {
83
+ return false;
84
+ }
85
+ break;
86
+ case log_filter_data_1.LogDebugType.ShutterPositionChange:
87
+ if (((_d = settings_service_1.SettingsService.settings.logSettings) === null || _d === void 0 ? void 0 : _d.debugShutterPositionChange) === true) {
88
+ return false;
89
+ }
90
+ break;
91
+ case log_filter_data_1.LogDebugType.NewMovementState:
92
+ if (((_e = settings_service_1.SettingsService.settings.logSettings) === null || _e === void 0 ? void 0 : _e.debugNewMovementState) === true) {
93
+ return false;
94
+ }
95
+ break;
96
+ case log_filter_data_1.LogDebugType.SkipUnchangedMovementState:
97
+ break;
98
+ }
99
+ return true;
100
+ }
56
101
  }
57
102
  exports.ServerLogService = ServerLogService;
58
103
  ServerLogService.telegramLevel = -1; // Controlled from within Config File
@@ -76,7 +76,7 @@ class Utils {
76
76
  }
77
77
  static jsonFilter(object) {
78
78
  return lodash_1.default.omit(object, Object.keys(object).filter((key) => {
79
- if (key.includes('Timeout') || key.includes('Interval')) {
79
+ if (key.includes('Timeout') || key.includes('Interval') || key.includes('timeouts')) {
80
80
  // Exclude timeout Variables.
81
81
  return true;
82
82
  }