node-red-contrib-homekit-bridged 1.4.3 → 1.5.0-dev.3

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/CHANGELOG.md CHANGED
@@ -11,6 +11,18 @@ All notable changes to this project will be documented in this file.
11
11
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres
12
12
  to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
13
13
 
14
+ ## [1.5.0-dev.2]
15
+
16
+ ### Fixed
17
+
18
+ - Accessory could not be recovered from NO_RESPONSE using single Characteristic
19
+ - Make unsupported Characteristic error more
20
+ descriptive [#456](https://github.com/NRCHKB/node-red-contrib-homekit-bridged/issues/456)
21
+
22
+ ### Changed
23
+
24
+ - Updated hap-nodejs to [0.9.7](https://github.com/homebridge/HAP-NodeJS/releases/tag/v0.9.7) (bug fixes)
25
+
14
26
  ## [1.4.3]
15
27
 
16
28
  ### Added
@@ -19,7 +31,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
19
31
 
20
32
  ### Changed
21
33
 
22
- - Updated hap-nodejs to [0.9.6](https://github.com/homebridge/HAP-NodeJS/releases/tag/v0.9.6) (bug fixes and security fixes)
34
+ - Updated hap-nodejs to [0.9.6](https://github.com/homebridge/HAP-NodeJS/releases/tag/v0.9.6) (bug fixes and security
35
+ fixes)
23
36
 
24
37
  ## [1.4.2]
25
38
 
@@ -56,7 +69,8 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
56
69
 
57
70
  ### Changed
58
71
 
59
- - Updated hap-nodejs to [0.9.5](https://github.com/homebridge/HAP-NodeJS/releases/tag/v0.9.5) (added new iOS 15 Services and Characteristics)
72
+ - Updated hap-nodejs to [0.9.5](https://github.com/homebridge/HAP-NodeJS/releases/tag/v0.9.5) (added new iOS 15 Services
73
+ and Characteristics)
60
74
  - Updated dependencies to latest versions
61
75
  - Changed `BatteryService` to `Battery` in demo examples as `BatteryService` is deprecated #381 - thanks @crxporter
62
76
  - Readme rework - thanks @crxporter
@@ -74,6 +74,7 @@ module.exports = (RED) => {
74
74
  log.debug('Starting Parent Service');
75
75
  configure.call(self);
76
76
  self.configured = true;
77
+ self.reachable = true;
77
78
  }
78
79
  else {
79
80
  const serviceType = config.serviceName === 'CameraControl' ? 'Camera' : 'Linked';
@@ -115,14 +116,15 @@ module.exports = (RED) => {
115
116
  log.error('Parent Node not assigned', false);
116
117
  throw new NRCHKBError_1.default('Parent Node not assigned');
117
118
  }
118
- self.parentService = parentNode.service;
119
+ self.parentNode = parentNode;
120
+ self.parentService = self.parentNode.service;
119
121
  if (!self.parentService) {
120
122
  log.error('Parent Service not assigned', false);
121
123
  throw new NRCHKBError_1.default('Parent Service not assigned');
122
124
  }
123
- self.hostNode = parentNode.hostNode;
124
- parentNode.childNodes.push(self);
125
- self.accessory = parentNode.accessory;
125
+ self.hostNode = self.parentNode.hostNode;
126
+ self.parentNode.childNodes.push(self);
127
+ self.accessory = self.parentNode.accessory;
126
128
  }
127
129
  self.name = self.config.name;
128
130
  if (self.hasOwnProperty('_flow') &&
@@ -74,6 +74,7 @@ module.exports = (RED) => {
74
74
  log.debug('Starting Parent Service');
75
75
  configure.call(self);
76
76
  self.configured = true;
77
+ self.reachable = true;
77
78
  }
78
79
  else {
79
80
  const serviceType = config.serviceName === 'CameraControl' ? 'Camera' : 'Linked';
@@ -115,14 +116,15 @@ module.exports = (RED) => {
115
116
  log.error('Parent Node not assigned', false);
116
117
  throw new NRCHKBError_1.default('Parent Node not assigned');
117
118
  }
118
- self.parentService = parentNode.service;
119
+ self.parentNode = parentNode;
120
+ self.parentService = self.parentNode.service;
119
121
  if (!self.parentService) {
120
122
  log.error('Parent Service not assigned', false);
121
123
  throw new NRCHKBError_1.default('Parent Service not assigned');
122
124
  }
123
- self.hostNode = parentNode.hostNode;
124
- parentNode.childNodes.push(self);
125
- self.accessory = parentNode.accessory;
125
+ self.hostNode = self.parentNode.hostNode;
126
+ self.parentNode.childNodes.push(self);
127
+ self.accessory = self.parentNode.accessory;
126
128
  }
127
129
  self.name = self.config.name;
128
130
  if (self.hasOwnProperty('_flow') &&
package/build/lib/api.js CHANGED
@@ -141,6 +141,14 @@ module.exports = function (RED) {
141
141
  const characteristicNameToKey = (name) => {
142
142
  return name.replace(' ', '');
143
143
  };
144
+ const toNumber = (value, optional = undefined) => {
145
+ const num = Number(value);
146
+ if (isNaN(num)) {
147
+ return optional;
148
+ }
149
+ else
150
+ return num;
151
+ };
144
152
  const refreshCustomCharacteristics = (customCharacteristics) => {
145
153
  log.debug('Refreshing Custom Characteristics');
146
154
  const customCharacteristicKeys = [];
@@ -165,6 +173,15 @@ module.exports = function (RED) {
165
173
  if (((_e = validatedProps.adminOnlyAccess) === null || _e === void 0 ? void 0 : _e.length) === 0) {
166
174
  validatedProps.adminOnlyAccess = undefined;
167
175
  }
176
+ if (validatedProps.minValue) {
177
+ validatedProps.minValue = toNumber(validatedProps.minValue);
178
+ }
179
+ if (validatedProps.maxValue) {
180
+ validatedProps.maxValue = toNumber(validatedProps.maxValue);
181
+ }
182
+ if (validatedProps.minStep) {
183
+ validatedProps.minStep = toNumber(validatedProps.minStep);
184
+ }
168
185
  class CustomCharacteristic extends hap_nodejs_1.Characteristic {
169
186
  constructor() {
170
187
  var _a;
@@ -18,6 +18,7 @@ declare type HAPService2NodeType = NodeType & {
18
18
  childNodes: (HAPService2NodeType | HAPServiceNodeType)[];
19
19
  service: Service;
20
20
  parentService: Service;
21
+ parentNode?: HAPService2NodeType | HAPServiceNodeType;
21
22
  accessory: Accessory;
22
23
  characteristicProperties: {
23
24
  [key: string]: CharacteristicProps;
@@ -29,5 +30,6 @@ declare type HAPService2NodeType = NodeType & {
29
30
  onCharacteristicSet: (this: Characteristic, newValue: CharacteristicValue, callback: CharacteristicSetCallback, context: any, connection?: HAPConnection) => void;
30
31
  onCharacteristicChange: (this: Characteristic, change: CharacteristicChange) => void;
31
32
  uniqueIdentifier: string;
33
+ reachable?: boolean;
32
34
  } & StatusUtilType;
33
35
  export default HAPService2NodeType;
@@ -18,6 +18,7 @@ declare type HAPServiceNodeType = NodeType & {
18
18
  childNodes: (HAPService2NodeType | HAPServiceNodeType)[];
19
19
  service: Service;
20
20
  parentService: Service;
21
+ parentNode?: HAPService2NodeType | HAPServiceNodeType;
21
22
  accessory: Accessory;
22
23
  characteristicProperties: {
23
24
  [key: string]: CharacteristicProps;
@@ -29,5 +30,6 @@ declare type HAPServiceNodeType = NodeType & {
29
30
  onCharacteristicSet: (this: Characteristic, newValue: CharacteristicValue, callback: CharacteristicSetCallback, context: any, connection?: HAPConnection) => void;
30
31
  onCharacteristicChange: (this: Characteristic, change: CharacteristicChange) => void;
31
32
  uniqueIdentifier: string;
33
+ reachable?: boolean;
32
34
  } & StatusUtilType;
33
35
  export default HAPServiceNodeType;
@@ -42,7 +42,7 @@ module.exports = function (node) {
42
42
  characteristic.props.minValue = -100;
43
43
  }
44
44
  });
45
- return supported;
45
+ return [...new Set(supported)];
46
46
  };
47
47
  return {
48
48
  load: load,
@@ -42,7 +42,7 @@ module.exports = function (node) {
42
42
  characteristic.props.minValue = -100;
43
43
  }
44
44
  });
45
- return supported;
45
+ return [...new Set(supported)];
46
46
  };
47
47
  return {
48
48
  load: load,
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const HostType_1 = __importDefault(require("../types/HostType"));
6
+ const hap_nodejs_1 = require("hap-nodejs");
7
7
  const logger_1 = require("@nrchkb/logger");
8
8
  const NRCHKBError_1 = __importDefault(require("../NRCHKBError"));
9
9
  module.exports = function (node) {
@@ -31,12 +31,13 @@ module.exports = function (node) {
31
31
  return hap;
32
32
  };
33
33
  const onCharacteristicGet = function (callback, context, connection) {
34
- log.debug(`onCharacteristicGet with status: ${this.statusCode}, value: ${this.value}, reachability is ${node.accessory.reachable} with context ${JSON.stringify(context)} on connection ${connection === null || connection === void 0 ? void 0 : connection.sessionID}`);
34
+ 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}`);
35
36
  if (callback) {
36
37
  try {
37
- callback(node.accessory.reachable
38
- ? this.statusCode
39
- : new Error(NO_RESPONSE_MSG), this.value);
38
+ callback(((_b = node.parentNode) !== null && _b !== void 0 ? _b : node).reachable
39
+ ? null
40
+ : new hap_nodejs_1.HapStatusError(-70402), this.value);
40
41
  }
41
42
  catch (_) { }
42
43
  }
@@ -76,13 +77,14 @@ module.exports = function (node) {
76
77
  }
77
78
  };
78
79
  const onCharacteristicSet = (allCharacteristics) => function (newValue, callback, context, connection) {
79
- log.debug(`onCharacteristicSet with status: ${this.statusCode}, value: ${this.value}, reachability is ${node.accessory.reachable}
80
+ var _a, _b;
81
+ log.debug(`onCharacteristicSet with status: ${this.statusCode}, value: ${this.value}, reachability is ${((_a = node.parentNode) !== null && _a !== void 0 ? _a : node).reachable}
80
82
  with context ${JSON.stringify(context)} on connection ${connection === null || connection === void 0 ? void 0 : connection.sessionID}`);
81
83
  try {
82
84
  if (callback) {
83
- callback(node.accessory.reachable
85
+ callback(((_b = node.parentNode) !== null && _b !== void 0 ? _b : node).reachable
84
86
  ? null
85
- : new Error(NO_RESPONSE_MSG));
87
+ : new hap_nodejs_1.HapStatusError(-70402));
86
88
  }
87
89
  }
88
90
  catch (_) { }
@@ -92,8 +94,9 @@ module.exports = function (node) {
92
94
  }, connection);
93
95
  };
94
96
  const onCharacteristicChange = (allCharacteristics) => function (change) {
97
+ var _a;
95
98
  const { oldValue, newValue, context, originator, reason } = change;
96
- log.debug(`onCharacteristicChange with reason: ${reason}, oldValue: ${oldValue}, newValue: ${newValue}, reachability is ${node.accessory.reachable}
99
+ log.debug(`onCharacteristicChange with reason: ${reason}, oldValue: ${oldValue}, newValue: ${newValue}, reachability is ${((_a = node.parentNode) !== null && _a !== void 0 ? _a : node).reachable}
97
100
  with context ${JSON.stringify(context)} on connection ${originator === null || originator === void 0 ? void 0 : originator.sessionID}`);
98
101
  if (oldValue != newValue) {
99
102
  onValueChange.call(this, allCharacteristics, 0, {
@@ -127,22 +130,20 @@ module.exports = function (node) {
127
130
  }
128
131
  node.topic_in = msg.topic ? msg.topic : '';
129
132
  Object.keys(msg.payload).map((key) => {
133
+ var _a, _b;
130
134
  if (node.supported.indexOf(key) < 0) {
131
- log.error(`Instead of ${key} try one of these characteristics: ${node.supported.join(', ')}`);
135
+ log.error(`Instead of '${key}' try one of these characteristics: '${node.supported.join("', '")}'`);
132
136
  }
133
137
  else {
134
- if ((node.config.isParent &&
135
- node.config.hostType == HostType_1.default.BRIDGE) ||
136
- (!node.config.isParent &&
137
- node.hostNode.hostType == HostType_1.default.BRIDGE)) {
138
- node.accessory.updateReachability(msg.payload[key] !== NO_RESPONSE_MSG);
139
- }
138
+ const value = (_a = msg.payload) === null || _a === void 0 ? void 0 : _a[key];
139
+ const parentNode = (_b = node.parentNode) !== null && _b !== void 0 ? _b : node;
140
+ parentNode.reachable = value !== NO_RESPONSE_MSG;
140
141
  const characteristic = node.service.getCharacteristic(Characteristic[key]);
141
142
  if (context !== null) {
142
- characteristic.setValue(msg.payload[key], undefined, context);
143
+ characteristic.setValue(value, context);
143
144
  }
144
145
  else {
145
- characteristic.setValue(msg.payload[key]);
146
+ characteristic.setValue(value);
146
147
  }
147
148
  }
148
149
  });
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- const HostType_1 = __importDefault(require("../types/HostType"));
6
+ const hap_nodejs_1 = require("hap-nodejs");
7
7
  const logger_1 = require("@nrchkb/logger");
8
8
  const Storage_1 = require("../Storage");
9
9
  const NRCHKBError_1 = __importDefault(require("../NRCHKBError"));
@@ -58,12 +58,13 @@ module.exports = function (node) {
58
58
  const characteristic = this;
59
59
  const oldValue = characteristic.value;
60
60
  const delayedCallback = (value) => {
61
+ var _a;
61
62
  const newValue = value !== null && value !== void 0 ? value : characteristic.value;
62
63
  if (callback) {
63
64
  try {
64
- callback(node.accessory.reachable
65
- ? characteristic.statusCode
66
- : new Error(NO_RESPONSE_MSG), newValue);
65
+ callback(((_a = node.parentNode) !== null && _a !== void 0 ? _a : node).reachable
66
+ ? null
67
+ : new hap_nodejs_1.HapStatusError(-70402), newValue);
67
68
  }
68
69
  catch (_) { }
69
70
  }
@@ -88,11 +89,12 @@ module.exports = function (node) {
88
89
  }
89
90
  };
90
91
  const onCharacteristicSet = (allCharacteristics) => function (newValue, callback, _context, connection) {
92
+ var _a;
91
93
  try {
92
94
  if (callback) {
93
- callback(node.accessory.reachable
95
+ callback(((_a = node.parentNode) !== null && _a !== void 0 ? _a : node).reachable
94
96
  ? null
95
- : new Error(NO_RESPONSE_MSG));
97
+ : new hap_nodejs_1.HapStatusError(-70402));
96
98
  }
97
99
  }
98
100
  catch (_) { }
@@ -135,7 +137,7 @@ module.exports = function (node) {
135
137
  }
136
138
  node.topic_in = (_a = msg.topic) !== null && _a !== void 0 ? _a : '';
137
139
  Object.keys(msg.payload).map((key) => {
138
- var _a, _b;
140
+ var _a, _b, _c;
139
141
  if (node.supported.indexOf(key) < 0) {
140
142
  if (node.config.useEventCallback &&
141
143
  Storage_1.Storage.uuid4Validate(key)) {
@@ -151,20 +153,16 @@ module.exports = function (node) {
151
153
  }
152
154
  }
153
155
  else {
154
- log.error(`Instead of ${key} try one of these characteristics: ${node.supported.join(', ')}`);
156
+ log.error(`Instead of '${key}' try one of these characteristics: '${node.supported.join("', '")}'`);
155
157
  }
156
158
  }
157
159
  else {
158
160
  const value = (_b = msg.payload) === null || _b === void 0 ? void 0 : _b[key];
159
- if ((node.config.isParent &&
160
- node.config.hostType == HostType_1.default.BRIDGE) ||
161
- (!node.config.isParent &&
162
- node.hostNode.hostType == HostType_1.default.BRIDGE)) {
163
- node.accessory.updateReachability(value !== NO_RESPONSE_MSG);
164
- }
161
+ const parentNode = (_c = node.parentNode) !== null && _c !== void 0 ? _c : node;
162
+ parentNode.reachable = value !== NO_RESPONSE_MSG;
165
163
  const characteristic = node.service.getCharacteristic(Characteristic[key]);
166
164
  if (context !== null) {
167
- characteristic.setValue(value, undefined, context);
165
+ characteristic.setValue(value, context);
168
166
  }
169
167
  else {
170
168
  characteristic.setValue(value);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "node-red-contrib-homekit-bridged",
3
- "version": "1.4.3",
3
+ "version": "1.5.0-dev.3",
4
4
  "description": "Node-RED nodes to simulate Apple HomeKit devices.",
5
5
  "main": "build/nodes/nrchkb.js",
6
6
  "scripts": {
@@ -18,11 +18,11 @@
18
18
  },
19
19
  "keywords": [
20
20
  "homekit",
21
- "hap-nodejs",
22
21
  "node-red",
22
+ "NRCHKB",
23
23
  "iot",
24
24
  "home",
25
- "NRCHKB",
25
+ "hap-nodejs",
26
26
  "homebridge"
27
27
  ],
28
28
  "node-red": {
@@ -33,11 +33,12 @@
33
33
  "service": "build/nodes/service.js",
34
34
  "service2": "build/nodes/service2.js",
35
35
  "status": "build/nodes/status.js"
36
- }
36
+ },
37
+ "version": ">=1.3.7"
37
38
  },
38
39
  "author": {
39
40
  "name": "Tadeusz Wyrzykowski",
40
- "email": "tadeusz@hey.com",
41
+ "email": "shaquu@icloud.com",
41
42
  "url": "https://github.com/Shaquu"
42
43
  },
43
44
  "license": "Apache-2.0",
@@ -47,34 +48,34 @@
47
48
  "homepage": "https://github.com/NRCHKB/node-red-contrib-homekit-bridged#readme",
48
49
  "dependencies": {
49
50
  "@nrchkb/logger": "^1.3.3",
50
- "hap-nodejs": "^0.9.6",
51
+ "hap-nodejs": "~0.10.0",
51
52
  "node-persist": "^3.1.0",
52
53
  "semver": "^7.3.5",
53
54
  "uuid": "^8.3.2"
54
55
  },
55
56
  "devDependencies": {
56
- "@homebridge/ciao": "^1.1.2",
57
+ "@homebridge/ciao": "^1.1.3",
57
58
  "@node-red/registry": "^1.3.7",
58
- "@types/mocha": "^9.0.0",
59
- "@types/node": "^10.17.50",
59
+ "@types/mocha": "^9.1.0",
60
+ "@types/node": "^10.17.60",
60
61
  "@types/node-persist": "^3.1.2",
61
- "@types/node-red": "^1.1.1",
62
- "@types/semver": "^7.3.8",
63
- "@types/uuid": "^8.3.1",
64
- "@typescript-eslint/eslint-plugin": "^4.33.0",
65
- "@typescript-eslint/parser": "^4.33.0",
62
+ "@types/node-red": "^1.2.0",
63
+ "@types/semver": "^7.3.9",
64
+ "@types/uuid": "^8.3.4",
65
+ "@typescript-eslint/eslint-plugin": "^5.11.0",
66
+ "@typescript-eslint/parser": "^5.11.0",
66
67
  "babel-eslint": "^10.1.0",
67
- "eslint": "^7.32.0",
68
+ "eslint": "^8.8.0",
68
69
  "eslint-config-prettier": "^8.3.0",
69
70
  "eslint-plugin-prettier": "^4.0.0",
70
- "husky": "^7.0.2",
71
- "mocha": "^9.1.2",
72
- "node-red": "^1.3.7",
71
+ "husky": "^7.0.4",
72
+ "mocha": "^9.2.0",
73
+ "node-red": "1.3.7",
73
74
  "node-red-node-test-helper": "^0.2.7",
74
75
  "pinst": "^2.1.6",
75
- "prettier": "^2.4.1",
76
- "ts-node": "^10.2.1",
77
- "typescript": "^4.4.3"
76
+ "prettier": "^2.5.1",
77
+ "ts-node": "^10.5.0",
78
+ "typescript": "^4.5.5"
78
79
  },
79
80
  "engines": {
80
81
  "node": ">=10.22.1"