node-red-contrib-homekit-bridged 1.7.0-dev.1 → 1.7.0-dev.11

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.
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2019 Node-RED Contribution - HomeKit Bridged
3
+ Copyright (c) 2024 Node-RED Contribution - HomeKit Bridged
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
@@ -22,7 +22,7 @@ const HostType_1 = __importDefault(require("./types/HostType"));
22
22
  module.exports = (RED, hostType) => {
23
23
  const MdnsUtils = require('./utils/MdnsUtils')();
24
24
  const init = function (config) {
25
- var _a, _b, _c, _d, _e;
25
+ var _a, _b, _c, _d, _e, _f;
26
26
  const self = this;
27
27
  const log = (0, logger_1.logger)('NRCHKB', 'HAPHostNode', config.bridgeName, self);
28
28
  self.hostType = hostType;
@@ -36,7 +36,8 @@ module.exports = (RED, hostType) => {
36
36
  if (preload_1.default.parse(config.firmwareRev) == null) {
37
37
  config.firmwareRev = new semver_1.SemVer('0.0.0');
38
38
  }
39
- if (config.customMdnsConfig) {
39
+ if (!((_a = config.bind) === null || _a === void 0 ? void 0 : _a.length) && config.customMdnsConfig) {
40
+ log.error('Custom mdns config is deprecated, use bind instead!');
40
41
  self.mdnsConfig = {};
41
42
  if (MdnsUtils.checkMulticast(config.mdnsMulticast)) {
42
43
  self.mdnsConfig.multicast = config.mdnsMulticast;
@@ -45,13 +46,13 @@ module.exports = (RED, hostType) => {
45
46
  self.mdnsConfig.interface = config.mdnsInterface;
46
47
  }
47
48
  if (MdnsUtils.checkPort(config.mdnsPort)) {
48
- self.mdnsConfig.port = parseInt((_a = config.mdnsPort) === null || _a === void 0 ? void 0 : _a.toString());
49
+ self.mdnsConfig.port = parseInt((_b = config.mdnsPort) === null || _b === void 0 ? void 0 : _b.toString());
49
50
  }
50
51
  if (MdnsUtils.checkIp(config.mdnsIp)) {
51
52
  self.mdnsConfig.ip = config.mdnsIp;
52
53
  }
53
54
  if (MdnsUtils.checkTtl(config.mdnsTtl)) {
54
- self.mdnsConfig.ttl = parseInt((_b = config.mdnsTtl) === null || _b === void 0 ? void 0 : _b.toString());
55
+ self.mdnsConfig.ttl = parseInt((_c = config.mdnsTtl) === null || _c === void 0 ? void 0 : _c.toString());
55
56
  }
56
57
  if (MdnsUtils.checkLoopback(config.mdnsLoopback)) {
57
58
  self.mdnsConfig.loopback = config.mdnsLoopback;
@@ -81,7 +82,7 @@ module.exports = (RED, hostType) => {
81
82
  self.host = new hap_nodejs_1.Accessory(self.name, hostUUID);
82
83
  }
83
84
  self.publish = function () {
84
- var _a, _b, _c;
85
+ var _a, _b, _c, _d;
85
86
  if (self.hostType == HostType_1.default.BRIDGE) {
86
87
  log.debug(`Publishing ${hostTypeName} with pin code ${self.config.pinCode} and ${self.host.bridgedAccessories.length} accessories`);
87
88
  }
@@ -99,6 +100,15 @@ module.exports = (RED, hostType) => {
99
100
  oldPinCode = oldPinCode.replace(/-/g, '');
100
101
  oldPinCode = `${oldPinCode.slice(0, 3)}-${oldPinCode.slice(3, 5)}-${oldPinCode.slice(5, 8)}`;
101
102
  }
103
+ let bind;
104
+ if (((_c = self.config.bind) === null || _c === void 0 ? void 0 : _c.length) && self.config.bindType) {
105
+ if (self.config.bindType == 'str') {
106
+ bind = self.config.bind;
107
+ }
108
+ else if (self.config.bindType == 'json') {
109
+ bind = JSON.parse(self.config.bind);
110
+ }
111
+ }
102
112
  self.host.publish({
103
113
  username: self.bridgeUsername,
104
114
  port: self.config.port && !isNaN(self.config.port)
@@ -107,7 +117,8 @@ module.exports = (RED, hostType) => {
107
117
  pincode: oldPinCode,
108
118
  category: self.accessoryCategory,
109
119
  mdns: self.mdnsConfig,
110
- advertiser: (_c = self.config.advertiser) !== null && _c !== void 0 ? _c : "bonjour-hap",
120
+ bind: bind,
121
+ advertiser: (_d = self.config.advertiser) !== null && _d !== void 0 ? _d : "bonjour-hap",
111
122
  }, self.config.allowInsecureRequest);
112
123
  self.published = true;
113
124
  return true;
@@ -141,9 +152,9 @@ module.exports = (RED, hostType) => {
141
152
  .setCharacteristic(hap_nodejs_1.Characteristic.Manufacturer, self.config.manufacturer)
142
153
  .setCharacteristic(hap_nodejs_1.Characteristic.SerialNumber, self.config.serialNo)
143
154
  .setCharacteristic(hap_nodejs_1.Characteristic.Model, self.config.model)
144
- .setCharacteristic(hap_nodejs_1.Characteristic.FirmwareRevision, (_c = self.config.firmwareRev) === null || _c === void 0 ? void 0 : _c.toString())
145
- .setCharacteristic(hap_nodejs_1.Characteristic.HardwareRevision, (_d = self.config.hardwareRev) === null || _d === void 0 ? void 0 : _d.toString())
146
- .setCharacteristic(hap_nodejs_1.Characteristic.SoftwareRevision, (_e = self.config.softwareRev) === null || _e === void 0 ? void 0 : _e.toString());
155
+ .setCharacteristic(hap_nodejs_1.Characteristic.FirmwareRevision, (_d = self.config.firmwareRev) === null || _d === void 0 ? void 0 : _d.toString())
156
+ .setCharacteristic(hap_nodejs_1.Characteristic.HardwareRevision, (_e = self.config.hardwareRev) === null || _e === void 0 ? void 0 : _e.toString())
157
+ .setCharacteristic(hap_nodejs_1.Characteristic.SoftwareRevision, (_f = self.config.softwareRev) === null || _f === void 0 ? void 0 : _f.toString());
147
158
  };
148
159
  const macify = (nodeId) => {
149
160
  if (nodeId) {
@@ -95,8 +95,9 @@ module.exports = (RED) => {
95
95
  : self.config.accessoryId;
96
96
  self.hostNode = RED.nodes.getNode(hostId);
97
97
  if (!self.hostNode) {
98
- log.error('Host Node not found', false);
99
- throw new NRCHKBError_1.default('Host Node not found');
98
+ const message = `Host node ${self.config.hostType == HostType_1.default.BRIDGE ? 'Bridge' : 'Standalone Accessory'} ${hostId} not found`;
99
+ log.error(message, false);
100
+ throw new NRCHKBError_1.default(message);
100
101
  }
101
102
  self.childNodes = [];
102
103
  self.childNodes.push(self);
@@ -161,6 +162,7 @@ module.exports = (RED) => {
161
162
  config: self.config,
162
163
  }, self.parentService);
163
164
  self.characteristicProperties = CharacteristicUtils.load(self.service, self.config);
165
+ ServiceUtils.configureAdaptiveLightning();
164
166
  if (self.config.isParent) {
165
167
  BridgeUtils.delayedPublish(self);
166
168
  }
@@ -95,8 +95,9 @@ module.exports = (RED) => {
95
95
  : self.config.accessoryId;
96
96
  self.hostNode = RED.nodes.getNode(hostId);
97
97
  if (!self.hostNode) {
98
- log.error('Host Node not found', false);
99
- throw new NRCHKBError_1.default('Host Node not found');
98
+ const message = `Host node ${self.config.hostType == HostType_1.default.BRIDGE ? 'Bridge' : 'Standalone Accessory'} ${hostId} not found`;
99
+ log.error(message, false);
100
+ throw new NRCHKBError_1.default(message);
100
101
  }
101
102
  self.childNodes = [];
102
103
  self.childNodes.push(self);
@@ -161,6 +162,7 @@ module.exports = (RED) => {
161
162
  config: self.config,
162
163
  }, self.parentService);
163
164
  self.characteristicProperties = CharacteristicUtils.load(self.service, self.config);
165
+ ServiceUtils.configureAdaptiveLightning();
164
166
  if (self.config.isParent) {
165
167
  BridgeUtils.delayedPublish(self);
166
168
  }
package/build/lib/api.js CHANGED
@@ -25,6 +25,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  const logger_1 = require("@nrchkb/logger");
27
27
  const hap_nodejs_1 = require("hap-nodejs");
28
+ const EveCharacteristics_1 = __importDefault(require("./hap/eve-app/EveCharacteristics"));
28
29
  const Storage_1 = require("./Storage");
29
30
  const HapCategories_1 = __importDefault(require("./types/hap-nodejs/HapCategories"));
30
31
  const version = require('../../package.json').version.trim();
@@ -127,9 +128,9 @@ module.exports = function (RED) {
127
128
  });
128
129
  };
129
130
  const _initNRCHKBCustomCharacteristicsAPI = () => __awaiter(this, void 0, void 0, function* () {
130
- const getCustomCharacteristics = () => {
131
- return Storage_1.Storage.loadCustomCharacteristics()
132
- .then((value) => {
131
+ const getCustomCharacteristics = () => __awaiter(this, void 0, void 0, function* () {
132
+ try {
133
+ const value = yield Storage_1.Storage.loadCustomCharacteristics();
133
134
  log.trace('loadCustomCharacteristics()');
134
135
  log.trace(value);
135
136
  if (Array.isArray(value)) {
@@ -137,14 +138,14 @@ module.exports = function (RED) {
137
138
  }
138
139
  else {
139
140
  log.debug('customCharacteristics is not Array, returning empty value');
140
- return [];
141
+ return EveCharacteristics_1.default;
141
142
  }
142
- })
143
- .catch((error) => {
143
+ }
144
+ catch (error) {
144
145
  log.error(`Failed to get customCharacteristics in nrchkbStorage due to ${error}`);
145
- return [];
146
- });
147
- };
146
+ return EveCharacteristics_1.default;
147
+ }
148
+ });
148
149
  const characteristicNameToKey = (name) => {
149
150
  return name.replace(' ', '');
150
151
  };
@@ -260,7 +261,7 @@ module.exports = function (RED) {
260
261
  });
261
262
  }));
262
263
  RED.httpAdmin.post('/nrchkb/config', RED.auth.needsPermission('nrchkb.write'), (req, res) => __awaiter(this, void 0, void 0, function* () {
263
- const customCharacteristics = req.body.customCharacteristics || [];
264
+ const customCharacteristics = req.body.customCharacteristics || EveCharacteristics_1.default;
264
265
  Storage_1.Storage.saveCustomCharacteristics(customCharacteristics)
265
266
  .then(() => {
266
267
  res.sendStatus(200);
@@ -0,0 +1,9 @@
1
+ import { Characteristic } from 'hap-nodejs';
2
+ import { EveS2R1, EveS2R2, EveS2W1, EveS2W2 } from './eve-app/EveCharacteristics';
3
+ declare class HAPCharacteristic extends Characteristic {
4
+ static EveS2R1: typeof EveS2R1;
5
+ static EveS2R2: typeof EveS2R2;
6
+ static EveS2W1: typeof EveS2W1;
7
+ static EveS2W2: typeof EveS2W2;
8
+ }
9
+ export default HAPCharacteristic;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const hap_nodejs_1 = require("hap-nodejs");
4
+ class HAPCharacteristic extends hap_nodejs_1.Characteristic {
5
+ }
6
+ exports.default = HAPCharacteristic;
@@ -0,0 +1,6 @@
1
+ import { Service } from 'hap-nodejs';
2
+ import { EveHistoryData } from './eve-app/EveServices';
3
+ declare class HAPService extends Service {
4
+ static EveHistoryData: typeof EveHistoryData;
5
+ }
6
+ export default HAPService;
@@ -0,0 +1,6 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const hap_nodejs_1 = require("hap-nodejs");
4
+ class HAPService extends hap_nodejs_1.Service {
5
+ }
6
+ exports.default = HAPService;
@@ -0,0 +1,20 @@
1
+ import CustomCharacteristicType from '../../types/CustomCharacteristicType';
2
+ import HAPCharacteristic from '../HAPCharacteristic';
3
+ declare const EveCharacteristics: CustomCharacteristicType[];
4
+ export declare class EveS2R1 extends HAPCharacteristic {
5
+ static readonly UUID: string;
6
+ constructor();
7
+ }
8
+ export declare class EveS2R2 extends HAPCharacteristic {
9
+ static readonly UUID: string;
10
+ constructor();
11
+ }
12
+ export declare class EveS2W1 extends HAPCharacteristic {
13
+ static readonly UUID: string;
14
+ constructor();
15
+ }
16
+ export declare class EveS2W2 extends HAPCharacteristic {
17
+ static readonly UUID: string;
18
+ constructor();
19
+ }
20
+ export default EveCharacteristics;
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.EveS2W2 = exports.EveS2W1 = exports.EveS2R2 = exports.EveS2R1 = void 0;
7
+ const HAPCharacteristic_1 = __importDefault(require("../HAPCharacteristic"));
8
+ const EveCharacteristics = [
9
+ {
10
+ UUID: 'E863F10A-079E-48FF-8F27-9C2605A29F52',
11
+ name: 'Eve-Volt',
12
+ format: "float",
13
+ perms: ["pr"],
14
+ description: 'Volt (V) value. Used by Eve.app.',
15
+ },
16
+ {
17
+ UUID: 'E863F126-079E-48FF-8F27-9C2605A29F52',
18
+ name: 'Eve-Ampere',
19
+ format: "float",
20
+ perms: ["pr"],
21
+ description: 'Ampere (A) value. Used by Eve.app.',
22
+ },
23
+ {
24
+ UUID: 'E863F10D-079E-48FF-8F27-9C2605A29F52',
25
+ name: 'Eve-Watt',
26
+ format: "float",
27
+ perms: ["pr"],
28
+ description: 'Watt (W) value. Used by Eve.app, reported as "Consumption".',
29
+ },
30
+ {
31
+ UUID: 'E863F10C-079E-48FF-8F27-9C2605A29F52',
32
+ name: 'Eve-Kilowatt-hour',
33
+ format: "float",
34
+ perms: ["pr"],
35
+ description: 'Kilowatt-hour (kWh) value. Used by Eve.app, reported as Total Consumption.',
36
+ },
37
+ {
38
+ UUID: 'E863F110-079E-48FF-8F27-9C2605A29F52',
39
+ name: 'Eve-Volt-Ampere',
40
+ format: "uint16",
41
+ perms: ["pr"],
42
+ description: 'Volt-Ampere (VA) value. Used by Eve.app.',
43
+ },
44
+ ];
45
+ class EveS2R1 extends HAPCharacteristic_1.default {
46
+ constructor() {
47
+ super('Eve-S2R1', EveS2R1.UUID, {
48
+ format: "data",
49
+ perms: ["pr", "ev", "hd"],
50
+ });
51
+ }
52
+ }
53
+ exports.EveS2R1 = EveS2R1;
54
+ EveS2R1.UUID = 'E863F116-079E-48FF-8F27-9C2605A29F52';
55
+ HAPCharacteristic_1.default.EveS2R1 = EveS2R1;
56
+ class EveS2R2 extends HAPCharacteristic_1.default {
57
+ constructor() {
58
+ super('Eve-S2R2', EveS2R2.UUID, {
59
+ format: "data",
60
+ perms: ["pr", "ev", "hd"],
61
+ });
62
+ }
63
+ }
64
+ exports.EveS2R2 = EveS2R2;
65
+ EveS2R2.UUID = 'E863F117-079E-48FF-8F27-9C2605A29F52';
66
+ HAPCharacteristic_1.default.EveS2R2 = EveS2R2;
67
+ class EveS2W1 extends HAPCharacteristic_1.default {
68
+ constructor() {
69
+ super('Eve-S2W1', EveS2W1.UUID, {
70
+ format: "data",
71
+ perms: ["pw", "hd"],
72
+ });
73
+ }
74
+ }
75
+ exports.EveS2W1 = EveS2W1;
76
+ EveS2W1.UUID = 'E863F11C-079E-48FF-8F27-9C2605A29F52';
77
+ HAPCharacteristic_1.default.EveS2W1 = EveS2W1;
78
+ class EveS2W2 extends HAPCharacteristic_1.default {
79
+ constructor() {
80
+ super('Eve-S2W2', EveS2W2.UUID, {
81
+ format: "data",
82
+ perms: ["pw", "hd"],
83
+ });
84
+ }
85
+ }
86
+ exports.EveS2W2 = EveS2W2;
87
+ EveS2W2.UUID = 'E863F121-079E-48FF-8F27-9C2605A29F52';
88
+ HAPCharacteristic_1.default.EveS2W2 = EveS2W2;
89
+ exports.default = EveCharacteristics;
@@ -0,0 +1,5 @@
1
+ import HAPService from '../HAPService';
2
+ export declare class EveHistoryData extends HAPService {
3
+ static readonly UUID: string;
4
+ constructor();
5
+ }
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.EveHistoryData = void 0;
7
+ const HAPCharacteristic_1 = __importDefault(require("../HAPCharacteristic"));
8
+ const HAPService_1 = __importDefault(require("../HAPService"));
9
+ class EveHistoryData extends HAPService_1.default {
10
+ constructor() {
11
+ super('EveHistoryData', EveHistoryData.UUID);
12
+ this.addCharacteristic(HAPCharacteristic_1.default.EveS2R1);
13
+ this.addCharacteristic(HAPCharacteristic_1.default.EveS2R2);
14
+ this.addCharacteristic(HAPCharacteristic_1.default.EveS2W1);
15
+ this.addCharacteristic(HAPCharacteristic_1.default.EveS2W2);
16
+ }
17
+ }
18
+ exports.EveHistoryData = EveHistoryData;
19
+ EveHistoryData.UUID = 'E863F007-079E-48FF-8F27-9C2605A29F52';
20
+ HAPService_1.default.EveHistoryData = EveHistoryData;
@@ -13,6 +13,8 @@ type HAPHostConfigType = NodeDef & {
13
13
  firmwareRev: SemVer;
14
14
  hardwareRev: SemVer;
15
15
  softwareRev: SemVer;
16
+ bind?: string;
17
+ bindType?: 'json' | 'str';
16
18
  customMdnsConfig: boolean;
17
19
  mdnsMulticast: boolean;
18
20
  mdnsInterface: string;
@@ -1,12 +1,11 @@
1
- /// <reference types="hap-nodejs/@types/bonjour-hap" />
2
- import { MulticastOptions } from 'bonjour-hap';
3
1
  import { Accessory, Categories } from 'hap-nodejs';
2
+ import BonjourMulticastOptions from './hap-nodejs/BonjourMulticastOptions';
4
3
  import HAPHostConfigType from './HAPHostConfigType';
5
4
  import HostType from './HostType';
6
5
  import NodeType from './NodeType';
7
6
  type HAPHostNodeType = NodeType & {
8
7
  config: HAPHostConfigType;
9
- mdnsConfig: MulticastOptions;
8
+ mdnsConfig: BonjourMulticastOptions;
10
9
  accessoryCategory: Categories;
11
10
  published: boolean;
12
11
  bridgeUsername: string;
@@ -1,4 +1,4 @@
1
- import { Accessory, Characteristic, CharacteristicChange, CharacteristicGetCallback, CharacteristicProps, CharacteristicSetCallback, CharacteristicValue, Service } from 'hap-nodejs';
1
+ import { Accessory, AdaptiveLightingController, Characteristic, CharacteristicChange, CharacteristicGetCallback, CharacteristicProps, CharacteristicSetCallback, CharacteristicValue, Service } from 'hap-nodejs';
2
2
  import { HAPConnection } from 'hap-nodejs/dist/lib/util/eventedhttp';
3
3
  import { NodeAPI } from 'node-red';
4
4
  import { NodeStatusUtils } from '../utils/NodeStatusUtils';
@@ -32,5 +32,6 @@ type HAPServiceNodeType = NodeType & {
32
32
  uniqueIdentifier: string;
33
33
  reachable?: boolean;
34
34
  nodeStatusUtils: NodeStatusUtils;
35
+ adaptiveLightingController?: AdaptiveLightingController;
35
36
  };
36
37
  export default HAPServiceNodeType;
@@ -1,4 +1,3 @@
1
- /// <reference types="node" />
2
1
  type PublishTimersType = {
3
2
  [key: string]: NodeJS.Timeout;
4
3
  };
@@ -0,0 +1,10 @@
1
+ type BonjourMulticastOptions = {
2
+ multicast?: boolean;
3
+ interface?: string;
4
+ port?: number;
5
+ ip?: string;
6
+ ttl?: number;
7
+ loopback?: boolean;
8
+ reuseAddr?: boolean;
9
+ };
10
+ export default BonjourMulticastOptions;
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -1,4 +1,3 @@
1
- /// <reference types="node-red__registry" />
2
1
  import { NodeStatus } from '@node-red/registry';
3
2
  import NodeType from '../types/NodeType';
4
3
  type StatusType = 'NO_RESPONSE' | 'MSG';
@@ -1,8 +1,32 @@
1
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
26
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
27
  };
5
28
  Object.defineProperty(exports, "__esModule", { value: true });
29
+ const util = __importStar(require("node:util"));
6
30
  const logger_1 = require("@nrchkb/logger");
7
31
  const hap_nodejs_1 = require("hap-nodejs");
8
32
  const NRCHKBError_1 = __importDefault(require("../NRCHKBError"));
@@ -32,7 +56,7 @@ module.exports = function (node) {
32
56
  };
33
57
  const onCharacteristicGet = function (callback, context, connection) {
34
58
  var _a, _b;
35
- log.debug(`onCharacteristicGet with status: ${this.statusCode}, value: ${this.value}, reachability is ${((_a = node.parentNode) !== null && _a !== void 0 ? _a : node).reachable} with context ${JSON.stringify(context)} on connection ${connection === null || connection === void 0 ? void 0 : connection.sessionID}`);
59
+ log.debug(`onCharacteristicGet with status: ${this.statusCode}, value: ${this.value}, reachability is ${((_a = node.parentNode) !== null && _a !== void 0 ? _a : node).reachable} with context ${util.inspect(context)} on connection ${connection === null || connection === void 0 ? void 0 : connection.sessionID}`);
36
60
  if (callback) {
37
61
  try {
38
62
  callback(((_b = node.parentNode) !== null && _b !== void 0 ? _b : node).reachable
@@ -92,7 +116,7 @@ module.exports = function (node) {
92
116
  const onCharacteristicSet = (allCharacteristics) => function (newValue, callback, context, connection) {
93
117
  var _a, _b;
94
118
  log.debug(`onCharacteristicSet with status: ${this.statusCode}, value: ${this.value}, reachability is ${((_a = node.parentNode) !== null && _a !== void 0 ? _a : node).reachable}
95
- with context ${JSON.stringify(context)} on connection ${connection === null || connection === void 0 ? void 0 : connection.sessionID}`);
119
+ with context ${util.inspect(context)} on connection ${connection === null || connection === void 0 ? void 0 : connection.sessionID}`);
96
120
  try {
97
121
  if (callback) {
98
122
  callback(((_b = node.parentNode) !== null && _b !== void 0 ? _b : node).reachable
@@ -110,7 +134,7 @@ module.exports = function (node) {
110
134
  var _a;
111
135
  const { oldValue, newValue, context, originator, reason } = change;
112
136
  log.debug(`onCharacteristicChange with reason: ${reason}, oldValue: ${oldValue}, newValue: ${newValue}, reachability is ${((_a = node.parentNode) !== null && _a !== void 0 ? _a : node).reachable}
113
- with context ${JSON.stringify(context)} on connection ${originator === null || originator === void 0 ? void 0 : originator.sessionID}`);
137
+ with context ${util.inspect(context)} on connection ${originator === null || originator === void 0 ? void 0 : originator.sessionID}`);
114
138
  if (oldValue != newValue) {
115
139
  onValueChange.call(this, allCharacteristics, 0, {
116
140
  oldValue,
@@ -120,7 +144,8 @@ module.exports = function (node) {
120
144
  }
121
145
  };
122
146
  const onInput = function (msg) {
123
- if (msg.hasOwnProperty('payload')) {
147
+ var _a, _b;
148
+ if (msg.payload) {
124
149
  const type = typeof msg.payload;
125
150
  if (type !== 'object') {
126
151
  log.error(`Invalid payload type: ${type}`);
@@ -131,29 +156,39 @@ module.exports = function (node) {
131
156
  log.error('Invalid message (payload missing)');
132
157
  return;
133
158
  }
134
- const topic = node.config.topic ? node.config.topic : node.name;
159
+ const topic = (_a = node.config.topic) !== null && _a !== void 0 ? _a : node.name;
135
160
  if (node.config.filter && msg.topic !== topic) {
136
161
  log.debug("msg.topic doesn't match configured value and filter is enabled. Dropping message.");
137
162
  return;
138
163
  }
139
164
  let context = null;
140
- if (msg.payload.hasOwnProperty('Context')) {
165
+ if (msg.payload.Context) {
141
166
  context = msg.payload.Context;
142
167
  delete msg.payload.Context;
143
168
  }
144
- node.topic_in = msg.topic ? msg.topic : '';
169
+ node.topic_in = (_b = msg.topic) !== null && _b !== void 0 ? _b : '';
145
170
  Object.keys(msg.payload).map((key) => {
146
- var _a, _b;
171
+ var _a, _b, _c, _d;
147
172
  if (node.supported.indexOf(key) < 0) {
148
- log.error(`Instead of '${key}' try one of these characteristics: '${node.supported.join("', '")}'`);
173
+ if (key === 'AdaptiveLightingController' &&
174
+ node.adaptiveLightingController) {
175
+ const value = (_a = msg.payload) === null || _a === void 0 ? void 0 : _a[key];
176
+ const event = value === null || value === void 0 ? void 0 : value.event;
177
+ if (event === 'disable') {
178
+ (_b = node.adaptiveLightingController) === null || _b === void 0 ? void 0 : _b.disableAdaptiveLighting();
179
+ }
180
+ }
181
+ else {
182
+ log.error(`Instead of '${key}' try one of these characteristics: '${node.supported.join("', '")}'`);
183
+ }
149
184
  }
150
185
  else {
151
- const value = (_a = msg.payload) === null || _a === void 0 ? void 0 : _a[key];
152
- const parentNode = (_b = node.parentNode) !== null && _b !== void 0 ? _b : node;
186
+ const value = (_c = msg.payload) === null || _c === void 0 ? void 0 : _c[key];
187
+ const parentNode = (_d = node.parentNode) !== null && _d !== void 0 ? _d : node;
153
188
  parentNode.reachable = value !== NO_RESPONSE_MSG;
154
189
  const characteristic = node.service.getCharacteristic(Characteristic[key]);
155
190
  if (context !== null) {
156
- characteristic.setValue(value, context);
191
+ characteristic.setValue(value, undefined, context);
157
192
  }
158
193
  else {
159
194
  characteristic.setValue(value);
@@ -184,7 +219,6 @@ module.exports = function (node) {
184
219
  done();
185
220
  };
186
221
  const getOrCreate = function (accessory, serviceInformation, parentService) {
187
- var _a;
188
222
  const newService = new Service[serviceInformation.serviceName](serviceInformation.name, serviceInformation.UUID);
189
223
  log.debug(`Looking for service with UUID ${serviceInformation.UUID} ...`);
190
224
  let service = accessory.services.find((service) => {
@@ -203,21 +237,6 @@ module.exports = function (node) {
203
237
  }
204
238
  else {
205
239
  service = accessory.addService(newService);
206
- if (serviceInformation.serviceName === 'Lightbulb' &&
207
- serviceInformation.config.adaptiveLightingOptionsEnable) {
208
- try {
209
- const adaptiveLightingController = new hap_nodejs_1.AdaptiveLightingController(service, {
210
- controllerMode: (_a = serviceInformation.config
211
- .adaptiveLightingOptionsMode) !== null && _a !== void 0 ? _a : 1,
212
- customTemperatureAdjustment: serviceInformation.config
213
- .adaptiveLightingOptionsCustomTemperatureAdjustment,
214
- });
215
- accessory.configureController(adaptiveLightingController);
216
- }
217
- catch (error) {
218
- log.error(`Failed to configure adaptive lightning due to ${error}`);
219
- }
220
- }
221
240
  }
222
241
  }
223
242
  else {
@@ -290,6 +309,59 @@ module.exports = function (node) {
290
309
  log.error('Invalid message (required {"payload":{"nrchkb":{"setup":{}}}})');
291
310
  }
292
311
  };
312
+ const configureAdaptiveLightning = () => {
313
+ if (node.service.UUID === Service.Lightbulb.UUID &&
314
+ node.config.adaptiveLightingOptionsEnable) {
315
+ try {
316
+ node.service.getCharacteristic(Characteristic.Brightness);
317
+ node.service.getCharacteristic(Characteristic.ColorTemperature);
318
+ const options = {
319
+ controllerMode: node.config.adaptiveLightingOptionsMode
320
+ ? +node.config.adaptiveLightingOptionsMode
321
+ : 1,
322
+ customTemperatureAdjustment: node.config
323
+ .adaptiveLightingOptionsCustomTemperatureAdjustment
324
+ ? +node.config
325
+ .adaptiveLightingOptionsCustomTemperatureAdjustment
326
+ : undefined,
327
+ };
328
+ log.trace(`Configuring Adaptive Lighting with options: ${options}`);
329
+ const adaptiveLightingController = new hap_nodejs_1.AdaptiveLightingController(node.service, options);
330
+ adaptiveLightingController.on('update', () => {
331
+ const activeAdaptiveLightingTransition = {
332
+ transitionStartMillis: adaptiveLightingController.getAdaptiveLightingStartTimeOfTransition(),
333
+ timeMillisOffset: adaptiveLightingController.getAdaptiveLightingTimeOffset(),
334
+ transitionCurve: adaptiveLightingController.getAdaptiveLightingTransitionCurve(),
335
+ brightnessAdjustmentRange: adaptiveLightingController.getAdaptiveLightingBrightnessMultiplierRange(),
336
+ updateInterval: adaptiveLightingController.getAdaptiveLightingUpdateInterval(),
337
+ notifyIntervalThreshold: adaptiveLightingController.getAdaptiveLightingNotifyIntervalThreshold(),
338
+ };
339
+ node.send({
340
+ payload: {
341
+ AdaptiveLightingController: {
342
+ event: 'update',
343
+ data: activeAdaptiveLightingTransition,
344
+ },
345
+ },
346
+ });
347
+ });
348
+ adaptiveLightingController.on('disable', () => {
349
+ node.send({
350
+ payload: {
351
+ AdaptiveLightingController: {
352
+ event: 'disable',
353
+ },
354
+ },
355
+ });
356
+ });
357
+ node.accessory.configureController(adaptiveLightingController);
358
+ node.adaptiveLightingController = adaptiveLightingController;
359
+ }
360
+ catch (error) {
361
+ log.error(`Failed to configure Adaptive Lightning due to ${error}`);
362
+ }
363
+ }
364
+ };
293
365
  return {
294
366
  getOrCreate,
295
367
  onCharacteristicGet,
@@ -299,5 +371,6 @@ module.exports = function (node) {
299
371
  onClose,
300
372
  waitForParent,
301
373
  handleWaitForSetup,
374
+ configureAdaptiveLightning,
302
375
  };
303
376
  };