Sensors.js
3.26 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
110
111
112
113
114
115
116
117
118
119
120
121
'use strict';
const sensorsApi = require('./http/endpoints/sensors')
, ApiDefinition = require('./http/ApiDefinition.js')
, util = require('../util')
;
/**
* @typedef {import('@peter-murray/hue-bridge-model').model.Sensor} Sensor
*
* @type {Sensors}
*/
module.exports = class Sensors extends ApiDefinition {
constructor(hueApi) {
super(hueApi);
}
/**
* Gets all the sesnors from the bridge
* @returns {Promise<Sensor[]>}
*/
getAll() {
return this.execute(sensorsApi.getAllSensors);
}
/**
* @deprecated use getSensor(id) instead
* @param id {string | Sensor}
* @returns {Promise<Sensor>}
*/
get(id) {
util.deprecatedFunction('5.x', 'sensors.get(id)', 'Use sensors.getSensor(id) instead.');
return this.getSensor(id);
}
/**
* @param id {string | Sensor}
* @returns {Promise<Sensor>}
*/
getSensor(id) {
return this.execute(sensorsApi.getSensor, {id: id});
}
/**
* Starts a search for new ZigBee sensors
* @returns {Promise<boolean>}
*/
searchForNew() {
return this.execute(sensorsApi.findNewSensors);
}
/**
* Obtains the new sesnors that were found from the previous search for new sensors
* @returns {Promise<Sensor>}.
*/
getNew() {
return this.execute(sensorsApi.getNewSensors);
}
/**
* Will update the name attribute of the Sensor on the Bridge.
* @param sensor { Sensor } The Sensor with the update to the name applied
* @returns {Promise<Boolean>}
*/
renameSensor(sensor) {
return this.execute(sensorsApi.updateSensor, {id: sensor, name: sensor.name});
}
/**
* @deprecated use renameSensor(sensor) instead
* @param id {String | Sensor} The id or the Sensor instance to update
* @returns {Promise<Boolean>}
*/
updateName(id, name) {
util.deprecatedFunction('5.x', 'sensors.updateName(id, name)', 'Use sensors.rename(sensor) instead.');
return this.execute(sensorsApi.updateSensor, {id: id, name: name});
}
/**
* Creates a new Sensor (CLIP based)
* @param sensor {Sensor} The CLIP Sensor that you wish to create.
* @returns {Promise<Sensor>}
*/
createSensor(sensor) {
const self = this;
return self.execute(sensorsApi.createSensor, {sensor: sensor})
.then(data => {
return self.getSensor(data.id);
});
}
/**
* Deletes a sensor from the Bridge
* @param id {string | Sensor} The id or Sensor instance to remove from the bridge
* @returns {Promise<Boolean>}
*/
deleteSensor(id) {
return this.execute(sensorsApi.deleteSensor, {id: id});
}
/**
* Will update the configuration attributes of the Sensor in the bridge.
* @param sensor {Sensor}
* @returns {Promise<Object>}
*/
updateSensorConfig(sensor) {
return this.execute(sensorsApi.changeSensorConfig, {id: sensor.id, sensor: sensor});
}
/**
* Will update the state attributes of the Sensor in the bridge.
* @param sensor {Sensor}
* @param limitToStateNames {String[]} optional list of state attributes to limit the update to (should not be needed in practice, was added to get around a bug).
* @returns {Promise<Object>}
*/
updateSensorState(sensor, limitToStateNames) {
return this.execute(sensorsApi.changeSensorState, {id: sensor.id, sensor: sensor, filterStateNames: limitToStateNames});
}
};