v3.js
2.76 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
'use strict';
const api = require('./api/index')
, discovery = require('./api/discovery/index')
, v3Model = require('@peter-murray/hue-bridge-model').v3Model
, ApiError = require('./ApiError')
, util = require('./util')
;
// Definition of the v3 API for node-hue-api
module.exports = {
api: api,
discovery: {
upnpSearch: (timeout) => {
util.deprecatedFunction(
'6.x',
`require('node-hue-api').v3.discovery.upnpSearch()`,
`Use require('node-hue-api').discovery.upnpSearch()`);
return discovery.upnpSearch(timeout);
},
nupnpSearch: () => {
util.deprecatedFunction(
'6.x',
`require('node-hue-api').v3.discovery.nupnpSearch()`,
`Use require('node-hue-api').discovery.nupnpSearch()`);
return discovery.nupnpSearch();
},
description: (ipAddress) => {
util.deprecatedFunction(
'6.x',
`require('node-hue-api').v3.discovery.description(ipAddress)`,
`Use require('node-hue-api').discovery.description(ipAddress)`);
return discovery.description(ipAddress);
},
},
//TODO think about removing this and deferring to the model
lightStates: v3Model.lightStates,
model: v3Model,
//TODO remove
sensors: sensorsObject(
'Sensors are now contained in the v3.model interface\n' +
'You can use the v3.model.createCLIP[xxx]Sensor() where [xxx] is the type of Sensor to instantiate a sensor.'
),
//TODO remove
Scene: classRemoved(
'Scenes are no longer exposed as a class.\n' +
'Create a Scene using v3.model.createLightScene() or v3.model.createGroupScene()'
),
//TODO remove
rules: rulesObject(
'Rules are now exposed under the v3.model interface.\n' +
'Create a rule using v3.model.createRule()\n' +
'Create a RuleCondition using v3.model.ruleConditions.[sensor|group]()\n' +
'Create a RuleAction using v3.mode.ruleActions.[light|group|sensor|scene]\n'
),
};
function sensorsObject(msg) {
return {
clip: {
GenericFlag: classRemoved(msg),
OpenClose: classRemoved(msg),
GenericStatus: classRemoved(msg),
Humidity: classRemoved(msg),
Lightlevel: classRemoved(msg),
Presence: classRemoved(msg),
Switch: classRemoved(msg),
Temperature: classRemoved(msg),
}
}
}
function rulesObject(msg) {
return {
Rule: classRemoved(msg),
conditions: {
group: functionRemoved(msg),
sensor: functionRemoved(msg),
},
actions: {
light: functionRemoved(msg),
group: functionRemoved(msg),
scene: functionRemoved(msg),
},
};
}
function functionRemoved(msg) {
return function () {
throw new ApiError(msg);
};
}
function classRemoved(msg) {
return class RemovedClass {
constructor() {
throw new ApiError(msg);
}
};
}