iobroker.iot 3.5.2 → 4.0.1
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 +24 -9
- package/admin/assets/index-Y479CE6x.js +681 -0
- package/admin/index_m.html +1 -1
- package/admin/rules/assets/{ActionVisu-D9x2f6zu.js → ActionVisu-DE8dgNVF.js} +1 -1
- package/admin/rules/assets/{ActionVisu__loadShare__react__loadShare__-Cg21Ef1U.js → ActionVisu__loadShare__react__loadShare__-BKaC-p5K.js} +1 -1
- package/admin/rules/assets/{ActionVisu__loadShare__react_mf_2_dom__loadShare__-B1zRWn0u.js → ActionVisu__loadShare__react_mf_2_dom__loadShare__-Bs1o8DtQ.js} +2 -2
- package/admin/rules/assets/ActionVisu__mf_v__runtimeInit__mf_v__-DtUoI3FU.js +5 -0
- package/admin/rules/assets/bootstrap-Ba57tu25.js +1 -0
- package/admin/rules/assets/hostInit-hos3Txsy.js +1 -1
- package/admin/rules/assets/{index-Duo7mFlZ.js → index-CbxmbJvB.js} +2 -2
- package/admin/rules/assets/{index-CAAeiKCc.js → index-DjPMvPni.js} +2 -2
- package/admin/rules/assets/index-_Y2FN5EZ.js +1152 -0
- package/admin/rules/assets/{virtualExposes-BqVak7rX.js → virtualExposes-BNZJTatg.js} +2 -2
- package/admin/rules/customRuleBlocks.js +2 -2
- package/io-package.json +27 -27
- package/package.json +17 -14
- package/admin/assets/index-Df2NS929.js +0 -681
- package/admin/rules/assets/ActionVisu__mf_v__runtimeInit__mf_v__-Cz053nO7.js +0 -10
- package/admin/rules/assets/bootstrap-BCFKIiwZ.js +0 -1
- package/admin/rules/assets/index-BwcOGyWI.js +0 -1152
- package/lib/AlexaSmartHomeV3/Alexa/AlexaResponse.js +0 -262
- package/lib/AlexaSmartHomeV3/Alexa/Capabilities/Base.js +0 -124
- package/lib/AlexaSmartHomeV3/Alexa/Capabilities/BrightnessController.js +0 -15
- package/lib/AlexaSmartHomeV3/Alexa/Capabilities/ColorController.js +0 -10
- package/lib/AlexaSmartHomeV3/Alexa/Capabilities/ColorTemperatureController.js +0 -15
- package/lib/AlexaSmartHomeV3/Alexa/Capabilities/ContactSensor.js +0 -10
- package/lib/AlexaSmartHomeV3/Alexa/Capabilities/LockController.js +0 -10
- package/lib/AlexaSmartHomeV3/Alexa/Capabilities/ModeController.js +0 -69
- package/lib/AlexaSmartHomeV3/Alexa/Capabilities/MotionSensor.js +0 -10
- package/lib/AlexaSmartHomeV3/Alexa/Capabilities/PercentageController.js +0 -10
- package/lib/AlexaSmartHomeV3/Alexa/Capabilities/PowerController.js +0 -15
- package/lib/AlexaSmartHomeV3/Alexa/Capabilities/Speaker.js +0 -20
- package/lib/AlexaSmartHomeV3/Alexa/Capabilities/TemperatureSensor.js +0 -10
- package/lib/AlexaSmartHomeV3/Alexa/Capabilities/ThermostatController.js +0 -34
- package/lib/AlexaSmartHomeV3/Alexa/Capabilities/index.js +0 -14
- package/lib/AlexaSmartHomeV3/Alexa/Directives/Base.js +0 -27
- package/lib/AlexaSmartHomeV3/Alexa/Directives/ChangeReport.js +0 -75
- package/lib/AlexaSmartHomeV3/Alexa/Directives/Discovery.js +0 -39
- package/lib/AlexaSmartHomeV3/Alexa/Directives/ReportState.js +0 -50
- package/lib/AlexaSmartHomeV3/Alexa/Directives/index.js +0 -13
- package/lib/AlexaSmartHomeV3/Alexa/ModeValues/Base.js +0 -38
- package/lib/AlexaSmartHomeV3/Alexa/ModeValues/Closed.js +0 -55
- package/lib/AlexaSmartHomeV3/Alexa/ModeValues/Open.js +0 -56
- package/lib/AlexaSmartHomeV3/Alexa/ModeValues/index.js +0 -14
- package/lib/AlexaSmartHomeV3/Alexa/Properties/AdjustableProperty.js +0 -11
- package/lib/AlexaSmartHomeV3/Alexa/Properties/Base.js +0 -108
- package/lib/AlexaSmartHomeV3/Alexa/Properties/Brightness.js +0 -14
- package/lib/AlexaSmartHomeV3/Alexa/Properties/Color.js +0 -40
- package/lib/AlexaSmartHomeV3/Alexa/Properties/ColorTemperatureInKelvin.js +0 -62
- package/lib/AlexaSmartHomeV3/Alexa/Properties/DetectionState.js +0 -22
- package/lib/AlexaSmartHomeV3/Alexa/Properties/LockState.js +0 -40
- package/lib/AlexaSmartHomeV3/Alexa/Properties/Mode.js +0 -32
- package/lib/AlexaSmartHomeV3/Alexa/Properties/Muted.js +0 -17
- package/lib/AlexaSmartHomeV3/Alexa/Properties/Percentage.js +0 -14
- package/lib/AlexaSmartHomeV3/Alexa/Properties/PowerState.js +0 -25
- package/lib/AlexaSmartHomeV3/Alexa/Properties/TargetSetpoint.js +0 -28
- package/lib/AlexaSmartHomeV3/Alexa/Properties/Temperature.js +0 -20
- package/lib/AlexaSmartHomeV3/Alexa/Properties/ThermostatMode.js +0 -52
- package/lib/AlexaSmartHomeV3/Alexa/Properties/Volume.js +0 -19
- package/lib/AlexaSmartHomeV3/Alexa/Properties/index.js +0 -14
- package/lib/AlexaSmartHomeV3/Controls/AdjustableControl.js +0 -22
- package/lib/AlexaSmartHomeV3/Controls/AdjustablePercentageControl.js +0 -28
- package/lib/AlexaSmartHomeV3/Controls/AirCondition.js +0 -144
- package/lib/AlexaSmartHomeV3/Controls/Blind.js +0 -12
- package/lib/AlexaSmartHomeV3/Controls/ContactSensor.js +0 -17
- package/lib/AlexaSmartHomeV3/Controls/Control.js +0 -352
- package/lib/AlexaSmartHomeV3/Controls/Ct.js +0 -172
- package/lib/AlexaSmartHomeV3/Controls/Dimmer.js +0 -124
- package/lib/AlexaSmartHomeV3/Controls/Door.js +0 -9
- package/lib/AlexaSmartHomeV3/Controls/Gate.js +0 -42
- package/lib/AlexaSmartHomeV3/Controls/Hue.js +0 -207
- package/lib/AlexaSmartHomeV3/Controls/Light.js +0 -54
- package/lib/AlexaSmartHomeV3/Controls/Lock.js +0 -36
- package/lib/AlexaSmartHomeV3/Controls/Motion.js +0 -17
- package/lib/AlexaSmartHomeV3/Controls/ReadOnlyDetector.js +0 -25
- package/lib/AlexaSmartHomeV3/Controls/Slider.js +0 -10
- package/lib/AlexaSmartHomeV3/Controls/Socket.js +0 -21
- package/lib/AlexaSmartHomeV3/Controls/Temperature.js +0 -22
- package/lib/AlexaSmartHomeV3/Controls/Thermostat.js +0 -86
- package/lib/AlexaSmartHomeV3/Controls/VacuumCleaner.js +0 -28
- package/lib/AlexaSmartHomeV3/Controls/Volume.js +0 -109
- package/lib/AlexaSmartHomeV3/Controls/VolumeGroup.js +0 -9
- package/lib/AlexaSmartHomeV3/Controls/Window.js +0 -9
- package/lib/AlexaSmartHomeV3/Controls/index.js +0 -14
- package/lib/AlexaSmartHomeV3/Device.js +0 -84
- package/lib/AlexaSmartHomeV3/DeviceManager.js +0 -415
- package/lib/AlexaSmartHomeV3/Exceptions/AlexaV3Exception.js +0 -8
- package/lib/AlexaSmartHomeV3/Exceptions/HourlyDeviceRateLimitExceeded.js +0 -5
- package/lib/AlexaSmartHomeV3/Exceptions/OverallDailyRateLimitExceeded.js +0 -5
- package/lib/AlexaSmartHomeV3/Helpers/AdapterProvider.js +0 -46
- package/lib/AlexaSmartHomeV3/Helpers/FileHelper.js +0 -70
- package/lib/AlexaSmartHomeV3/Helpers/IotProxy.js +0 -44
- package/lib/AlexaSmartHomeV3/Helpers/Logger.js +0 -95
- package/lib/AlexaSmartHomeV3/Helpers/RateLimiter.js +0 -82
- package/lib/AlexaSmartHomeV3/Helpers/Utils.js +0 -583
- package/lib/Utils.js +0 -608
- package/lib/adminCommonSocket.js +0 -781
- package/lib/alexaCustom.js +0 -622
- package/lib/alexaSmartHomeV2.js +0 -2792
- package/lib/alexaSmartHomeV3.js +0 -117
- package/lib/alisa.js +0 -2412
- package/lib/devices.js +0 -20
- package/lib/functions.js +0 -21
- package/lib/googleHome.js +0 -3323
- package/lib/notifications.js +0 -37
- package/lib/remote.js +0 -1363
- package/lib/rooms.js +0 -45
- package/lib/texts.js +0 -79
- package/lib/translate.js +0 -19
- package/lib/visuApp.js +0 -157
- package/main.js +0 -1444
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
const AlexaResponse = require('../Alexa/AlexaResponse');
|
|
2
|
-
const Utils = require('../Helpers/Utils');
|
|
3
|
-
const Logger = require('../Helpers/Logger');
|
|
4
|
-
const AdapterProvider = require('../Helpers/AdapterProvider');
|
|
5
|
-
const Properties = require('../Alexa/Properties');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Represents the base functionality for a control in a smart device. A smart device has at least one control.
|
|
9
|
-
* The specific functionality, natively supported capabilities, etc. are defined in derived classes.
|
|
10
|
-
* @class
|
|
11
|
-
*/
|
|
12
|
-
class Control {
|
|
13
|
-
/**
|
|
14
|
-
* @constructor
|
|
15
|
-
* @param detectedControl - The detected control in terms of iobroker type detector.
|
|
16
|
-
*/
|
|
17
|
-
constructor(detectedControl) {
|
|
18
|
-
this.stateKeys = [
|
|
19
|
-
'SET',
|
|
20
|
-
'ACTUAL',
|
|
21
|
-
'ON_SET',
|
|
22
|
-
'ON_ACTUAL',
|
|
23
|
-
'POWER',
|
|
24
|
-
'MODE',
|
|
25
|
-
'HUE',
|
|
26
|
-
'DIMMER',
|
|
27
|
-
'BRIGHTNESS',
|
|
28
|
-
'SATURATION',
|
|
29
|
-
'TEMPERATURE',
|
|
30
|
-
'ON',
|
|
31
|
-
'MUTE',
|
|
32
|
-
];
|
|
33
|
-
this.initStates(detectedControl);
|
|
34
|
-
this._supported = this.initCapabilities();
|
|
35
|
-
this._enforced = this.initEnforcedCapabilities();
|
|
36
|
-
this.log = new Logger(this);
|
|
37
|
-
this.log.silly(`created instance`);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* This function maps a passed on control to an array of objects. Each object contains an Alexa capability the control natively supports
|
|
41
|
-
* and at least one property. Every property is initialized with corresponding iobroker state ids and value converters from Alexa to iobroker types
|
|
42
|
-
* and vice versa.
|
|
43
|
-
*
|
|
44
|
-
* @returns Array of objects with natively supported Alexa capabilities and correspondingly configured instances of StateProxies
|
|
45
|
-
*/
|
|
46
|
-
initCapabilities() {
|
|
47
|
-
return [];
|
|
48
|
-
}
|
|
49
|
-
/**
|
|
50
|
-
* This function maps a passed on control to an array of objects. Each object contains an Alexa capability the control can handle even
|
|
51
|
-
* though not natively supported (e.g., the light control can handle the Alexa BrightnessController directive by switching
|
|
52
|
-
* itself `ON` on brightness > 0 and `OFF` on brightness == 0)
|
|
53
|
-
* Every capability has at least one property with set up iobroker state ids and value converters from Alexa to iobroker types
|
|
54
|
-
* and vice versa.
|
|
55
|
-
*
|
|
56
|
-
* @returns Array of objects with natively supported Alexa capabilities and correspondingly configured instances of StateProxies
|
|
57
|
-
*/
|
|
58
|
-
initEnforcedCapabilities() {
|
|
59
|
-
return [];
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
get allCapabilities() {
|
|
63
|
-
return this.supported.concat(this.enforced);
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
static get type() {
|
|
67
|
-
return Utils.firstLower(Utils.className(this.toString()));
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Getter for Alexa categories
|
|
71
|
-
*/
|
|
72
|
-
get categories() {
|
|
73
|
-
return ['OTHER'];
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
get name() {
|
|
77
|
-
return `${this.constructor.name}`;
|
|
78
|
-
}
|
|
79
|
-
/**
|
|
80
|
-
* Getter for _supported
|
|
81
|
-
*/
|
|
82
|
-
get supported() {
|
|
83
|
-
return this._supported;
|
|
84
|
-
}
|
|
85
|
-
/**
|
|
86
|
-
* Getter for _enforced
|
|
87
|
-
*/
|
|
88
|
-
get enforced() {
|
|
89
|
-
return this._enforced;
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* This function returns whether the control natively supports the passed on Alexa directive.
|
|
93
|
-
* @param {*} event - The event containing the Alexa directive as it comes from AWS Alexa Service
|
|
94
|
-
* @returns {Boolean} - True if the control natively supports the directive, false - otherwise
|
|
95
|
-
*/
|
|
96
|
-
supports(event) {
|
|
97
|
-
return this.supported.find(capability => capability.matches(event)) !== undefined;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* This function returns whether the control though doesn't natively support the passed on Alexa directive, but able to handle it.
|
|
101
|
-
* @param {*} event - The event containing the Alexa directive as it comes from AWS Alexa Service
|
|
102
|
-
* @returns {Boolean} - True if the control can handle the directive, false - otherwise
|
|
103
|
-
*/
|
|
104
|
-
canHandle(event) {
|
|
105
|
-
return this.enforced.find(capability => capability.matches(event)) !== undefined;
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* This function processes an Alexa directive. Usually the result of the processing is setting an iobroker state to some value
|
|
109
|
-
* as a reaction to an interaction with Alexa via voice, app, etc.
|
|
110
|
-
* @async
|
|
111
|
-
* @param {*} event - The event containing the Alexa directive as it comes from AWS Alexa Service
|
|
112
|
-
* @returns {Promise<Object>} - Object containing the response to be sent to Alexa Service
|
|
113
|
-
*/
|
|
114
|
-
async handle(event) {
|
|
115
|
-
this.log.debug(`handling Alexa event`);
|
|
116
|
-
this.log.silly(`${JSON.stringify(event)}`);
|
|
117
|
-
|
|
118
|
-
const property = this.allCapabilities
|
|
119
|
-
.flatMap(item => item.properties)
|
|
120
|
-
.find(property => property.matches(event));
|
|
121
|
-
|
|
122
|
-
if (property) {
|
|
123
|
-
let alexaValue;
|
|
124
|
-
try {
|
|
125
|
-
const setter = this.valueSetter(event);
|
|
126
|
-
alexaValue = await setter(event, property);
|
|
127
|
-
} catch (error) {
|
|
128
|
-
this.log.debug(`${error}`);
|
|
129
|
-
this.log.error(`failed handling Alexa event`);
|
|
130
|
-
return Promise.reject(AlexaResponse.endpointUnreachable().get());
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// even though the handler successfully processed the Alexa event,
|
|
134
|
-
// we return an error here for ENFORCED capabilities, to prevent
|
|
135
|
-
// reporting multiple successes for the same capability and
|
|
136
|
-
// running into a situation of returning a wrong value back to Alexa
|
|
137
|
-
if (this.enforced.find(capability => capability.matches(event))) {
|
|
138
|
-
return Promise.reject(AlexaResponse.directiveNotSupportedByControl(this.name, event?.directive?.header?.namespace, event?.directive?.header?.payloadVersion).get());
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
const response = AlexaResponse.handled(event, property.propertyName, property.reportValue(alexaValue), property.instance);
|
|
142
|
-
|
|
143
|
-
// though the processed directive required to change a single value, the response must contain values of all "relevant" properties
|
|
144
|
-
// Please refer to this for details: https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-thermostatcontroller.html#settargettemperature-response-event
|
|
145
|
-
|
|
146
|
-
// TODO: add values of relevant properties to response
|
|
147
|
-
|
|
148
|
-
this.log.silly(`${JSON.stringify(response.get())}`);
|
|
149
|
-
return response.get();
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const errorResponse = AlexaResponse.directiveNotSupportedByControl(this.name, event?.directive?.header?.namespace);
|
|
153
|
-
this.log.silly(`${JSON.stringify(errorResponse.get())}`);
|
|
154
|
-
return Promise.reject(errorResponse.get());
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
valueSetter(event) {
|
|
158
|
-
return this.setValue.bind(this);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
async setValue(event, property) {
|
|
162
|
-
// extract alexa value from event
|
|
163
|
-
const alexaValue = property.alexaDirectiveValue(event);
|
|
164
|
-
|
|
165
|
-
// convert alexa value to iobroker value
|
|
166
|
-
let value = property.value(alexaValue);
|
|
167
|
-
|
|
168
|
-
// if set, the device could support toggle
|
|
169
|
-
if (event.currentState) {
|
|
170
|
-
// console.error(`----------------------------------- command: ${value}, current value: ${JSON.stringify(event.currentState)}`);
|
|
171
|
-
const state = event.currentState.find(item => item.name === property.propertyName);
|
|
172
|
-
if (state && value === true) {
|
|
173
|
-
// it could support toggle.
|
|
174
|
-
// get current value
|
|
175
|
-
let current = property.value(state.value);
|
|
176
|
-
if (current === true) {
|
|
177
|
-
// turn off
|
|
178
|
-
value = false;
|
|
179
|
-
} else if (current !== false) {
|
|
180
|
-
const currentValue = await this.getOrRetrieveCurrentValue(property);
|
|
181
|
-
if (currentValue === true) {
|
|
182
|
-
// turn off
|
|
183
|
-
value = false;
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
// set iobroker state
|
|
190
|
-
await this.setState(property, value);
|
|
191
|
-
|
|
192
|
-
property.currentValue = value;
|
|
193
|
-
// return value as expected by Alexa
|
|
194
|
-
return property.alexaValue(value);
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
async adjustValue(event, property) {
|
|
198
|
-
// extract Alexa delta value from event
|
|
199
|
-
const delta = property.alexaDirectiveValue(event);
|
|
200
|
-
// get current value
|
|
201
|
-
const currentValue = await this.getOrRetrieveCurrentValue(property);
|
|
202
|
-
// convert the current value to Alexa value
|
|
203
|
-
const valueToAdjust = property.alexaValue(currentValue);
|
|
204
|
-
// adjust Alexa value
|
|
205
|
-
const adjustedValue = Utils.ensureValueInRange_0_100(valueToAdjust + delta);
|
|
206
|
-
// convert adjusted value to iobroker value
|
|
207
|
-
const value = property.value(adjustedValue);
|
|
208
|
-
|
|
209
|
-
// set iobroker state
|
|
210
|
-
await this.setState(property, value);
|
|
211
|
-
|
|
212
|
-
return adjustedValue;
|
|
213
|
-
}
|
|
214
|
-
|
|
215
|
-
/**
|
|
216
|
-
* @param {Object} property
|
|
217
|
-
*/
|
|
218
|
-
async getOrRetrieveCurrentValue(property) {
|
|
219
|
-
if (property.currentValue === undefined) {
|
|
220
|
-
property.currentValue = await AdapterProvider.getState(property.getId);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (property.currentValue === undefined) {
|
|
224
|
-
throw new Error(`unable to retrieve ${property.getId}`);
|
|
225
|
-
}
|
|
226
|
-
|
|
227
|
-
return property.currentValue;
|
|
228
|
-
}
|
|
229
|
-
|
|
230
|
-
async reportState() {
|
|
231
|
-
this.log.debug(`reporting state`);
|
|
232
|
-
|
|
233
|
-
let propertiesToReport = [];
|
|
234
|
-
|
|
235
|
-
for (const capability of this.supported) {
|
|
236
|
-
for (const property of capability.properties) {
|
|
237
|
-
try {
|
|
238
|
-
await this.getOrRetrieveCurrentValue(property);
|
|
239
|
-
|
|
240
|
-
let toReport = {
|
|
241
|
-
namespace: capability.namespace,
|
|
242
|
-
instance: property.instance,
|
|
243
|
-
name: property.propertyName,
|
|
244
|
-
value: property.reportValue(property.alexaValue(property.currentValue)),
|
|
245
|
-
};
|
|
246
|
-
|
|
247
|
-
if (!toReport.instance) {
|
|
248
|
-
delete toReport.instance;
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
propertiesToReport.push(toReport);
|
|
252
|
-
} catch (error) {
|
|
253
|
-
this.log.error(`failed reporting state for property ${property.propertyName} of ${this.name}`);
|
|
254
|
-
this.log.debug(`${error}`);
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
this.log.debug(`${JSON.stringify(propertiesToReport)}`);
|
|
260
|
-
return propertiesToReport;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
toString() {
|
|
264
|
-
return `${this.constructor.name}`;
|
|
265
|
-
}
|
|
266
|
-
|
|
267
|
-
initStates(ctrl) {
|
|
268
|
-
this._states = {};
|
|
269
|
-
for (const stateKey of this.stateKeys) {
|
|
270
|
-
this._states[stateKey] = ctrl.states.find(s => s.name === stateKey);
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
get states() {
|
|
275
|
-
return this._states;
|
|
276
|
-
}
|
|
277
|
-
|
|
278
|
-
get statesMap() {
|
|
279
|
-
const map = {}
|
|
280
|
-
for (const stateKey of this.stateKeys) {
|
|
281
|
-
map[stateKey.toLowerCase()] = stateKey;
|
|
282
|
-
}
|
|
283
|
-
return map;
|
|
284
|
-
}
|
|
285
|
-
|
|
286
|
-
async setState(property, value) {
|
|
287
|
-
await AdapterProvider.setState(property.setId, value);
|
|
288
|
-
property.currentValue = value;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
//-------------------------------------------------------
|
|
293
|
-
// standard property init objects
|
|
294
|
-
//
|
|
295
|
-
|
|
296
|
-
blankInitObject() {
|
|
297
|
-
// const states = this.initStates(ctrl);
|
|
298
|
-
const map = this.statesMap;
|
|
299
|
-
return {
|
|
300
|
-
setState: this.states[map.actual],
|
|
301
|
-
getState: this.states[map.actual],
|
|
302
|
-
};
|
|
303
|
-
}
|
|
304
|
-
|
|
305
|
-
powerStateInitObject() {
|
|
306
|
-
// const states = this.initStates(ctrl);
|
|
307
|
-
const map = this.statesMap;
|
|
308
|
-
|
|
309
|
-
return {
|
|
310
|
-
setState: this.states[map.set],
|
|
311
|
-
getState: this.states[map.actual],
|
|
312
|
-
alexaSetter: function (alexaValue) {
|
|
313
|
-
return alexaValue === Properties.PowerState.ON;
|
|
314
|
-
},
|
|
315
|
-
alexaGetter: function (value) {
|
|
316
|
-
return value ? Properties.PowerState.ON : Properties.PowerState.OFF;
|
|
317
|
-
},
|
|
318
|
-
};
|
|
319
|
-
}
|
|
320
|
-
|
|
321
|
-
detectedStateInitObject() {
|
|
322
|
-
const map = this.statesMap;
|
|
323
|
-
return {
|
|
324
|
-
setState: this.states[map.actual],
|
|
325
|
-
getState: this.states[map.actual],
|
|
326
|
-
alexaSetter: function (alexaValue) {
|
|
327
|
-
// should be never called
|
|
328
|
-
return 0;
|
|
329
|
-
},
|
|
330
|
-
alexaGetter: function (value) {
|
|
331
|
-
return value ? Properties.DetectionState.DETECTED : Properties.DetectionState.NOT_DETECTED;
|
|
332
|
-
},
|
|
333
|
-
};
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
percentageInitObject() {
|
|
337
|
-
const map = this.statesMap;
|
|
338
|
-
// const range = Utils.configuredRangeOrDefault(this.states[map.set]);
|
|
339
|
-
return {
|
|
340
|
-
setState: this.states[map.set],
|
|
341
|
-
getState: this.states[map.actual],
|
|
342
|
-
alexaSetter: function (alexaValue) {
|
|
343
|
-
return Utils.denormalize_0_100(alexaValue, this.valuesRangeMin, this.valuesRangeMax);
|
|
344
|
-
},
|
|
345
|
-
alexaGetter: function (value) {
|
|
346
|
-
return Utils.normalize_0_100(value, this.valuesRangeMin, this.valuesRangeMax);
|
|
347
|
-
},
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
|
-
|
|
352
|
-
module.exports = Control;
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
const Capabilities = require('../Alexa/Capabilities');
|
|
2
|
-
const Utils = require('../Helpers/Utils');
|
|
3
|
-
const Properties = require('../Alexa/Properties');
|
|
4
|
-
const AdapterProvider = require('../Helpers/AdapterProvider');
|
|
5
|
-
const AdjustableControl = require('./AdjustableControl');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @class
|
|
9
|
-
*/
|
|
10
|
-
class Ct extends AdjustableControl {
|
|
11
|
-
get categories() {
|
|
12
|
-
return ['LIGHT'];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
adjustableProperties() {
|
|
16
|
-
return [Properties.ColorTemperatureInKelvin];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
initCapabilities() {
|
|
20
|
-
const map = this.statesMap;
|
|
21
|
-
const result = [new Capabilities.ColorController()];
|
|
22
|
-
|
|
23
|
-
// if the state DIMMER or BRIGHTNESS configured
|
|
24
|
-
if (this.states[map.dimmer] || this.states[map.brightness]) {
|
|
25
|
-
this._brightnessCapability = new Capabilities.BrightnessController();
|
|
26
|
-
this._brightness = this._brightnessCapability.brightness;
|
|
27
|
-
result.push(this._brightnessCapability);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
// if the state TEMPERATURE configured
|
|
31
|
-
if (this.states[map.temperature]) {
|
|
32
|
-
this._colorTemperatureCapability = new Capabilities.ColorTemperatureController();
|
|
33
|
-
result.push(this._colorTemperatureCapability);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// if the state ON, DIMMER or BRIGHTNESS configured
|
|
37
|
-
if (this.states[map.on] || this._brightness) {
|
|
38
|
-
this._powerControllerCapability = new Capabilities.PowerController();
|
|
39
|
-
this._powerState = this._powerControllerCapability.powerState;
|
|
40
|
-
result.push(this._powerControllerCapability);
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
for (const property of result.flatMap(item => item.properties)) {
|
|
44
|
-
property.init(this.composeInitObject(property))
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
return result;
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
async getOrRetrieveCurrentValue(property) {
|
|
51
|
-
const map = this.statesMap;
|
|
52
|
-
|
|
53
|
-
if (property.currentValue === undefined) {
|
|
54
|
-
property.currentValue = await AdapterProvider.getState(property.getId);
|
|
55
|
-
// convert the non-zero brightness to power = true
|
|
56
|
-
if (property.propertyName === Properties.PowerState.propertyName && !this.states[map.on]) {
|
|
57
|
-
property.currentValue = property.currentValue !== 0;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
if (property.currentValue === undefined) {
|
|
62
|
-
throw new Error(`unable to retrieve ${property.getId}`);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
return property.currentValue;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
async setState(property, value) {
|
|
69
|
-
const map = this.statesMap;
|
|
70
|
-
|
|
71
|
-
if (property.propertyName === Properties.PowerState.propertyName) {
|
|
72
|
-
if (this.states[map.on]) {
|
|
73
|
-
await AdapterProvider.setState(property.setId, value);
|
|
74
|
-
property.currentValue = value;
|
|
75
|
-
} else {
|
|
76
|
-
if (value) { // set brightness
|
|
77
|
-
// set byOn to the configured value or range.max otherwise
|
|
78
|
-
const range = Utils.configuredRangeOrDefault(this.states[map.dimmer] || this.states[map.brightness]);
|
|
79
|
-
let byOn = (this.states[map.dimmer] || this.states[map.brightness])?.smartName?.byON;
|
|
80
|
-
byOn = isNaN(byOn) ? range.max : parseInt(byOn);
|
|
81
|
-
await AdapterProvider.setState(this._brightness.setId, byOn);
|
|
82
|
-
this._brightness.currentValue = byOn;
|
|
83
|
-
this._powerState.currentValue = true;
|
|
84
|
-
} else { // set brightness to 0 on power OFF
|
|
85
|
-
await AdapterProvider.setState(this._brightness.setId, 0);
|
|
86
|
-
this._brightness.currentValue = 0;
|
|
87
|
-
this._powerState.currentValue = false;
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
} else
|
|
91
|
-
if (property.propertyName === Properties.Brightness.propertyName
|
|
92
|
-
|| property.propertyName === Properties.ColorTemperatureInKelvin.propertyName) {
|
|
93
|
-
await AdapterProvider.setState(property.setId, value);
|
|
94
|
-
property.currentValue = value;
|
|
95
|
-
} else
|
|
96
|
-
if (property.propertyName === Properties.ColorTemperatureInKelvin.propertyName) {
|
|
97
|
-
await AdapterProvider.setState(property.setId, value);
|
|
98
|
-
property.currentValue = value;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
async adjustValue(event, property) {
|
|
103
|
-
// extract Alexa delta value from event
|
|
104
|
-
const delta = property.alexaDirectiveValue(event);
|
|
105
|
-
|
|
106
|
-
// convert delta to iobroker value
|
|
107
|
-
const value = property.value(delta);
|
|
108
|
-
|
|
109
|
-
// set iobroker state
|
|
110
|
-
await this.setState(property, value);
|
|
111
|
-
|
|
112
|
-
return value;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
composeInitObject(property) {
|
|
116
|
-
const map = this.statesMap;
|
|
117
|
-
|
|
118
|
-
if (property.propertyName === Properties.PowerState.propertyName) {
|
|
119
|
-
return {
|
|
120
|
-
setState: this.states[map.on] || this.states[map.dimmer] || this.states[map.brightness],
|
|
121
|
-
getState: this.states[map.on] || this.states[map.dimmer] || this.states[map.brightness],
|
|
122
|
-
alexaSetter: function (alexaValue) {
|
|
123
|
-
return alexaValue === Properties.PowerState.ON;
|
|
124
|
-
},
|
|
125
|
-
alexaGetter: function (value) {
|
|
126
|
-
return value ? Properties.PowerState.ON : Properties.PowerState.OFF;
|
|
127
|
-
},
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
if (property.propertyName === Properties.Brightness.propertyName) {
|
|
132
|
-
return {
|
|
133
|
-
setState: this.states[map.dimmer] || this.states[map.brightness],
|
|
134
|
-
getState: this.states[map.dimmer] || this.states[map.brightness],
|
|
135
|
-
alexaSetter: function (alexaValue) {
|
|
136
|
-
return Utils.denormalize_0_100(alexaValue, this.valuesRangeMin, this.valuesRangeMax);
|
|
137
|
-
},
|
|
138
|
-
alexaGetter: function (value) {
|
|
139
|
-
return Utils.normalize_0_100(value, this.valuesRangeMin, this.valuesRangeMax);
|
|
140
|
-
},
|
|
141
|
-
};
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
if (property.propertyName === Properties.ColorTemperatureInKelvin.propertyName) {
|
|
145
|
-
return {
|
|
146
|
-
setState: this.states[map.temperature],
|
|
147
|
-
getState: this.states[map.temperature],
|
|
148
|
-
alexaSetter: function (alexaValue) {
|
|
149
|
-
if (alexaValue === 1) { // increase directive
|
|
150
|
-
const closest = Utils.closestFromList(this.currentValue || this.colorTemperatureTable[0], this.colorTemperatureTable);
|
|
151
|
-
let index = this.colorTemperatureTable.indexOf(closest) + 1;
|
|
152
|
-
index = index >= this.colorTemperatureTable.length ? this.colorTemperatureTable.length - 1 : index;
|
|
153
|
-
return this.colorTemperatureTable[index];
|
|
154
|
-
}
|
|
155
|
-
if (alexaValue === -1) { // decrease directive
|
|
156
|
-
const closest = Utils.closestFromList(this.currentValue || this.colorTemperatureTable[0], this.colorTemperatureTable);
|
|
157
|
-
let index = this.colorTemperatureTable.indexOf(closest) - 1;
|
|
158
|
-
index = index < 0 ? 0 : index;
|
|
159
|
-
return this.colorTemperatureTable[index];
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
return alexaValue;
|
|
163
|
-
},
|
|
164
|
-
alexaGetter: function (value) {
|
|
165
|
-
return value;
|
|
166
|
-
},
|
|
167
|
-
};
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
module.exports = Ct;
|
|
@@ -1,124 +0,0 @@
|
|
|
1
|
-
const Capabilities = require('../Alexa/Capabilities');
|
|
2
|
-
const AdjustableControl = require('./AdjustableControl');
|
|
3
|
-
const Utils = require('../Helpers/Utils');
|
|
4
|
-
const Properties = require('../Alexa/Properties');
|
|
5
|
-
const AdapterProvider = require('../Helpers/AdapterProvider');
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* @class
|
|
9
|
-
*/
|
|
10
|
-
class Dimmer extends AdjustableControl {
|
|
11
|
-
get categories() {
|
|
12
|
-
return ['LIGHT'];
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
adjustableProperties() {
|
|
16
|
-
return [Properties.Brightness];
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
initCapabilities() {
|
|
20
|
-
this._powerControllerCapability = new Capabilities.PowerController();
|
|
21
|
-
this._powerState = this._powerControllerCapability.powerState;
|
|
22
|
-
|
|
23
|
-
this._brightnessCapability = new Capabilities.BrightnessController();
|
|
24
|
-
this._brightness = this._brightnessCapability.brightness;
|
|
25
|
-
|
|
26
|
-
let result = [this._powerControllerCapability, this._brightnessCapability];
|
|
27
|
-
for (const property of result.flatMap(item => item.properties)) {
|
|
28
|
-
property.init(this.composeInitObject(property))
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return result;
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
async setState(property, value) {
|
|
35
|
-
// set the property itself
|
|
36
|
-
await AdapterProvider.setState(property.setId, value);
|
|
37
|
-
property.currentValue = value;
|
|
38
|
-
const valuesRange = Utils.configuredRangeOrDefault(this.states[this.statesMap.set]);
|
|
39
|
-
|
|
40
|
-
// todo: use adapter.config.deviceOffLevel
|
|
41
|
-
// If
|
|
42
|
-
|
|
43
|
-
if (property.propertyName === Properties.PowerState.propertyName) {
|
|
44
|
-
// set brightness
|
|
45
|
-
if (value) {
|
|
46
|
-
// set byOn to the configured value or 100 otherwise
|
|
47
|
-
let byOn = this.states[this.statesMap.set].smartName?.byON;
|
|
48
|
-
byOn = isNaN(byOn) ? valuesRange.max : parseInt(byOn);
|
|
49
|
-
await AdapterProvider.setState(this._brightness.setId, byOn);
|
|
50
|
-
this._brightness.currentValue = byOn;
|
|
51
|
-
} else { // set brightness to 0 on power OFF
|
|
52
|
-
await AdapterProvider.setState(this._brightness.setId, valuesRange.min);
|
|
53
|
-
this._brightness.currentValue = valuesRange.min;
|
|
54
|
-
}
|
|
55
|
-
} else {
|
|
56
|
-
// set power
|
|
57
|
-
const powerValue = value !== valuesRange.min;
|
|
58
|
-
|
|
59
|
-
// only do this on different IDs for brightness and power
|
|
60
|
-
if (this._brightness.setId !== this._powerState.setId) {
|
|
61
|
-
await AdapterProvider.setState(this._powerState.setId, powerValue);
|
|
62
|
-
}
|
|
63
|
-
this._powerState.currentValue = powerValue;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
async getOrRetrieveCurrentValue(property) {
|
|
68
|
-
if (property.currentValue === undefined) {
|
|
69
|
-
property.currentValue = await AdapterProvider.getState(property.getId);
|
|
70
|
-
|
|
71
|
-
const valuesRange = Utils.configuredRangeOrDefault(this.states[this.statesMap.set]);
|
|
72
|
-
// convert non-zero brightness to power = true
|
|
73
|
-
if (property.propertyName === this._powerState.propertyName && property.getId === this._brightness.getId) {
|
|
74
|
-
property.currentValue = property.currentValue !== valuesRange.min;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
if (property.currentValue === undefined) {
|
|
79
|
-
throw new Error(`unable to retrieve ${property.getId}`);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
return property.currentValue;
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
composeInitObject(property) {
|
|
86
|
-
/*
|
|
87
|
-
Device of type 'dimmer' can be switched 'ON'/'OFF' and its brightness can be set to a value between 0 and 100.
|
|
88
|
-
|
|
89
|
-
If there is no 'ON_SET' state available:
|
|
90
|
-
- switching control 'OFF' is done via setting its brightness to 0
|
|
91
|
-
- switching control 'ON' is done via setting its brightness to the configured 'byOn' value or to the last known brightness.
|
|
92
|
-
*/
|
|
93
|
-
|
|
94
|
-
const map = this.statesMap;
|
|
95
|
-
|
|
96
|
-
if (property.propertyName === Properties.PowerState.propertyName) {
|
|
97
|
-
return {
|
|
98
|
-
setState: this.states[map.on_set] || this.states[map.set],
|
|
99
|
-
getState: this.states[map.on_actual] || this.states[map.on_set] || this.states[map.set],
|
|
100
|
-
alexaSetter: function (alexaValue) {
|
|
101
|
-
return alexaValue === Properties.PowerState.ON;
|
|
102
|
-
},
|
|
103
|
-
alexaGetter: function (value) {
|
|
104
|
-
return value ? Properties.PowerState.ON : Properties.PowerState.OFF;
|
|
105
|
-
},
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
if (property.propertyName === Properties.Brightness.propertyName) {
|
|
110
|
-
return {
|
|
111
|
-
setState: this.states[map.set],
|
|
112
|
-
getState: this.states[map.actual],
|
|
113
|
-
alexaSetter: function (alexaValue) {
|
|
114
|
-
return Utils.denormalize_0_100(alexaValue, this.valuesRangeMin, this.valuesRangeMax);
|
|
115
|
-
},
|
|
116
|
-
alexaGetter: function (value) {
|
|
117
|
-
return Utils.normalize_0_100(value, this.valuesRangeMin, this.valuesRangeMax);
|
|
118
|
-
},
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
module.exports = Dimmer;
|