hoffmation-base 0.1.29-5 → 0.1.29-9

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 (44) hide show
  1. package/README.md +32 -0
  2. package/lib/index.js +6 -1
  3. package/lib/models/persistence/ShutterCalibration.d.ts +8 -0
  4. package/lib/models/persistence/ShutterCalibration.js +13 -0
  5. package/lib/models/persistence/index.d.ts +4 -3
  6. package/lib/models/persistence/index.js +4 -3
  7. package/lib/server/config/iConfig.d.ts +1 -1
  8. package/lib/server/devices/Fenster.d.ts +1 -1
  9. package/lib/server/devices/Fenster.js +1 -1
  10. package/lib/server/devices/Griffe.js +1 -1
  11. package/lib/server/devices/deviceType.d.ts +1 -0
  12. package/lib/server/devices/deviceType.js +1 -0
  13. package/lib/server/devices/devices.js +4 -0
  14. package/lib/server/devices/groups/fensterGroup.js +2 -1
  15. package/lib/server/devices/hmIPDevices/hmIpGriff.d.ts +1 -1
  16. package/lib/server/devices/hmIPDevices/hmIpGriff.js +1 -1
  17. package/lib/server/devices/hmIPDevices/hmIpRoll.js +1 -1
  18. package/lib/server/devices/hmIPDevices/hmIpTuer.d.ts +5 -5
  19. package/lib/server/devices/hmIPDevices/hmIpTuer.js +13 -13
  20. package/lib/server/devices/hmIPDevices/index.d.ts +2 -2
  21. package/lib/server/devices/hmIPDevices/index.js +2 -2
  22. package/lib/server/devices/index.d.ts +1 -0
  23. package/lib/server/devices/index.js +1 -0
  24. package/lib/server/devices/{FensterPosition.d.ts → models/FensterPosition.d.ts} +0 -0
  25. package/lib/server/devices/{FensterPosition.js → models/FensterPosition.js} +0 -0
  26. package/lib/server/devices/models/MagnetPosition.d.ts +4 -0
  27. package/lib/server/devices/models/MagnetPosition.js +8 -0
  28. package/lib/server/devices/models/index.d.ts +2 -0
  29. package/lib/server/devices/models/index.js +14 -0
  30. package/lib/server/devices/zigbee/index.d.ts +2 -0
  31. package/lib/server/devices/zigbee/index.js +2 -0
  32. package/lib/server/devices/zigbee/zigbeeIlluShutter.d.ts +2 -0
  33. package/lib/server/devices/zigbee/zigbeeIlluShutter.js +24 -1
  34. package/lib/server/devices/zigbee/zigbeeMagnetContact.d.ts +17 -0
  35. package/lib/server/devices/zigbee/zigbeeMagnetContact.js +81 -0
  36. package/lib/server/devices/zigbee/zigbeeSMaBiTMagnetContact.d.ts +7 -0
  37. package/lib/server/devices/zigbee/zigbeeSMaBiTMagnetContact.js +23 -0
  38. package/lib/server/devices/zigbee/zigbeeShutter.js +1 -1
  39. package/lib/server/services/dbo/persist.d.ts +11 -3
  40. package/lib/server/services/dbo/persist.js +75 -14
  41. package/lib/tsconfig.tsbuildinfo +1 -1
  42. package/package.json +2 -2
  43. package/lib/server/devices/hmIPDevices/TuerPosition.d.ts +0 -4
  44. package/lib/server/devices/hmIPDevices/TuerPosition.js +0 -8
package/README.md CHANGED
@@ -1,2 +1,34 @@
1
1
  # Hoffmation-Base
