node-red-contrib-huemagic 4.0.2 → 4.0.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/README.md +10 -10
- package/examples/Hue Bridge.json +1 -1
- package/huemagic/hue-bridge-config.html +4 -4
- package/huemagic/hue-bridge-config.js +130 -127
- package/huemagic/hue-bridge.js +5 -5
- package/huemagic/hue-brightness.html +7 -7
- package/huemagic/hue-brightness.js +11 -5
- package/huemagic/hue-buttons.html +7 -7
- package/huemagic/hue-buttons.js +11 -5
- package/huemagic/hue-group.html +11 -11
- package/huemagic/hue-group.js +3 -3
- package/huemagic/hue-light.html +7 -7
- package/huemagic/hue-light.js +3 -3
- package/huemagic/hue-motion.html +7 -7
- package/huemagic/hue-motion.js +11 -5
- package/huemagic/hue-rules.html +5 -5
- package/huemagic/hue-rules.js +10 -4
- package/huemagic/hue-scene.html +5 -5
- package/huemagic/hue-scene.js +1 -1
- package/huemagic/hue-temperature.html +7 -7
- package/huemagic/hue-temperature.js +11 -5
- package/huemagic/locales/de/hue-bridge.json +1 -1
- package/huemagic/locales/en-US/hue-bridge.json +1 -1
- package/huemagic/locales/en-US/hue-buttons.html +1 -1
- package/huemagic/locales/en-US/hue-magic.html +2 -2
- package/huemagic/locales/en-US/hue-motion.html +1 -1
- package/huemagic/locales/en-US/hue-temperature.html +1 -1
- package/huemagic/utils/api.js +45 -45
- package/huemagic/utils/messages.js +124 -124
- package/package.json +1 -1
package/huemagic/utils/api.js
CHANGED
|
@@ -55,7 +55,7 @@ function API()
|
|
|
55
55
|
|
|
56
56
|
//
|
|
57
57
|
// MAKE A REQUEST
|
|
58
|
-
this.request = function({ method = 'GET',
|
|
58
|
+
this.request = function({ method = 'GET', resource = null, data = null, version = 2 })
|
|
59
59
|
{
|
|
60
60
|
const scope = this;
|
|
61
61
|
return new Promise(function(resolve, reject)
|
|
@@ -71,17 +71,17 @@ function API()
|
|
|
71
71
|
"httpsAgent": new https.Agent({ rejectUnauthorized: false }), // Node is somehow not able to parse the official Philips Hue PEM
|
|
72
72
|
};
|
|
73
73
|
|
|
74
|
-
// HAS
|
|
75
|
-
if(
|
|
74
|
+
// HAS RESOURCE? -> APPEND
|
|
75
|
+
if(resource !== null)
|
|
76
76
|
{
|
|
77
77
|
if(version === 2)
|
|
78
78
|
{
|
|
79
|
-
|
|
80
|
-
request['url'] += "/clip/v2/resource" +
|
|
79
|
+
resource = (resource !== "all") ? "/"+resource : "";
|
|
80
|
+
request['url'] += "/clip/v2/resource" + resource;
|
|
81
81
|
}
|
|
82
82
|
else if(version === 1)
|
|
83
83
|
{
|
|
84
|
-
request['url'] += "/api/" + scope.accessKey +
|
|
84
|
+
request['url'] += "/api/" + scope.accessKey + resource;
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
|
|
@@ -182,41 +182,41 @@ function API()
|
|
|
182
182
|
}
|
|
183
183
|
|
|
184
184
|
//
|
|
185
|
-
// GET FULL/ROOT
|
|
186
|
-
this.
|
|
185
|
+
// GET FULL/ROOT RESOURCE
|
|
186
|
+
this.fullResource = function(resource, allResources = {})
|
|
187
187
|
{
|
|
188
188
|
const scope = this;
|
|
189
|
-
var
|
|
189
|
+
var fullResource = Object.assign({}, resource);
|
|
190
190
|
|
|
191
|
-
if(
|
|
191
|
+
if(resource["owner"])
|
|
192
192
|
{
|
|
193
|
-
|
|
193
|
+
fullResource = scope.fullResource(allResources[fullResource["owner"]["rid"]], allResources);
|
|
194
194
|
}
|
|
195
|
-
else if(
|
|
195
|
+
else if(resource["type"] === "device" || resource["type"] === "room" || resource["type"] === "zone" || resource["type"] === "bridge_home")
|
|
196
196
|
{
|
|
197
197
|
// RESOLVE SERVICES
|
|
198
198
|
var allServices = {};
|
|
199
199
|
|
|
200
|
-
for (var i =
|
|
200
|
+
for (var i = resource["services"].length - 1; i >= 0; i--)
|
|
201
201
|
{
|
|
202
|
-
const targetService =
|
|
202
|
+
const targetService = resource["services"][i];
|
|
203
203
|
const targetType = targetService["rtype"];
|
|
204
204
|
const targetID = targetService["rid"];
|
|
205
205
|
|
|
206
206
|
if(!allServices[targetType]) { allServices[targetType] = {}; }
|
|
207
|
-
allServices[targetType][targetID] = Object.assign({},
|
|
207
|
+
allServices[targetType][targetID] = Object.assign({}, allResources[targetID]);
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
// REPLACE SERVICES
|
|
211
|
-
|
|
211
|
+
fullResource["services"] = allServices;
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
return
|
|
214
|
+
return fullResource;
|
|
215
215
|
}
|
|
216
216
|
|
|
217
217
|
//
|
|
218
|
-
// PROCESS
|
|
219
|
-
this.
|
|
218
|
+
// PROCESS RESOURCES
|
|
219
|
+
this.processResources = function(resources)
|
|
220
220
|
{
|
|
221
221
|
const scope = this;
|
|
222
222
|
|
|
@@ -226,62 +226,62 @@ function API()
|
|
|
226
226
|
// ACTION!
|
|
227
227
|
return new Promise(function(resolve, reject)
|
|
228
228
|
{
|
|
229
|
-
let
|
|
230
|
-
let
|
|
229
|
+
let resourceList = {};
|
|
230
|
+
let processedResources = {
|
|
231
231
|
_groupsOf: {}
|
|
232
232
|
};
|
|
233
233
|
|
|
234
|
-
// CREATE ID BASED OBJECT OF ALL
|
|
235
|
-
|
|
234
|
+
// CREATE ID BASED OBJECT OF ALL RESOURCES
|
|
235
|
+
resources.forEach(function(resource, index)
|
|
236
236
|
{
|
|
237
237
|
// IS BUTTON? -> REMOVE PREVIOUS STATE
|
|
238
|
-
if(
|
|
238
|
+
if(resource.type === "button")
|
|
239
239
|
{
|
|
240
|
-
delete
|
|
240
|
+
delete resource["button"];
|
|
241
241
|
}
|
|
242
242
|
|
|
243
|
-
|
|
243
|
+
resourceList[resource.id] = resource;
|
|
244
244
|
});
|
|
245
245
|
|
|
246
|
-
// GET FULL
|
|
247
|
-
|
|
246
|
+
// GET FULL RESOURCES OF EACH OBJECT
|
|
247
|
+
resources.forEach(function(resource, index)
|
|
248
248
|
{
|
|
249
|
-
// GET FULL
|
|
250
|
-
let
|
|
249
|
+
// GET FULL RESOURCE
|
|
250
|
+
let fullResource = scope.fullResource(resource, resourceList);
|
|
251
251
|
|
|
252
252
|
// ADD CURRENT DATE/TIME
|
|
253
|
-
|
|
253
|
+
fullResource["updated"] = currentDateTime;
|
|
254
254
|
|
|
255
|
-
// ALL ALL TYPES BEHIND
|
|
256
|
-
|
|
255
|
+
// ALL ALL TYPES BEHIND RESOURCE
|
|
256
|
+
fullResource["types"] = [ fullResource["type"] ];
|
|
257
257
|
|
|
258
|
-
//
|
|
259
|
-
if(
|
|
258
|
+
// RESOURCE HAS SERVICES?
|
|
259
|
+
if(fullResource["services"])
|
|
260
260
|
{
|
|
261
|
-
let additionalServiceTypes = Object.keys(
|
|
261
|
+
let additionalServiceTypes = Object.keys(fullResource["services"]);
|
|
262
262
|
|
|
263
263
|
// SET ADDITIONAL TYPES BEHIND RECCOURCE
|
|
264
|
-
|
|
264
|
+
fullResource["types"] = fullResource["types"].concat(additionalServiceTypes);
|
|
265
265
|
}
|
|
266
266
|
|
|
267
267
|
// RESOURCE HAS GROUPED SERVICES?
|
|
268
|
-
if(
|
|
268
|
+
if(fullResource["grouped_services"])
|
|
269
269
|
{
|
|
270
|
-
for (var g =
|
|
270
|
+
for (var g = fullResource["grouped_services"].length - 1; g >= 0; g--)
|
|
271
271
|
{
|
|
272
|
-
const groupedService =
|
|
272
|
+
const groupedService = fullResource["grouped_services"][g];
|
|
273
273
|
const groupedServiceID = groupedService["rid"];
|
|
274
274
|
|
|
275
|
-
if(!
|
|
276
|
-
|
|
275
|
+
if(!processedResources["_groupsOf"][groupedServiceID]) { processedResources["_groupsOf"][groupedServiceID] = []; }
|
|
276
|
+
processedResources["_groupsOf"][groupedServiceID].push(fullResource.id);
|
|
277
277
|
}
|
|
278
278
|
}
|
|
279
279
|
|
|
280
|
-
// GIVE FULL
|
|
281
|
-
|
|
280
|
+
// GIVE FULL RESOURCE BACK TO COLLECTION
|
|
281
|
+
processedResources[fullResource.id] = fullResource;
|
|
282
282
|
});
|
|
283
283
|
|
|
284
|
-
resolve(
|
|
284
|
+
resolve(processedResources);
|
|
285
285
|
});
|
|
286
286
|
}
|
|
287
287
|
}
|
|
@@ -5,44 +5,44 @@ const colorUtils = require("./color");
|
|
|
5
5
|
// HUE BRIDGE
|
|
6
6
|
class HueBridgeMessage
|
|
7
7
|
{
|
|
8
|
-
constructor(
|
|
8
|
+
constructor(resource, options = {})
|
|
9
9
|
{
|
|
10
10
|
this.message = {};
|
|
11
11
|
this.message.payload = {};
|
|
12
|
-
this.message.payload.id =
|
|
13
|
-
this.message.payload.name =
|
|
14
|
-
this.message.payload.factoryNew =
|
|
15
|
-
this.message.payload.replacesBridgeId =
|
|
16
|
-
this.message.payload.dataStoreVersion =
|
|
17
|
-
this.message.payload.starterKitId =
|
|
18
|
-
this.message.payload.softwareVersion =
|
|
19
|
-
this.message.payload.apiVersion =
|
|
20
|
-
this.message.payload.zigbeeChannel =
|
|
21
|
-
this.message.payload.macAddress =
|
|
22
|
-
this.message.payload.ipAddress =
|
|
23
|
-
this.message.payload.dhcpEnabled =
|
|
24
|
-
this.message.payload.netmask =
|
|
25
|
-
this.message.payload.gateway =
|
|
26
|
-
this.message.payload.proxyAddress =
|
|
27
|
-
this.message.payload.proxyPort =
|
|
28
|
-
this.message.payload.utcTime =
|
|
29
|
-
this.message.payload.timeZone =
|
|
30
|
-
this.message.payload.localTime =
|
|
31
|
-
this.message.payload.portalServicesEnabled =
|
|
32
|
-
this.message.payload.portalConnected =
|
|
33
|
-
this.message.payload.linkButtonEnabled =
|
|
34
|
-
this.message.payload.touchlinkEnabled = (
|
|
12
|
+
this.message.payload.id = resource.bridgeid;
|
|
13
|
+
this.message.payload.name = resource.name;
|
|
14
|
+
this.message.payload.factoryNew = resource.factorynew;
|
|
15
|
+
this.message.payload.replacesBridgeId = resource.replacesbridgeid ? resource.replacesbridgeid : false;
|
|
16
|
+
this.message.payload.dataStoreVersion = resource.datastoreversion;
|
|
17
|
+
this.message.payload.starterKitId = resource.starterkitid.length > 0 ? resource.starterkitid : false;
|
|
18
|
+
this.message.payload.softwareVersion = resource.swversion;
|
|
19
|
+
this.message.payload.apiVersion = resource.apiversion;
|
|
20
|
+
this.message.payload.zigbeeChannel = resource.zigbeechannel;
|
|
21
|
+
this.message.payload.macAddress = resource.mac;
|
|
22
|
+
this.message.payload.ipAddress = resource.ipaddress;
|
|
23
|
+
this.message.payload.dhcpEnabled = resource.dhcp;
|
|
24
|
+
this.message.payload.netmask = resource.netmask;
|
|
25
|
+
this.message.payload.gateway = resource.gateway;
|
|
26
|
+
this.message.payload.proxyAddress = resource.proxyaddress == "none" ? false : resource.proxyaddress;
|
|
27
|
+
this.message.payload.proxyPort = resource.proxyport;
|
|
28
|
+
this.message.payload.utcTime = resource.UTC;
|
|
29
|
+
this.message.payload.timeZone = resource.timezone;
|
|
30
|
+
this.message.payload.localTime = resource.localtime;
|
|
31
|
+
this.message.payload.portalServicesEnabled = resource.portalservices;
|
|
32
|
+
this.message.payload.portalConnected = resource.portalconnection;
|
|
33
|
+
this.message.payload.linkButtonEnabled = resource.linkbutton;
|
|
34
|
+
this.message.payload.touchlinkEnabled = (resource["touchlink"] && resource["touchlink"] == true) ? true : false;
|
|
35
35
|
this.message.payload.autoUpdatesEnabled = options["autoupdate"] ? options["autoupdate"] : false;
|
|
36
36
|
this.message.payload.users = []; // NEW!
|
|
37
|
-
this.message.payload.updated =
|
|
37
|
+
this.message.payload.updated = resource.updated; // NEW!
|
|
38
38
|
|
|
39
39
|
this.message.payload.model = {};
|
|
40
|
-
this.message.payload.model.id =
|
|
40
|
+
this.message.payload.model.id = resource.modelid;
|
|
41
41
|
this.message.payload.model.manufacturer = "Philips";
|
|
42
42
|
this.message.payload.model.name = "Hue v2";
|
|
43
43
|
|
|
44
44
|
// GET USERS
|
|
45
|
-
for (const [userID, user] of Object.entries(
|
|
45
|
+
for (const [userID, user] of Object.entries(resource["whitelist"]))
|
|
46
46
|
{
|
|
47
47
|
this.message.payload.users.push({
|
|
48
48
|
user: userID,
|
|
@@ -64,10 +64,10 @@ class HueBridgeMessage
|
|
|
64
64
|
// HUE BRIGHTNESS
|
|
65
65
|
class HueBrightnessMessage
|
|
66
66
|
{
|
|
67
|
-
constructor(
|
|
67
|
+
constructor(resource, options = {})
|
|
68
68
|
{
|
|
69
|
-
const service = Object.values(
|
|
70
|
-
const connectivity =
|
|
69
|
+
const service = Object.values(resource["services"]["light_level"])[0];
|
|
70
|
+
const connectivity = resource.services.zigbee_connectivity ? Object.values(resource.services.zigbee_connectivity)[0] : ((resource.services.zgp_connectivity) ? Object.values(resource.services.zgp_connectivity)[0] : false);
|
|
71
71
|
|
|
72
72
|
var realLUX = service.light.light_level - 1;
|
|
73
73
|
realLUX = realLUX / 10000;
|
|
@@ -82,25 +82,25 @@ class HueBrightnessMessage
|
|
|
82
82
|
this.message.payload.lightLevel = service.light.light_level;
|
|
83
83
|
this.message.payload.dark = (realLUX < 200);
|
|
84
84
|
this.message.payload.daylight = (realLUX > 200);
|
|
85
|
-
this.message.payload.updated =
|
|
85
|
+
this.message.payload.updated = resource.updated;
|
|
86
86
|
|
|
87
87
|
this.message.info = {};
|
|
88
88
|
this.message.info.id = service.id;
|
|
89
|
-
this.message.info.idV1 =
|
|
90
|
-
this.message.info.uniqueId =
|
|
91
|
-
this.message.info.deviceId =
|
|
92
|
-
this.message.info.name =
|
|
89
|
+
this.message.info.idV1 = resource.id_v1 ? resource.id_v1 : false; // NEW
|
|
90
|
+
this.message.info.uniqueId = resource.id + "-" + service.id;
|
|
91
|
+
this.message.info.deviceId = resource.id; // NEW!
|
|
92
|
+
this.message.info.name = resource.metadata.name;
|
|
93
93
|
this.message.info.type = "light_level";
|
|
94
|
-
this.message.info.softwareVersion =
|
|
95
|
-
this.message.info.battery = Object.values(
|
|
96
|
-
this.message.info.batteryState = Object.values(
|
|
94
|
+
this.message.info.softwareVersion = resource.product_data.software_version;
|
|
95
|
+
this.message.info.battery = Object.values(resource.services.device_power)[0].power_state.battery_level;
|
|
96
|
+
this.message.info.batteryState = Object.values(resource.services.device_power)[0].power_state.battery_state; // NEW!
|
|
97
97
|
|
|
98
98
|
this.message.info.model = {};
|
|
99
|
-
this.message.info.model.id =
|
|
100
|
-
this.message.info.model.manufacturer =
|
|
101
|
-
this.message.info.model.name =
|
|
102
|
-
this.message.info.model.type =
|
|
103
|
-
this.message.info.model.certified =
|
|
99
|
+
this.message.info.model.id = resource.product_data.model_id;
|
|
100
|
+
this.message.info.model.manufacturer = resource.product_data.manufacturer_name;
|
|
101
|
+
this.message.info.model.name = resource.product_data.product_name;
|
|
102
|
+
this.message.info.model.type = resource.product_data.product_archetype;
|
|
103
|
+
this.message.info.model.certified = resource.product_data.certified; // NEW
|
|
104
104
|
}
|
|
105
105
|
|
|
106
106
|
get msg()
|
|
@@ -114,20 +114,20 @@ class HueBrightnessMessage
|
|
|
114
114
|
// HUE GROUP
|
|
115
115
|
class HueGroupMessage
|
|
116
116
|
{
|
|
117
|
-
constructor(
|
|
117
|
+
constructor(resource, options = {})
|
|
118
118
|
{
|
|
119
|
-
let service = Object.values(
|
|
120
|
-
service = options.
|
|
119
|
+
let service = Object.values(resource["services"]["grouped_light"])[0];
|
|
120
|
+
service = options.resources[service.id];
|
|
121
121
|
|
|
122
122
|
this.message = {};
|
|
123
123
|
this.message.payload = {};
|
|
124
124
|
this.message.payload.on = service.on.on;
|
|
125
|
-
this.message.payload.updated =
|
|
125
|
+
this.message.payload.updated = resource.updated;
|
|
126
126
|
|
|
127
127
|
this.message.info = {};
|
|
128
|
-
this.message.info.id =
|
|
129
|
-
this.message.info.idV1 =
|
|
130
|
-
this.message.info.name =
|
|
128
|
+
this.message.info.id = resource.id;
|
|
129
|
+
this.message.info.idV1 = resource.id_v1 ? resource.id_v1 : false; // NEW
|
|
130
|
+
this.message.info.name = resource.metadata ? resource.metadata.name : "all";
|
|
131
131
|
this.message.info.type = "group";
|
|
132
132
|
}
|
|
133
133
|
|
|
@@ -142,10 +142,10 @@ class HueGroupMessage
|
|
|
142
142
|
// HUE LIGHT
|
|
143
143
|
class HueLightMessage
|
|
144
144
|
{
|
|
145
|
-
constructor(
|
|
145
|
+
constructor(resource, options = {})
|
|
146
146
|
{
|
|
147
|
-
const service = Object.values(
|
|
148
|
-
const connectivity =
|
|
147
|
+
const service = Object.values(resource["services"]["light"])[0];
|
|
148
|
+
const connectivity = resource.services.zigbee_connectivity ? Object.values(resource.services.zigbee_connectivity)[0] : ((resource.services.zgp_connectivity) ? Object.values(resource.services.zgp_connectivity)[0] : false);
|
|
149
149
|
|
|
150
150
|
this.message = {};
|
|
151
151
|
this.message.payload = {};
|
|
@@ -154,23 +154,23 @@ class HueLightMessage
|
|
|
154
154
|
this.message.payload.brightnessLevel = service.dimming ? Math.round((254/100)*this.message.payload.brightness) : false;
|
|
155
155
|
this.message.payload.reachable = connectivity ? (connectivity.status === "connected") : "unknown";
|
|
156
156
|
this.message.payload.connectionStatus = connectivity ? connectivity.status : "unknown"; // NEW!
|
|
157
|
-
this.message.payload.updated =
|
|
157
|
+
this.message.payload.updated = resource.updated;
|
|
158
158
|
|
|
159
159
|
this.message.info = {};
|
|
160
160
|
this.message.info.id = service.id;
|
|
161
|
-
this.message.info.idV1 =
|
|
162
|
-
this.message.info.uniqueId =
|
|
163
|
-
this.message.info.deviceId =
|
|
161
|
+
this.message.info.idV1 = resource.id_v1 ? resource.id_v1 : false; // NEW
|
|
162
|
+
this.message.info.uniqueId = resource.id + "-" + service.id;
|
|
163
|
+
this.message.info.deviceId = resource.id; // NEW!
|
|
164
164
|
this.message.info.name = service.metadata.name;
|
|
165
165
|
this.message.info.type = "light";
|
|
166
|
-
this.message.info.softwareVersion =
|
|
166
|
+
this.message.info.softwareVersion = resource.product_data.software_version;
|
|
167
167
|
|
|
168
168
|
this.message.info.model = {};
|
|
169
|
-
this.message.info.model.id =
|
|
170
|
-
this.message.info.model.manufacturer =
|
|
171
|
-
this.message.info.model.name =
|
|
172
|
-
this.message.info.model.type =
|
|
173
|
-
this.message.info.model.certified =
|
|
169
|
+
this.message.info.model.id = resource.product_data.model_id;
|
|
170
|
+
this.message.info.model.manufacturer = resource.product_data.manufacturer_name;
|
|
171
|
+
this.message.info.model.name = resource.product_data.product_name;
|
|
172
|
+
this.message.info.model.type = resource.product_data.product_archetype;
|
|
173
|
+
this.message.info.model.certified = resource.product_data.certified; // NEW
|
|
174
174
|
this.message.info.model.friendsOfHue = true;
|
|
175
175
|
|
|
176
176
|
// HAS COLOR CAPABILITIES?
|
|
@@ -237,10 +237,10 @@ class HueLightMessage
|
|
|
237
237
|
// HUE MOTION
|
|
238
238
|
class HueMotionMessage
|
|
239
239
|
{
|
|
240
|
-
constructor(
|
|
240
|
+
constructor(resource, options = {})
|
|
241
241
|
{
|
|
242
|
-
const service = Object.values(
|
|
243
|
-
const connectivity =
|
|
242
|
+
const service = Object.values(resource["services"]["motion"])[0];
|
|
243
|
+
const connectivity = resource.services.zigbee_connectivity ? Object.values(resource.services.zigbee_connectivity)[0] : ((resource.services.zgp_connectivity) ? Object.values(resource.services.zgp_connectivity)[0] : false);
|
|
244
244
|
|
|
245
245
|
this.message = {};
|
|
246
246
|
this.message.payload = {
|
|
@@ -248,26 +248,26 @@ class HueMotionMessage
|
|
|
248
248
|
reachable: connectivity ? (connectivity.status === "connected") : "unknown",
|
|
249
249
|
connectionStatus: connectivity ? connectivity.status : "unknown", // NEW!
|
|
250
250
|
motion: (service.motion.motion && service.motion.motion_valid),
|
|
251
|
-
updated:
|
|
251
|
+
updated: resource.updated
|
|
252
252
|
};
|
|
253
253
|
|
|
254
254
|
this.message.info = {};
|
|
255
255
|
this.message.info.id = service.id;
|
|
256
|
-
this.message.info.idV1 =
|
|
257
|
-
this.message.info.uniqueId =
|
|
258
|
-
this.message.info.deviceId =
|
|
259
|
-
this.message.info.name =
|
|
256
|
+
this.message.info.idV1 = resource.id_v1 ? resource.id_v1 : false; // NEW
|
|
257
|
+
this.message.info.uniqueId = resource.id + "-" + service.id;
|
|
258
|
+
this.message.info.deviceId = resource.id; // NEW!
|
|
259
|
+
this.message.info.name = resource.metadata.name;
|
|
260
260
|
this.message.info.type = "motion";
|
|
261
|
-
this.message.info.softwareVersion =
|
|
262
|
-
this.message.info.battery = Object.values(
|
|
263
|
-
this.message.info.batteryState = Object.values(
|
|
261
|
+
this.message.info.softwareVersion = resource.product_data.software_version;
|
|
262
|
+
this.message.info.battery = Object.values(resource.services.device_power)[0].power_state.battery_level;
|
|
263
|
+
this.message.info.batteryState = Object.values(resource.services.device_power)[0].power_state.battery_state; // NEW!
|
|
264
264
|
|
|
265
265
|
this.message.info.model = {};
|
|
266
|
-
this.message.info.model.id =
|
|
267
|
-
this.message.info.model.manufacturer =
|
|
268
|
-
this.message.info.model.name =
|
|
269
|
-
this.message.info.model.type =
|
|
270
|
-
this.message.info.model.certified =
|
|
266
|
+
this.message.info.model.id = resource.product_data.model_id;
|
|
267
|
+
this.message.info.model.manufacturer = resource.product_data.manufacturer_name;
|
|
268
|
+
this.message.info.model.name = resource.product_data.product_name;
|
|
269
|
+
this.message.info.model.type = resource.product_data.product_archetype;
|
|
270
|
+
this.message.info.model.certified = resource.product_data.certified; // NEW
|
|
271
271
|
}
|
|
272
272
|
|
|
273
273
|
get msg()
|
|
@@ -281,23 +281,23 @@ class HueMotionMessage
|
|
|
281
281
|
// HUE RULES
|
|
282
282
|
class HueRulesMessage
|
|
283
283
|
{
|
|
284
|
-
constructor(
|
|
284
|
+
constructor(resource, options = {})
|
|
285
285
|
{
|
|
286
286
|
this.message = {};
|
|
287
287
|
this.message.payload = {};
|
|
288
|
-
this.message.payload.enabled = (
|
|
289
|
-
this.message.payload.triggered = (
|
|
288
|
+
this.message.payload.enabled = (resource["status"] == "enabled"); // NEW!
|
|
289
|
+
this.message.payload.triggered = (resource["lasttriggered"] != null) ? dayjs(resource["lasttriggered"]).format() : false;
|
|
290
290
|
|
|
291
291
|
this.message.info = {};
|
|
292
|
-
this.message.info.id =
|
|
293
|
-
this.message.info.created = dayjs(
|
|
294
|
-
this.message.info.name =
|
|
295
|
-
this.message.info.timesTriggered =
|
|
296
|
-
this.message.info.owner =
|
|
297
|
-
this.message.info.status =
|
|
298
|
-
|
|
299
|
-
this.message.conditions =
|
|
300
|
-
this.message.actions =
|
|
292
|
+
this.message.info.id = resource["id"];
|
|
293
|
+
this.message.info.created = dayjs(resource["created"]).format();
|
|
294
|
+
this.message.info.name = resource["name"];
|
|
295
|
+
this.message.info.timesTriggered = resource["timestriggered"];
|
|
296
|
+
this.message.info.owner = resource["_owner"];
|
|
297
|
+
this.message.info.status = resource["status"];
|
|
298
|
+
|
|
299
|
+
this.message.conditions = resource["conditions"];
|
|
300
|
+
this.message.actions = resource["actions"];
|
|
301
301
|
}
|
|
302
302
|
|
|
303
303
|
get msg()
|
|
@@ -311,13 +311,13 @@ class HueRulesMessage
|
|
|
311
311
|
// HUE BUTTONS
|
|
312
312
|
class HueButtonsMessage
|
|
313
313
|
{
|
|
314
|
-
constructor(
|
|
314
|
+
constructor(resource, options = {})
|
|
315
315
|
{
|
|
316
|
-
const connectivity =
|
|
316
|
+
const connectivity = resource.services.zigbee_connectivity ? Object.values(resource.services.zigbee_connectivity)[0] : ((resource.services.zgp_connectivity) ? Object.values(resource.services.zgp_connectivity)[0] : false);
|
|
317
317
|
|
|
318
318
|
// FIND PRESSED BUTTON
|
|
319
319
|
var pressedButton = false;
|
|
320
|
-
const allButtons = Object.values(
|
|
320
|
+
const allButtons = Object.values(resource.services.button);
|
|
321
321
|
|
|
322
322
|
for (var i = allButtons.length - 1; i >= 0; i--)
|
|
323
323
|
{
|
|
@@ -334,26 +334,26 @@ class HueButtonsMessage
|
|
|
334
334
|
connectionStatus: connectivity ? connectivity.status : "unknown", // NEW!
|
|
335
335
|
button: pressedButton ? pressedButton.metadata.control_id : false, // NEW
|
|
336
336
|
action: pressedButton ? pressedButton.button.last_event : false, // NEW
|
|
337
|
-
updated:
|
|
337
|
+
updated: resource.updated
|
|
338
338
|
};
|
|
339
339
|
|
|
340
340
|
this.message.info = {};
|
|
341
|
-
this.message.info.id = pressedButton ? pressedButton.id :
|
|
342
|
-
this.message.info.idV1 =
|
|
343
|
-
this.message.info.uniqueId =
|
|
344
|
-
this.message.info.deviceId =
|
|
345
|
-
this.message.info.name =
|
|
341
|
+
this.message.info.id = pressedButton ? pressedButton.id : resource.id;
|
|
342
|
+
this.message.info.idV1 = resource.id_v1 ? resource.id_v1 : false; // NEW
|
|
343
|
+
this.message.info.uniqueId = resource.id + "-" + (pressedButton ? pressedButton.id : "");
|
|
344
|
+
this.message.info.deviceId = resource.id; // NEW!
|
|
345
|
+
this.message.info.name = resource.metadata.name;
|
|
346
346
|
this.message.info.type = "button";
|
|
347
|
-
this.message.info.softwareVersion =
|
|
348
|
-
this.message.info.battery =
|
|
349
|
-
this.message.info.batteryState =
|
|
347
|
+
this.message.info.softwareVersion = resource.product_data.software_version;
|
|
348
|
+
this.message.info.battery = resource.services.device_power ? Object.values(resource.services.device_power)[0].power_state.battery_level : false;
|
|
349
|
+
this.message.info.batteryState = resource.services.device_power ? Object.values(resource.services.device_power)[0].power_state.battery_state : false; // NEW!
|
|
350
350
|
|
|
351
351
|
this.message.info.model = {};
|
|
352
|
-
this.message.info.model.id =
|
|
353
|
-
this.message.info.model.manufacturer =
|
|
354
|
-
this.message.info.model.name =
|
|
355
|
-
this.message.info.model.type =
|
|
356
|
-
this.message.info.model.certified =
|
|
352
|
+
this.message.info.model.id = resource.product_data.model_id;
|
|
353
|
+
this.message.info.model.manufacturer = resource.product_data.manufacturer_name;
|
|
354
|
+
this.message.info.model.name = resource.product_data.product_name;
|
|
355
|
+
this.message.info.model.type = resource.product_data.product_archetype;
|
|
356
|
+
this.message.info.model.certified = resource.product_data.certified; // NEW
|
|
357
357
|
}
|
|
358
358
|
|
|
359
359
|
get msg()
|
|
@@ -367,10 +367,10 @@ class HueButtonsMessage
|
|
|
367
367
|
// HUE TEMPERATURE
|
|
368
368
|
class HueTemperatureMessage
|
|
369
369
|
{
|
|
370
|
-
constructor(
|
|
370
|
+
constructor(resource, options = {})
|
|
371
371
|
{
|
|
372
|
-
const service = Object.values(
|
|
373
|
-
const connectivity =
|
|
372
|
+
const service = Object.values(resource["services"]["temperature"])[0];
|
|
373
|
+
const connectivity = resource.services.zigbee_connectivity ? Object.values(resource.services.zigbee_connectivity)[0] : ((resource.services.zgp_connectivity) ? Object.values(resource.services.zgp_connectivity)[0] : false);
|
|
374
374
|
|
|
375
375
|
var deviceValue = service.temperature.temperature;
|
|
376
376
|
var celsius = Math.round(deviceValue * 100) / 100;
|
|
@@ -413,26 +413,26 @@ class HueTemperatureMessage
|
|
|
413
413
|
fahrenheit: fahrenheit,
|
|
414
414
|
temperatureIs: temperatureMessage,
|
|
415
415
|
deviceValue: deviceValue,
|
|
416
|
-
updated:
|
|
416
|
+
updated: resource.updated
|
|
417
417
|
};
|
|
418
418
|
|
|
419
419
|
this.message.info = {};
|
|
420
420
|
this.message.info.id = service.id;
|
|
421
|
-
this.message.info.idV1 =
|
|
422
|
-
this.message.info.uniqueId =
|
|
423
|
-
this.message.info.deviceId =
|
|
424
|
-
this.message.info.name =
|
|
421
|
+
this.message.info.idV1 = resource.id_v1 ? resource.id_v1 : false; // NEW
|
|
422
|
+
this.message.info.uniqueId = resource.id + "-" + service.id;
|
|
423
|
+
this.message.info.deviceId = resource.id; // NEW!
|
|
424
|
+
this.message.info.name = resource.metadata.name;
|
|
425
425
|
this.message.info.type = "temperature";
|
|
426
|
-
this.message.info.softwareVersion =
|
|
427
|
-
this.message.info.battery = Object.values(
|
|
428
|
-
this.message.info.batteryState = Object.values(
|
|
426
|
+
this.message.info.softwareVersion = resource.product_data.software_version;
|
|
427
|
+
this.message.info.battery = Object.values(resource.services.device_power)[0].power_state.battery_level;
|
|
428
|
+
this.message.info.batteryState = Object.values(resource.services.device_power)[0].power_state.battery_state; // NEW!
|
|
429
429
|
|
|
430
430
|
this.message.info.model = {};
|
|
431
|
-
this.message.info.model.id =
|
|
432
|
-
this.message.info.model.manufacturer =
|
|
433
|
-
this.message.info.model.name =
|
|
434
|
-
this.message.info.model.type =
|
|
435
|
-
this.message.info.model.certified =
|
|
431
|
+
this.message.info.model.id = resource.product_data.model_id;
|
|
432
|
+
this.message.info.model.manufacturer = resource.product_data.manufacturer_name;
|
|
433
|
+
this.message.info.model.name = resource.product_data.product_name;
|
|
434
|
+
this.message.info.model.type = resource.product_data.product_archetype;
|
|
435
|
+
this.message.info.model.certified = resource.product_data.certified; // NEW
|
|
436
436
|
}
|
|
437
437
|
|
|
438
438
|
get msg()
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "node-red-contrib-huemagic",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.3",
|
|
4
4
|
"description": "Philips Hue node to control bridges, lights, groups, scenes, rules, taps, switches, buttons, motion sensors, temperature sensors and Lux sensors using Node-RED.",
|
|
5
5
|
"author": "foddy",
|
|
6
6
|
"homepage": "https://github.com/Foddy/node-red-contrib-huemagic",
|