2
2
  [![DeepSource](https://deepsource.io/gh/theimo1221/Hoffmation-Base.svg/?label=active+issues&show_trend=true&token=Ec4T7omgYOMMc4ezxv_9bHk9)](https://deepsource.io/gh/theimo1221/Hoffmation-Base/?ref=repository-badge)
3
+
4
+ A home automation library specialized for Zigbee and Homematic IP devices in combination with ioBroker.
5
+ ## What does it do?
6
+ This project serves as library for home automation projects. It provides services, models and utilities necessary to interact with rooms and smart devices via iobroker, but also to connect them to other services for textual/audio/visual notifications or really just any code or service you want the devices to connect to.
7
+
8
+ Built on other open source projects that take care of the technical level, this project is made to provide a tool for the coding on the logical level. It is built as base to write automation code independent of the ioBroker user interface and currently provides support for the interaction with **devices** specified in [`src/server/devices`](src/server/devices) and **services** that can be found in [`src/server/services`](src/server/devices).
9
+
10
+ Those include, but are not limited to:
11
+
12
+ - **Devices**: Motion/Presence sensors, window handles, heating elements, lamps and dimmers, shutters, door contact sensors, physical buttons/switches, power sockets
13
+ - **Services**: Interaction service for a telegram bot, weather, sonos control, waste calendar
14
+
15
+ ## How can I use it?
16
+ This library *can* be used in conjunction with or as addition to own base projects, but it's intended to be used with the configuration project [Hoffmation-Express](https://github.com/theimo1221/Hoffmation-Express) which uses this library via a [npm package](https://www.npmjs.com/package/hoffmation-base).
17
+
18
+ Whether you use it with Hoffmation-Express or with your own controller code, make sure you pass a valid config file (see [`src/server/config/private`](src/server/config/private) for an example) and a valid ioBroker device tree (you can find more information about that in the Hoffmation-Express project).
19
+
20
+ ### Base requirements
21
+ In order to get the library running correctly, the following requirements should be met:
22
+ * You use ioBroker for all devices that you want to control or read from
23
+ Make sure you got the [socket.io](https://github.com/ioBroker/ioBroker.socketio) adapter installed
24
+ * You use devices that are supported or are able to use one of the supported devices as base for yours.
25
+ (If you use a Zigbee or Homematic IP device that is not currently supported, don't hesitate to create a pull request and add it!)
26
+ * You have a unix-based or windows device for the software you want to run this library with.
27
+
28
+ ### Build
29
+ To build the library, make sure [Node.js](https://nodejs.org/en/download/) is installed.
30
+ Then, just run `npm run build`.
31
+
32
+ ## Why would I use it?
33
+ Even if it looks simple at first, automating your entire home with a user interface can sometimes be more difficult than just *coding* your home.
34
+ Especially if you have a lot of specialized requirements that you want to satisfy, it can be simpler to just code your own rules and interfaces than to rely on user interfaces to do it for you.
package/lib/index.js CHANGED
@@ -26,7 +26,12 @@ class HoffmationBase {
26
26
  static async initializeBeforeIoBroker(initObject) {
27
27
  server_1.SettingsService.initialize(initObject.config);
28
28
  server_1.ServerLogService.writeLog(models_1.LogLevel.Info, `Hoffmation-Base Startup`);
29
- await server_1.Persist.initialize(initObject.config.persistence);
29
+ if (initObject.config.persistence) {
30
+ await server_1.Persist.initialize(initObject.config.persistence);
31
+ }
32
+ else {
33
+ server_1.Persist.turnOff();
34
+ }
30
35
  this._app = initObject.app;
31
36
  if (server_1.SettingsService.settings.mp3Server) {
32
37
  server_1.ServerLogService.writeLog(models_1.LogLevel.Info, `Mp3Server settings detected --> initializing`);
@@ -0,0 +1,8 @@
1
+ export declare class ShutterCalibration {
2
+ deviceID: string;
3
+ averageUp: number;
4
+ counterUp: number;
5
+ averageDown: number;
6
+ counterDown: number;
7
+ constructor(deviceID: string, averageUp: number, counterUp: number, averageDown: number, counterDown: number);
8
+ }
@@ -0,0 +1,13 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ShutterCalibration = void 0;
4
+ class ShutterCalibration {
5
+ constructor(deviceID, averageUp, counterUp, averageDown, counterDown) {
6
+ this.deviceID = deviceID;
7
+ this.averageUp = averageUp;
8
+ this.counterUp = counterUp;
9
+ this.averageDown = averageDown;
10
+ this.counterDown = counterDown;
11
+ }
12
+ }
13
+ exports.ShutterCalibration = ShutterCalibration;
@@ -1,6 +1,7 @@
1
- export * from './todaysCount';
2
1
  export * from './BasicRoomInfo';
3
- export * from './RoomDetailInfo';
2
+ export * from './CurrentIlluminationDataPoint';
4
3
  export * from './DailyMovementCount';
4
+ export * from './RoomDetailInfo';
5
+ export * from './ShutterCalibration';
5
6
  export * from './temperaturDataPoint';
6
- export * from './CurrentIlluminationDataPoint';
7
+ export * from './todaysCount';
@@ -10,9 +10,10 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
10
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
11
  };
12
12
  Object.defineProperty(exports, "__esModule", { value: true });
13
- __exportStar(require("./todaysCount"), exports);
14
13
  __exportStar(require("./BasicRoomInfo"), exports);
15
- __exportStar(require("./RoomDetailInfo"), exports);
14
+ __exportStar(require("./CurrentIlluminationDataPoint"), exports);
16
15
  __exportStar(require("./DailyMovementCount"), exports);
16
+ __exportStar(require("./RoomDetailInfo"), exports);
17
+ __exportStar(require("./ShutterCalibration"), exports);
17
18
  __exportStar(require("./temperaturDataPoint"), exports);
18
- __exportStar(require("./CurrentIlluminationDataPoint"), exports);
19
+ __exportStar(require("./todaysCount"), exports);
@@ -8,7 +8,7 @@ export interface iConfig {
8
8
  ioBrokerUrl: string;
9
9
  mp3Server?: iMp3Settings;
10
10
  muell?: iMuellSettings;
11
- persistence: iPersistenceSettings;
11
+ persistence?: iPersistenceSettings;
12
12
  polly?: iPollySettings;
13
13
  roomDefault: iRoomDefaultSettings;
14
14
  sonos?: iSonosSettings;
@@ -1,7 +1,7 @@
1
1
  import { HmIpGriff } from './hmIPDevices/hmIpGriff';
2
2
  import { RoomBase } from '../../models/rooms/RoomBase';
3
3
  import { ZigbeeAquaraVibra } from './zigbee/zigbeeAquaraVibra';
4
- import { FensterPosition } from './FensterPosition';
4
+ import { FensterPosition } from './models/FensterPosition';
5
5
  import { iShutter } from './iShutter';
6
6
  export declare class Fenster {
7
7
  room: RoomBase;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Fenster = void 0;
4
4
  const log_service_1 = require("../services/log-service");
5
5
  const utils_1 = require("../services/utils/utils");
6
- const FensterPosition_1 = require("./FensterPosition");
6
+ const FensterPosition_1 = require("./models/FensterPosition");
7
7
  const time_callback_service_1 = require("../services/time-callback-service");
8
8
  const logLevel_1 = require("../../models/logLevel");
9
9
  const ShutterService_1 = require("../services/ShutterService");
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Griffe = void 0;
4
4
  const deviceType_1 = require("./deviceType");
5
- const FensterPosition_1 = require("./FensterPosition");
5
+ const FensterPosition_1 = require("./models/FensterPosition");
6
6
  const devices_1 = require("./devices");
7
7
  class Griffe {
8
8
  static getGriffPosition() {
@@ -23,5 +23,6 @@ export declare enum DeviceType {
23
23
  ZigbeeIlluActuator = 210,
24
24
  ZigbeeAquaraMotion = 211,
25
25
  ZigbeeIlluShutter = 212,
26
+ ZigbeeSMaBiTMagnetContact = 212,
26
27
  Wled = 1001
27
28
  }
@@ -27,5 +27,6 @@ var DeviceType;
27
27
  DeviceType[DeviceType["ZigbeeIlluActuator"] = 210] = "ZigbeeIlluActuator";
28
28
  DeviceType[DeviceType["ZigbeeAquaraMotion"] = 211] = "ZigbeeAquaraMotion";
29
29
  DeviceType[DeviceType["ZigbeeIlluShutter"] = 212] = "ZigbeeIlluShutter";
30
+ DeviceType[DeviceType["ZigbeeSMaBiTMagnetContact"] = 212] = "ZigbeeSMaBiTMagnetContact";
30
31
  DeviceType[DeviceType["Wled"] = 1001] = "Wled";
31
32
  })(DeviceType = exports.DeviceType || (exports.DeviceType = {}));
@@ -29,6 +29,7 @@ const hmIpHeizung_1 = require("./hmIPDevices/hmIpHeizung");
29
29
  const hmIpTuer_1 = require("./hmIPDevices/hmIpTuer");
30
30
  const hmIpHeizgruppe_1 = require("./hmIPDevices/hmIpHeizgruppe");
31
31
  const zigbeeIlluShutter_1 = require("./zigbee/zigbeeIlluShutter");
32
+ const zigbeeSMaBiTMagnetContact_1 = require("./zigbee/zigbeeSMaBiTMagnetContact");
32
33
  class Devices {
33
34
  constructor(pDeviceData, pRoomImportEnforcer) {
34
35
  // This forces import of rooms at correct timing, to allow devices to land in proper rooms.
@@ -118,6 +119,9 @@ class Devices {
118
119
  case 'IlluShutter':
119
120
  d = new zigbeeIlluShutter_1.ZigbeeIlluShutter(zigbeeInfo);
120
121
  break;
122
+ case 'SMaBiTMagnet':
123
+ d = new zigbeeSMaBiTMagnetContact_1.ZigbeeSMaBiTMagnetContact(zigbeeInfo);
124
+ break;
121
125
  default:
122
126
  log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Warn, `No zigbee Device Type for ${zigbeeInfo.deviceType} defined`);
123
127
  d = new zigbeeDevice_1.ZigbeeDevice(zigbeeInfo, deviceType_1.DeviceType.unknown);
@@ -5,7 +5,7 @@ const timeCallback_1 = require("../../../models/timeCallback");
5
5
  const log_service_1 = require("../../services/log-service");
6
6
  const utils_1 = require("../../services/utils/utils");
7
7
  const weather_service_1 = require("../../services/weather/weather-service");
8
- const FensterPosition_1 = require("../FensterPosition");
8
+ const FensterPosition_1 = require("../models/FensterPosition");
9
9
  const logLevel_1 = require("../../../models/logLevel");
10
10
  const time_callback_service_1 = require("../../services/time-callback-service");
11
11
  const ShutterService_1 = require("../../services/ShutterService");
@@ -35,6 +35,7 @@ class FensterGroup {
35
35
  if (savePosition) {
36
36
  f.desiredPosition = 100;
37
37
  }
38
+ log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Debug, `Fenster.allRolloUp for ${f.rollo.info.customName}`);
38
39
  ShutterService_1.ShutterService.up(f.rollo, false);
39
40
  });
40
41
  }
@@ -1,7 +1,7 @@
1
1
  /// <reference types="iobroker" />
2
2
  import { HmIPDevice } from './hmIpDevice';
3
3
  import { DeviceInfo } from '../DeviceInfo';
4
- import { FensterPosition } from '../FensterPosition';
4
+ import { FensterPosition } from '../models/FensterPosition';
5
5
  import { Fenster } from '../Fenster';
6
6
  export declare class HmIpGriff extends HmIPDevice {
7
7
  position: FensterPosition;
@@ -7,7 +7,7 @@ const log_service_1 = require("../../services/log-service");
7
7
  const utils_1 = require("../../services/utils/utils");
8
8
  const weather_service_1 = require("../../services/weather/weather-service");
9
9
  const telegram_service_1 = require("../../services/Telegram/telegram-service");
10
- const FensterPosition_1 = require("../FensterPosition");
10
+ const FensterPosition_1 = require("../models/FensterPosition");
11
11
  const logLevel_1 = require("../../../models/logLevel");
12
12
  class HmIpGriff extends hmIpDevice_1.HmIPDevice {
13
13
  constructor(pInfo) {
@@ -5,7 +5,7 @@ const hmIpDevice_1 = require("./hmIpDevice");
5
5
  const deviceType_1 = require("../deviceType");
6
6
  const utils_1 = require("../../services/utils/utils");
7
7
  const log_service_1 = require("../../services/log-service");
8
- const FensterPosition_1 = require("../FensterPosition");
8
+ const FensterPosition_1 = require("../models/FensterPosition");
9
9
  const logLevel_1 = require("../../../models/logLevel");
10
10
  class HmIpRoll extends hmIpDevice_1.HmIPDevice {
11
11
  constructor(pInfo) {
@@ -1,16 +1,16 @@
1
1
  /// <reference types="iobroker" />
2
2
  import { HmIPDevice } from './hmIpDevice';
3
- import { TuerPosition } from './TuerPosition';
3
+ import { MagnetPosition } from '../models/MagnetPosition';
4
4
  import { DeviceInfo } from '../DeviceInfo';
5
5
  export declare class HmIpTuer extends HmIPDevice {
6
- position: TuerPosition;
6
+ position: MagnetPosition;
7
7
  private _closedCallback;
8
- private _offenCallback;
8
+ private _openCallback;
9
9
  private _iOpen;
10
10
  private minutesOpen;
11
11
  constructor(pInfo: DeviceInfo);
12
- addOffenCallback(pCallback: (pValue: boolean) => void): void;
12
+ addOpenCallback(pCallback: (pValue: boolean) => void): void;
13
13
  addClosedCallback(pCallback: (pValue: boolean) => void): void;
14
14
  update(idSplit: string[], state: ioBroker.State, initial?: boolean): void;
15
- updatePosition(pValue: TuerPosition): void;
15
+ updatePosition(pValue: MagnetPosition): void;
16
16
  }
@@ -5,20 +5,20 @@ const hmIpDevice_1 = require("./hmIpDevice");
5
5
  const deviceType_1 = require("../deviceType");
6
6
  const log_service_1 = require("../../services/log-service");
7
7
  const utils_1 = require("../../services/utils/utils");
8
- const TuerPosition_1 = require("./TuerPosition");
8
+ const MagnetPosition_1 = require("../models/MagnetPosition");
9
9
  const telegram_service_1 = require("../../services/Telegram/telegram-service");
10
10
  const logLevel_1 = require("../../../models/logLevel");
11
11
  const sonos_service_1 = require("../../services/Sonos/sonos-service");
12
12
  class HmIpTuer extends hmIpDevice_1.HmIPDevice {
13
13
  constructor(pInfo) {
14
14
  super(pInfo, deviceType_1.DeviceType.HmIpTuer);
15
- this.position = TuerPosition_1.TuerPosition.geschlossen;
15
+ this.position = MagnetPosition_1.MagnetPosition.closed;
16
16
  this._closedCallback = [];
17
- this._offenCallback = [];
17
+ this._openCallback = [];
18
18
  this.minutesOpen = 0;
19
19
  }
20
- addOffenCallback(pCallback) {
21
- this._offenCallback.push(pCallback);
20
+ addOpenCallback(pCallback) {
21
+ this._openCallback.push(pCallback);
22
22
  }
23
23
  addClosedCallback(pCallback) {
24
24
  this._closedCallback.push(pCallback);
@@ -30,7 +30,7 @@ class HmIpTuer extends hmIpDevice_1.HmIPDevice {
30
30
  case '1':
31
31
  if (idSplit[4] === 'STATE') {
32
32
  if (initial) {
33
- this.position = TuerPosition_1.TuerPosition.geschlossen;
33
+ this.position = MagnetPosition_1.MagnetPosition.closed;
34
34
  return;
35
35
  }
36
36
  this.updatePosition(state.val);
@@ -42,20 +42,20 @@ class HmIpTuer extends hmIpDevice_1.HmIPDevice {
42
42
  if (pValue === this.position) {
43
43
  return;
44
44
  }
45
- log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Trace, `Update Tür "${this.info.customName}"\nauf Position "${TuerPosition_1.TuerPosition[pValue]}"`);
45
+ log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Trace, `Update for Contact "${this.info.customName}" to position "${MagnetPosition_1.MagnetPosition[pValue]}"`);
46
46
  this.position = pValue;
47
47
  for (const c1 of this._closedCallback) {
48
48
  c1(pValue === 0);
49
49
  }
50
- for (const c2 of this._offenCallback) {
50
+ for (const c2 of this._openCallback) {
51
51
  c2(pValue === 1);
52
52
  }
53
- if (pValue === TuerPosition_1.TuerPosition.geschlossen) {
53
+ if (pValue === MagnetPosition_1.MagnetPosition.closed) {
54
54
  if (this._iOpen !== undefined) {
55
55
  clearInterval(this._iOpen);
56
- let message = `Die Haustür ist nun nach ${this.minutesOpen} Minuten wieder zu!`;
56
+ let message = `${this.info.customName} closed after ${this.minutesOpen} minutes!`;
57
57
  if (this.minutesOpen === 0) {
58
- message = 'Die Haustür ist wieder zu.';
58
+ message = `"${this.info.customName}" just closed`;
59
59
  }
60
60
  // const message: string = `Die Tür mit dem Namen "${this.info.customName}" wurde nach ${this.minutesOpen} Minuten geschlossen!`;
61
61
  log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Info, message);
@@ -66,13 +66,13 @@ class HmIpTuer extends hmIpDevice_1.HmIPDevice {
66
66
  return;
67
67
  }
68
68
  else if (this._iOpen === undefined) {
69
- const message = `Die Haustür wurde geöffnet!`;
69
+ const message = `"${this.info.customName}" was opened`;
70
70
  //const message: string = `Die Tür mit dem Namen "${this.info.customName}" wurde geöfnet!`
71
71
  telegram_service_1.TelegramService.inform(message);
72
72
  sonos_service_1.SonosService.speakOnAll(message, 40);
73
73
  this._iOpen = utils_1.Utils.guardedInterval(() => {
74
74
  this.minutesOpen++;
75
- const message = `Tuer: "${this.info.customName}" seit ${this.minutesOpen} Minuten auf Position ${TuerPosition_1.TuerPosition[this.position]}`;
75
+ const message = `Contact: "${this.info.customName}" is ${MagnetPosition_1.MagnetPosition[this.position]} since ${this.minutesOpen} minutes`;
76
76
  switch (this.minutesOpen) {
77
77
  case 2:
78
78
  case 5:
@@ -10,7 +10,7 @@ export * from './hmIpTaster';
10
10
  export * from './hmIpHeizung';
11
11
  export * from './hmIpBewegung';
12
12
  export * from './hmIpPraezenz';
13
- export * from './TuerPosition';
13
+ export * from '../models/MagnetPosition';
14
14
  export * from '../deviceType';
15
15
  export * from './hmIpHeizgruppe';
16
- export * from '../FensterPosition';
16
+ export * from '../models/FensterPosition';
@@ -22,7 +22,7 @@ __exportStar(require("./hmIpTaster"), exports);
22
22
  __exportStar(require("./hmIpHeizung"), exports);
23
23
  __exportStar(require("./hmIpBewegung"), exports);
24
24
  __exportStar(require("./hmIpPraezenz"), exports);
25
- __exportStar(require("./TuerPosition"), exports);
25
+ __exportStar(require("../models/MagnetPosition"), exports);
26
26
  __exportStar(require("../deviceType"), exports);
27
27
  __exportStar(require("./hmIpHeizgruppe"), exports);
28
- __exportStar(require("../FensterPosition"), exports);
28
+ __exportStar(require("../models/FensterPosition"), exports);
@@ -14,4 +14,5 @@ export * from './IoBrokerBaseDevice';
14
14
  export * from './iIlluminationSensor';
15
15
  export * from './groups/index';
16
16
  export * from './hmIPDevices/index';
17
+ export * from './models/index';
17
18
  export * from './zigbee/index';
@@ -26,4 +26,5 @@ __exportStar(require("./IoBrokerBaseDevice"), exports);
26
26
  __exportStar(require("./iIlluminationSensor"), exports);
27
27
  __exportStar(require("./groups/index"), exports);
28
28
  __exportStar(require("./hmIPDevices/index"), exports);
29
+ __exportStar(require("./models/index"), exports);
29
30
  __exportStar(require("./zigbee/index"), exports);
@@ -0,0 +1,4 @@
1
+ export declare enum MagnetPosition {
2
+ closed = 0,
3
+ open = 1
4
+ }
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MagnetPosition = void 0;
4
+ var MagnetPosition;
5
+ (function (MagnetPosition) {
6
+ MagnetPosition[MagnetPosition["closed"] = 0] = "closed";
7
+ MagnetPosition[MagnetPosition["open"] = 1] = "open";
8
+ })(MagnetPosition = exports.MagnetPosition || (exports.MagnetPosition = {}));
@@ -0,0 +1,2 @@
1
+ export * from './FensterPosition';
2
+ export * from './MagnetPosition';
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
10
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
11
+ };
12
+ Object.defineProperty(exports, "__esModule", { value: true });
13
+ __exportStar(require("./FensterPosition"), exports);
14
+ __exportStar(require("./MagnetPosition"), exports);
@@ -11,4 +11,6 @@ export * from './zigbeeIlluDimmer';
11
11
  export * from './zigbeeIlluLampe';
12
12
  export * from './zigbeeIlluLedRGBCCT';
13
13
  export * from './zigbeeIlluShutter';
14
+ export * from './zigbeeMagnetContact';
14
15
  export * from './zigbeeShutter';
16
+ export * from './zigbeeSMaBiTMagnetContact';
@@ -23,4 +23,6 @@ __exportStar(require("./zigbeeIlluDimmer"), exports);
23
23
  __exportStar(require("./zigbeeIlluLampe"), exports);
24
24
  __exportStar(require("./zigbeeIlluLedRGBCCT"), exports);
25
25
  __exportStar(require("./zigbeeIlluShutter"), exports);
26
+ __exportStar(require("./zigbeeMagnetContact"), exports);
26
27
  __exportStar(require("./zigbeeShutter"), exports);
28
+ __exportStar(require("./zigbeeSMaBiTMagnetContact"), exports);
@@ -8,10 +8,12 @@ export declare class ZigbeeIlluShutter extends ZigbeeShutter {
8
8
  private _msTilTop;
9
9
  private _msTilBot;
10
10
  private _movementStartPos;
11
+ private _shutterCalibrationData;
11
12
  constructor(pInfo: DeviceInfo);
12
13
  update(idSplit: string[], state: ioBroker.State, initial?: boolean): void;
13
14
  protected moveToPosition(targetPosition: number): void;
14
15
  private changeMovementState;
15
16
  private processNewMovementState;
16
17
  private isCalibrated;
18
+ private persistCalibrationData;
17
19
  }
@@ -6,6 +6,8 @@ const deviceType_1 = require("../deviceType");
6
6
  const log_service_1 = require("../../services/log-service");
7
7
  const logLevel_1 = require("../../../models/logLevel");
8
8
  const utils_1 = require("../../services/utils/utils");
9
+ const persist_1 = require("../../services/dbo/persist");
10
+ const ShutterCalibration_1 = require("../../../models/persistence/ShutterCalibration");
9
11
  var MovementState;
10
12
  (function (MovementState) {
11
13
  MovementState[MovementState["Down"] = 30] = "Down";
@@ -20,7 +22,17 @@ class ZigbeeIlluShutter extends zigbeeShutter_1.ZigbeeShutter {
20
22
  this._msTilTop = -1;
21
23
  this._msTilBot = -1;
22
24
  this._movementStartPos = -1;
25
+ this._shutterCalibrationData = new ShutterCalibration_1.ShutterCalibration(this.info.fullID, 0, 0, 0, 0);
23
26
  this._movementStateId = `${this.info.fullID}.position`;
27
+ // this.presenceStateID = `${this.info.fullID}.1.${HmIpPraezenz.PRESENCE_DETECTION}`;
28
+ persist_1.Persist.getShutterCalibration(this)
29
+ .then((calibrationData) => {
30
+ this._shutterCalibrationData = calibrationData;
31
+ log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.DeepTrace, `IlluShutter "${this.info.customName}" initialized with calibration data`);
32
+ })
33
+ .catch((err) => {
34
+ log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Warn, `Failed to initialize Calibration data for "${this.info.customName}", err ${err.message}`);
35
+ });
24
36
  }
25
37
  update(idSplit, state, initial = false) {
26
38
  switch (idSplit[3]) {
@@ -74,12 +86,20 @@ class ZigbeeIlluShutter extends zigbeeShutter_1.ZigbeeShutter {
74
86
  this._msTilTop = timePassed;
75
87
  log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Debug, `New Time-Until-Top measurement for ${this.info.customName}: ${timePassed}ms`);
76
88
  this.currentLevel = this._setLevel;
89
+ this._shutterCalibrationData.counterUp++;
90
+ this._shutterCalibrationData.averageUp +=
91
+ (this._msTilTop - this._shutterCalibrationData.averageUp) / this._shutterCalibrationData.counterUp;
92
+ this.persistCalibrationData();
77
93
  return;
78
94
  }
79
95
  if (this._movementStartPos === 100 && oldState === MovementState.Down && this._setLevel === 0) {
80
96
  log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Debug, `New Time-Until-Bottom measurement for ${this.info.customName}: ${timePassed}ms`);
81
97
  this._msTilBot = timePassed;
82
98
  this.currentLevel = this._setLevel;
99
+ this._shutterCalibrationData.counterDown++;
100
+ this._shutterCalibrationData.averageDown +=
101
+ (this._msTilBot - this._shutterCalibrationData.averageDown) / this._shutterCalibrationData.counterDown;
102
+ this.persistCalibrationData();
83
103
  return;
84
104
  }
85
105
  if (!this.isCalibrated()) {
@@ -93,7 +113,10 @@ class ZigbeeIlluShutter extends zigbeeShutter_1.ZigbeeShutter {
93
113
  }
94
114
  }
95
115
  isCalibrated() {
96
- return this._msTilTop > 0 && this._msTilBot > 0;
116
+ return this._shutterCalibrationData.averageUp > 0 && this._shutterCalibrationData.averageDown > 0;
117
+ }
118
+ persistCalibrationData() {
119
+ persist_1.Persist.persistShutterCalibration(this._shutterCalibrationData);
97
120
  }
98
121
  }
99
122
  exports.ZigbeeIlluShutter = ZigbeeIlluShutter;
@@ -0,0 +1,17 @@
1
+ /// <reference types="iobroker" />
2
+ import { DeviceType } from '../deviceType';
3
+ import { DeviceInfo } from '../DeviceInfo';
4
+ import { ZigbeeDevice } from './zigbeeDevice';
5
+ import { MagnetPosition } from '../models/MagnetPosition';
6
+ export declare class ZigbeeMagnetContact extends ZigbeeDevice {
7
+ position: MagnetPosition;
8
+ private _closedCallback;
9
+ private _openCallback;
10
+ private _iOpen;
11
+ private minutesOpen;
12
+ constructor(pInfo: DeviceInfo, deviceType: DeviceType);
13
+ addOpenCallback(pCallback: (pValue: boolean) => void): void;
14
+ addClosedCallback(pCallback: (pValue: boolean) => void): void;
15
+ update(idSplit: string[], state: ioBroker.State, initial?: boolean, pOverrride?: boolean): void;
16
+ protected updatePosition(pValue: MagnetPosition): void;
17
+ }
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZigbeeMagnetContact = void 0;
4
+ const log_service_1 = require("../../services/log-service");
5
+ const utils_1 = require("../../services/utils/utils");
6
+ const telegram_service_1 = require("../../services/Telegram/telegram-service");
7
+ const logLevel_1 = require("../../../models/logLevel");
8
+ const sonos_service_1 = require("../../services/Sonos/sonos-service");
9
+ const zigbeeDevice_1 = require("./zigbeeDevice");
10
+ const MagnetPosition_1 = require("../models/MagnetPosition");
11
+ class ZigbeeMagnetContact extends zigbeeDevice_1.ZigbeeDevice {
12
+ constructor(pInfo, deviceType) {
13
+ super(pInfo, deviceType);
14
+ this.position = MagnetPosition_1.MagnetPosition.closed;
15
+ this._closedCallback = [];
16
+ this._openCallback = [];
17
+ this.minutesOpen = 0;
18
+ }
19
+ addOpenCallback(pCallback) {
20
+ this._openCallback.push(pCallback);
21
+ }
22
+ addClosedCallback(pCallback) {
23
+ this._closedCallback.push(pCallback);
24
+ }
25
+ update(idSplit, state, initial = false, pOverrride = false) {
26
+ super.update(idSplit, state, initial, pOverrride);
27
+ }
28
+ updatePosition(pValue) {
29
+ if (pValue === this.position) {
30
+ return;
31
+ }
32
+ log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Trace, `Update for Contact "${this.info.customName}" to position "${MagnetPosition_1.MagnetPosition[pValue]}"`);
33
+ this.position = pValue;
34
+ for (const c1 of this._closedCallback) {
35
+ c1(pValue === 0);
36
+ }
37
+ for (const c2 of this._openCallback) {
38
+ c2(pValue === 1);
39
+ }
40
+ if (pValue === MagnetPosition_1.MagnetPosition.closed) {
41
+ if (this._iOpen !== undefined) {
42
+ clearInterval(this._iOpen);
43
+ let message = `${this.info.customName} closed after ${this.minutesOpen} minutes!`;
44
+ if (this.minutesOpen === 0) {
45
+ message = `"${this.info.customName}" just closed`;
46
+ }
47
+ // const message: string = `Die Tür mit dem Namen "${this.info.customName}" wurde nach ${this.minutesOpen} Minuten geschlossen!`;
48
+ log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Info, message);
49
+ telegram_service_1.TelegramService.inform(message);
50
+ this.minutesOpen = 0;
51
+ this._iOpen = undefined;
52
+ }
53
+ return;
54
+ }
55
+ else if (this._iOpen === undefined) {
56
+ const message = `"${this.info.customName}" was opened`;
57
+ //const message: string = `Die Tür mit dem Namen "${this.info.customName}" wurde geöfnet!`
58
+ telegram_service_1.TelegramService.inform(message);
59
+ sonos_service_1.SonosService.speakOnAll(message, 40);
60
+ this._iOpen = utils_1.Utils.guardedInterval(() => {
61
+ this.minutesOpen++;
62
+ const message = `Contact: "${this.info.customName}" is ${MagnetPosition_1.MagnetPosition[this.position]} since ${this.minutesOpen} minutes`;
63
+ switch (this.minutesOpen) {
64
+ case 2:
65
+ case 5:
66
+ case 10:
67
+ case 20:
68
+ case 45:
69
+ case 60:
70
+ log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Info, message);
71
+ telegram_service_1.TelegramService.inform(message);
72
+ break;
73
+ default:
74
+ log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.Trace, message);
75
+ break;
76
+ }
77
+ }, 60000, this);
78
+ }
79
+ }
80
+ }
81
+ exports.ZigbeeMagnetContact = ZigbeeMagnetContact;
@@ -0,0 +1,7 @@
1
+ /// <reference types="iobroker" />
2
+ import { ZigbeeMagnetContact } from './zigbeeMagnetContact';
3
+ import { DeviceInfo } from '../DeviceInfo';
4
+ export declare class ZigbeeSMaBiTMagnetContact extends ZigbeeMagnetContact {
5
+ constructor(pInfo: DeviceInfo);
6
+ update(idSplit: string[], state: ioBroker.State, initial?: boolean): void;
7
+ }
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ZigbeeSMaBiTMagnetContact = void 0;
4
+ const zigbeeMagnetContact_1 = require("./zigbeeMagnetContact");
5
+ const log_service_1 = require("../../services/log-service");
6
+ const logLevel_1 = require("../../../models/logLevel");
7
+ const MagnetPosition_1 = require("../models/MagnetPosition");
8
+ const deviceType_1 = require("../deviceType");
9
+ class ZigbeeSMaBiTMagnetContact extends zigbeeMagnetContact_1.ZigbeeMagnetContact {
10
+ constructor(pInfo) {
11
+ super(pInfo, deviceType_1.DeviceType.ZigbeeSMaBiTMagnetContact);
12
+ }
13
+ update(idSplit, state, initial = false) {
14
+ log_service_1.ServerLogService.writeLog(logLevel_1.LogLevel.DeepTrace, `Magnet Contact Update: JSON: ${JSON.stringify(state)}ID: ${idSplit.join('.')}`);
15
+ super.update(idSplit, state, initial, true);
16
+ switch (idSplit[3]) {
17
+ case 'opened':
18
+ this.updatePosition(state.val ? MagnetPosition_1.MagnetPosition.open : MagnetPosition_1.MagnetPosition.closed);
19
+ break;
20
+ }
21
+ }
22
+ }
23
+ exports.ZigbeeSMaBiTMagnetContact = ZigbeeSMaBiTMagnetContact;