iobroker.iot 4.0.1 → 4.0.2
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 +1 -1
- package/admin/assets/index-5zouxn2w.js +680 -0
- package/admin/index_m.html +1 -1
- package/admin/rules/assets/{ActionVisu-DE8dgNVF.js → ActionVisu-D9x2f6zu.js} +1 -1
- package/admin/rules/assets/{ActionVisu__loadShare__react__loadShare__-BKaC-p5K.js → ActionVisu__loadShare__react__loadShare__-Cg21Ef1U.js} +1 -1
- package/admin/rules/assets/{ActionVisu__loadShare__react_mf_2_dom__loadShare__-Bs1o8DtQ.js → ActionVisu__loadShare__react_mf_2_dom__loadShare__-B1zRWn0u.js} +2 -2
- package/admin/rules/assets/ActionVisu__mf_v__runtimeInit__mf_v__-Cz053nO7.js +10 -0
- package/admin/rules/assets/bootstrap-BCFKIiwZ.js +1 -0
- package/admin/rules/assets/hostInit-hos3Txsy.js +1 -1
- package/admin/rules/assets/{index-DjPMvPni.js → index-CAAeiKCc.js} +2 -2
- package/admin/rules/assets/{index-CbxmbJvB.js → index-Duo7mFlZ.js} +2 -2
- package/admin/rules/assets/index-DwYdaT5M.js +1151 -0
- package/admin/rules/assets/{virtualExposes-BNZJTatg.js → virtualExposes-BqVak7rX.js} +2 -2
- package/admin/rules/customRuleBlocks.js +2 -2
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/AlexaResponse.js +268 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/AlexaResponse.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/Base.js +110 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/Base.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/BrightnessController.js +19 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/BrightnessController.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/ColorController.js +14 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/ColorController.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/ColorTemperatureController.js +19 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/ColorTemperatureController.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/ContactSensor.js +16 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/ContactSensor.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/LockController.js +14 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/LockController.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/ModeController.js +68 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/ModeController.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/MotionSensor.js +14 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/MotionSensor.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/PercentageController.js +14 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/PercentageController.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/PowerController.js +19 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/PowerController.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/Speaker.js +25 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/Speaker.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/TemperatureSensor.js +14 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/TemperatureSensor.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/ThermostatController.js +37 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/ThermostatController.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/index.js +32 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/index.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Directives/Base.js +29 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Directives/Base.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Directives/ChangeReport.js +82 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Directives/ChangeReport.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Directives/Discovery.js +39 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Directives/Discovery.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Directives/ReportState.js +47 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Directives/ReportState.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Directives/index.js +14 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Directives/index.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/ModeValues/Base.js +36 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/ModeValues/Base.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/ModeValues/Closed.js +57 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/ModeValues/Closed.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/ModeValues/Open.js +57 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/ModeValues/Open.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/ModeValues/index.js +12 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/ModeValues/index.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/AdjustableProperty.js +16 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/AdjustableProperty.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Base.js +127 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Base.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Brightness.js +18 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Brightness.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Color.js +38 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Color.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/ColorTemperatureInKelvin.js +53 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/ColorTemperatureInKelvin.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/DetectionState.js +23 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/DetectionState.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/LockState.js +37 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/LockState.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Mode.js +34 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Mode.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Muted.js +19 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Muted.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Percentage.js +18 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Percentage.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/PowerState.js +25 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/PowerState.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/TargetSetpoint.js +31 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/TargetSetpoint.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Temperature.js +22 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Temperature.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/ThermostatMode.js +49 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/ThermostatMode.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Volume.js +21 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/Volume.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/index.js +38 -0
- package/build-backend/lib/AlexaSmartHomeV3/Alexa/Properties/index.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/AdjustableControl.js +20 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/AdjustableControl.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/AdjustablePercentageControl.js +26 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/AdjustablePercentageControl.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/AirCondition.js +148 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/AirCondition.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Blind.js +13 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Blind.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/ContactSensor.js +17 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/ContactSensor.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Control.js +321 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Control.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Ct.js +182 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Ct.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Dimmer.js +127 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Dimmer.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Door.js +10 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Door.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Gate.js +38 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Gate.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Hue.js +208 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Hue.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Light.js +47 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Light.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Lock.js +35 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Lock.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Motion.js +17 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Motion.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/ReadOnlyDetector.js +26 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/ReadOnlyDetector.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Slider.js +10 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Slider.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Socket.js +21 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Socket.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Temperature.js +21 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Temperature.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Thermostat.js +85 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Thermostat.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/VacuumCleaner.js +27 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/VacuumCleaner.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Volume.js +116 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Volume.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/VolumeGroup.js +10 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/VolumeGroup.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Window.js +10 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/Window.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/index.js +121 -0
- package/build-backend/lib/AlexaSmartHomeV3/Controls/index.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Device.js +83 -0
- package/build-backend/lib/AlexaSmartHomeV3/Device.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/DeviceManager.js +392 -0
- package/build-backend/lib/AlexaSmartHomeV3/DeviceManager.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Exceptions/AlexaV3Exception.js +10 -0
- package/build-backend/lib/AlexaSmartHomeV3/Exceptions/AlexaV3Exception.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Exceptions/HourlyDeviceRateLimitExceeded.js +10 -0
- package/build-backend/lib/AlexaSmartHomeV3/Exceptions/HourlyDeviceRateLimitExceeded.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Exceptions/OverallDailyRateLimitExceeded.js +10 -0
- package/build-backend/lib/AlexaSmartHomeV3/Exceptions/OverallDailyRateLimitExceeded.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/AdapterProvider.js +37 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/AdapterProvider.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/FileHelper.js +53 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/FileHelper.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/IotProxy.js +27 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/IotProxy.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/Logger.js +93 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/Logger.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/RateLimiter.js +112 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/RateLimiter.js.map +1 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/Utils.js +625 -0
- package/build-backend/lib/AlexaSmartHomeV3/Helpers/Utils.js.map +1 -0
- package/build-backend/lib/Utils.js +96 -0
- package/build-backend/lib/Utils.js.map +1 -0
- package/build-backend/lib/adminCommonSocket.js +715 -0
- package/build-backend/lib/adminCommonSocket.js.map +1 -0
- package/build-backend/lib/alexaCustom.js +542 -0
- package/build-backend/lib/alexaCustom.js.map +1 -0
- package/build-backend/lib/alexaSmartHomeV2.js +2788 -0
- package/build-backend/lib/alexaSmartHomeV3.js +97 -0
- package/build-backend/lib/alexaSmartHomeV3.js.map +1 -0
- package/build-backend/lib/alisa.js +2409 -0
- package/build-backend/lib/devices.js +23 -0
- package/build-backend/lib/devices.js.map +1 -0
- package/build-backend/lib/functions.js +24 -0
- package/build-backend/lib/functions.js.map +1 -0
- package/build-backend/lib/googleHome.js +3322 -0
- package/build-backend/lib/notifications.js +30 -0
- package/build-backend/lib/notifications.js.map +1 -0
- package/build-backend/lib/remote.js +1342 -0
- package/build-backend/lib/remote.js.map +1 -0
- package/build-backend/lib/rooms.js +48 -0
- package/build-backend/lib/rooms.js.map +1 -0
- package/build-backend/lib/texts.js +81 -0
- package/build-backend/lib/texts.js.map +1 -0
- package/build-backend/lib/translate.js +21 -0
- package/build-backend/lib/translate.js.map +1 -0
- package/build-backend/lib/visuApp.js +147 -0
- package/build-backend/lib/visuApp.js.map +1 -0
- package/build-backend/main.js +1361 -0
- package/build-backend/main.js.map +1 -0
- package/io-package.json +2 -2
- package/package.json +2 -2
- package/admin/assets/index-Y479CE6x.js +0 -681
- package/admin/rules/assets/ActionVisu__mf_v__runtimeInit__mf_v__-DtUoI3FU.js +0 -5
- package/admin/rules/assets/bootstrap-Ba57tu25.js +0 -1
- package/admin/rules/assets/index-_Y2FN5EZ.js +0 -1152
|
@@ -0,0 +1,321 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const AlexaResponse_1 = __importDefault(require("../Alexa/AlexaResponse"));
|
|
7
|
+
const Utils_1 = require("../Helpers/Utils");
|
|
8
|
+
const Logger_1 = __importDefault(require("../Helpers/Logger"));
|
|
9
|
+
const AdapterProvider_1 = __importDefault(require("../Helpers/AdapterProvider"));
|
|
10
|
+
const PowerState_1 = __importDefault(require("../Alexa/Properties/PowerState"));
|
|
11
|
+
const DetectionState_1 = __importDefault(require("../Alexa/Properties/DetectionState"));
|
|
12
|
+
/**
|
|
13
|
+
* Represents the base functionality for a control in a smart device. A smart device has at least one control.
|
|
14
|
+
* The specific functionality, natively supported capabilities, etc. are defined in derived classes.
|
|
15
|
+
*/
|
|
16
|
+
class Control {
|
|
17
|
+
static stateKeys = [
|
|
18
|
+
'SET',
|
|
19
|
+
'ACTUAL',
|
|
20
|
+
'ON_SET',
|
|
21
|
+
'ON_ACTUAL',
|
|
22
|
+
'POWER',
|
|
23
|
+
'MODE',
|
|
24
|
+
'HUE',
|
|
25
|
+
'DIMMER',
|
|
26
|
+
'BRIGHTNESS',
|
|
27
|
+
'SATURATION',
|
|
28
|
+
'TEMPERATURE',
|
|
29
|
+
'ON',
|
|
30
|
+
'MUTE',
|
|
31
|
+
];
|
|
32
|
+
log;
|
|
33
|
+
_supported;
|
|
34
|
+
_enforced;
|
|
35
|
+
_states = {};
|
|
36
|
+
/**
|
|
37
|
+
* @param detectedControl - The detected control in terms of iobroker type detector.
|
|
38
|
+
*/
|
|
39
|
+
constructor(detectedControl) {
|
|
40
|
+
this.initStates(detectedControl);
|
|
41
|
+
this._supported = this.initCapabilities();
|
|
42
|
+
this._enforced = this.initEnforcedCapabilities();
|
|
43
|
+
this.log = new Logger_1.default(this);
|
|
44
|
+
this.log.silly(`created instance`);
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* This function maps a passed on control to an array of objects. Each object contains an Alexa capability the control natively supports
|
|
48
|
+
* and at least one property. Every property is initialized with corresponding iobroker state ids and value converters from Alexa to iobroker types
|
|
49
|
+
* and vice versa.
|
|
50
|
+
*
|
|
51
|
+
* @returns Array of objects with natively supported Alexa capabilities and correspondingly configured instances of StateProxies
|
|
52
|
+
*/
|
|
53
|
+
initCapabilities() {
|
|
54
|
+
return [];
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* This function maps a passed on control to an array of objects. Each object contains an Alexa capability the control can handle even
|
|
58
|
+
* though not natively supported (e.g., the light control can handle the Alexa BrightnessController directive by switching
|
|
59
|
+
* itself `ON` on brightness > 0 and `OFF` on brightness == 0)
|
|
60
|
+
* Every capability has at least one property with set up iobroker state ids and value converters from Alexa to iobroker types
|
|
61
|
+
* and vice versa.
|
|
62
|
+
*
|
|
63
|
+
* @returns Array of objects with natively supported Alexa capabilities and correspondingly configured instances of StateProxies
|
|
64
|
+
*/
|
|
65
|
+
initEnforcedCapabilities() {
|
|
66
|
+
return [];
|
|
67
|
+
}
|
|
68
|
+
get allCapabilities() {
|
|
69
|
+
return this.supported.concat(this.enforced);
|
|
70
|
+
}
|
|
71
|
+
static get type() {
|
|
72
|
+
return (0, Utils_1.firstLower)((0, Utils_1.className)(this.toString()));
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Getter for Alexa categories
|
|
76
|
+
*/
|
|
77
|
+
get categories() {
|
|
78
|
+
return ['OTHER'];
|
|
79
|
+
}
|
|
80
|
+
get name() {
|
|
81
|
+
return `${this.constructor.name}`;
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Getter for _supported
|
|
85
|
+
*/
|
|
86
|
+
get supported() {
|
|
87
|
+
return this._supported;
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Getter for _enforced
|
|
91
|
+
*/
|
|
92
|
+
get enforced() {
|
|
93
|
+
return this._enforced;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* This function returns whether the control natively supports the passed on Alexa directive.
|
|
97
|
+
*
|
|
98
|
+
* @param event The event containing the Alexa directive as it comes from AWS Alexa Service
|
|
99
|
+
* @returns True if the control natively supports the directive, false - otherwise
|
|
100
|
+
*/
|
|
101
|
+
supports(event) {
|
|
102
|
+
return this.supported.find(capability => capability.matches(event)) !== undefined;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* This function returns whether the control though doesn't natively support the passed on Alexa directive, but able to handle it.
|
|
106
|
+
*
|
|
107
|
+
* @param event The event containing the Alexa directive as it comes from AWS Alexa Service
|
|
108
|
+
* @returns True if the control can handle the directive, false - otherwise
|
|
109
|
+
*/
|
|
110
|
+
canHandle(event) {
|
|
111
|
+
return this.enforced.find(capability => capability.matches(event)) !== undefined;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* This function processes an Alexa directive. Usually the result of the processing is setting an iobroker state to some value
|
|
115
|
+
* as a reaction to an interaction with Alexa via voice, app, etc.
|
|
116
|
+
*
|
|
117
|
+
* @param event The event containing the Alexa directive as it comes from AWS Alexa Service
|
|
118
|
+
* @returns Object containing the response to be sent to Alexa Service
|
|
119
|
+
*/
|
|
120
|
+
async handle(event) {
|
|
121
|
+
this.log.debug(`handling Alexa event`);
|
|
122
|
+
this.log.silly(`${JSON.stringify(event)}`);
|
|
123
|
+
const property = this.allCapabilities
|
|
124
|
+
.flatMap(item => item.properties)
|
|
125
|
+
.find(property => property.matches(event));
|
|
126
|
+
if (property) {
|
|
127
|
+
let alexaValue;
|
|
128
|
+
try {
|
|
129
|
+
const setter = this.valueSetter(event);
|
|
130
|
+
alexaValue = await setter(event, property);
|
|
131
|
+
}
|
|
132
|
+
catch (error) {
|
|
133
|
+
this.log.debug(`${error}`);
|
|
134
|
+
this.log.error(`failed handling Alexa event`);
|
|
135
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
136
|
+
return Promise.reject(AlexaResponse_1.default.endpointUnreachable(event.directive.header.messageId).get());
|
|
137
|
+
}
|
|
138
|
+
// even though the handler successfully processed the Alexa event,
|
|
139
|
+
// we return an error here for ENFORCED capabilities, to prevent
|
|
140
|
+
// reporting multiple successes for the same capability and
|
|
141
|
+
// running into a situation of returning a wrong value back to Alexa
|
|
142
|
+
if (this.enforced.find(capability => capability.matches(event))) {
|
|
143
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
144
|
+
return Promise.reject(AlexaResponse_1.default.directiveNotSupportedByControl(this.name, event?.directive?.header?.namespace, event?.directive?.header?.messageId, event?.directive?.header?.payloadVersion).get());
|
|
145
|
+
}
|
|
146
|
+
const response = AlexaResponse_1.default.handled(event, property.propertyName, property.reportValue(alexaValue), property.instance);
|
|
147
|
+
// though the processed directive required to change a single value, the response must contain values of all "relevant" properties
|
|
148
|
+
// Please refer to this for details: https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-thermostatcontroller.html#settargettemperature-response-event
|
|
149
|
+
// TODO: add values of relevant properties to response
|
|
150
|
+
this.log.silly(`${JSON.stringify(response.get())}`);
|
|
151
|
+
return response.get();
|
|
152
|
+
}
|
|
153
|
+
const errorResponse = AlexaResponse_1.default.directiveNotSupportedByControl(this.name, event?.directive?.header?.namespace, event?.directive?.header?.messageId, event?.directive?.header?.payloadVersion);
|
|
154
|
+
this.log.silly(`${JSON.stringify(errorResponse.get())}`);
|
|
155
|
+
// eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors
|
|
156
|
+
return Promise.reject(errorResponse.get());
|
|
157
|
+
}
|
|
158
|
+
valueSetter(_event) {
|
|
159
|
+
return this.setValue.bind(this);
|
|
160
|
+
}
|
|
161
|
+
async setValue(event, property) {
|
|
162
|
+
// extract alexa value from event
|
|
163
|
+
const alexaValue = property.alexaDirectiveValue(event);
|
|
164
|
+
// convert alexa value to iobroker value
|
|
165
|
+
let value = property.value(alexaValue);
|
|
166
|
+
// if set, the device could support toggle
|
|
167
|
+
if (event.currentState) {
|
|
168
|
+
// console.error(`----------------------------------- command: ${value}, current value: ${JSON.stringify(event.currentState)}`);
|
|
169
|
+
const state = event.currentState.find(item => item.name === property.propertyName);
|
|
170
|
+
if (state && value === true) {
|
|
171
|
+
// it could support toggle.
|
|
172
|
+
// get current value
|
|
173
|
+
const current = property.value(state.value);
|
|
174
|
+
if (current === true) {
|
|
175
|
+
// turn off
|
|
176
|
+
value = false;
|
|
177
|
+
}
|
|
178
|
+
else if (current !== false) {
|
|
179
|
+
const currentValue = await this.getOrRetrieveCurrentValue(property);
|
|
180
|
+
if (currentValue === true) {
|
|
181
|
+
// turn off
|
|
182
|
+
value = false;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
// set iobroker state
|
|
188
|
+
await this.setState(property, value);
|
|
189
|
+
property.currentValue = value;
|
|
190
|
+
// return value as expected by Alexa
|
|
191
|
+
return property.alexaValue(value);
|
|
192
|
+
}
|
|
193
|
+
async adjustValue(event, property) {
|
|
194
|
+
// extract Alexa delta value from event
|
|
195
|
+
const delta = property.alexaDirectiveValue(event);
|
|
196
|
+
// get current value
|
|
197
|
+
const currentValue = await this.getOrRetrieveCurrentValue(property);
|
|
198
|
+
// convert the current value to Alexa value
|
|
199
|
+
const valueToAdjust = property.alexaValue(currentValue);
|
|
200
|
+
// adjust Alexa value
|
|
201
|
+
const adjustedValue = (0, Utils_1.ensureValueInRange_0_100)(parseFloat(valueToAdjust || '0') + parseFloat(delta || '0'));
|
|
202
|
+
// convert adjusted value to iobroker value
|
|
203
|
+
const value = property.value(adjustedValue);
|
|
204
|
+
// set iobroker state
|
|
205
|
+
await this.setState(property, value);
|
|
206
|
+
return adjustedValue;
|
|
207
|
+
}
|
|
208
|
+
async getOrRetrieveCurrentValue(property) {
|
|
209
|
+
if (property.currentValue === undefined) {
|
|
210
|
+
property.currentValue = await AdapterProvider_1.default.getState(property.getId);
|
|
211
|
+
}
|
|
212
|
+
if (property.currentValue === undefined) {
|
|
213
|
+
throw new Error(`unable to retrieve ${property.getId}`);
|
|
214
|
+
}
|
|
215
|
+
return property.currentValue;
|
|
216
|
+
}
|
|
217
|
+
async reportState() {
|
|
218
|
+
this.log.debug(`reporting state`);
|
|
219
|
+
const propertiesToReport = [];
|
|
220
|
+
for (const capability of this.supported) {
|
|
221
|
+
for (const property of capability.properties) {
|
|
222
|
+
try {
|
|
223
|
+
await this.getOrRetrieveCurrentValue(property);
|
|
224
|
+
const toReport = {
|
|
225
|
+
namespace: capability.namespace,
|
|
226
|
+
instance: property.instance,
|
|
227
|
+
name: property.propertyName,
|
|
228
|
+
value: property.reportValue(property.alexaValue(property.currentValue)),
|
|
229
|
+
};
|
|
230
|
+
if (!toReport.instance) {
|
|
231
|
+
delete toReport.instance;
|
|
232
|
+
}
|
|
233
|
+
propertiesToReport.push(toReport);
|
|
234
|
+
}
|
|
235
|
+
catch (error) {
|
|
236
|
+
this.log.error(`failed reporting state for property ${property.propertyName} of ${this.name}`);
|
|
237
|
+
this.log.debug(`${error}`);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
this.log.debug(`${JSON.stringify(propertiesToReport)}`);
|
|
242
|
+
return propertiesToReport;
|
|
243
|
+
}
|
|
244
|
+
toString() {
|
|
245
|
+
return `${this.constructor.name}`;
|
|
246
|
+
}
|
|
247
|
+
initStates(ctrl) {
|
|
248
|
+
for (const stateKey of Control.stateKeys) {
|
|
249
|
+
this._states[stateKey] = ctrl.states.find(s => s.name === stateKey);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
get states() {
|
|
253
|
+
return this._states;
|
|
254
|
+
}
|
|
255
|
+
get statesMap() {
|
|
256
|
+
const map = {};
|
|
257
|
+
for (const stateKey of Control.stateKeys) {
|
|
258
|
+
map[stateKey.toLowerCase()] = stateKey;
|
|
259
|
+
}
|
|
260
|
+
return map;
|
|
261
|
+
}
|
|
262
|
+
async setState(property, value) {
|
|
263
|
+
await AdapterProvider_1.default.setState(property.setId, value);
|
|
264
|
+
property.currentValue = value;
|
|
265
|
+
}
|
|
266
|
+
//-------------------------------------------------------
|
|
267
|
+
// standard property init objects
|
|
268
|
+
//
|
|
269
|
+
blankInitObject() {
|
|
270
|
+
// const states = this.initStates(ctrl);
|
|
271
|
+
const map = this.statesMap;
|
|
272
|
+
return {
|
|
273
|
+
setState: this.states[map.actual],
|
|
274
|
+
getState: this.states[map.actual],
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
powerStateInitObject() {
|
|
278
|
+
// const states = this.initStates(ctrl);
|
|
279
|
+
const map = this.statesMap;
|
|
280
|
+
return {
|
|
281
|
+
setState: this.states[map.set],
|
|
282
|
+
getState: this.states[map.actual],
|
|
283
|
+
alexaSetter: function (alexaValue) {
|
|
284
|
+
return alexaValue === PowerState_1.default.ON;
|
|
285
|
+
},
|
|
286
|
+
alexaGetter: function (value) {
|
|
287
|
+
return value ? PowerState_1.default.ON : PowerState_1.default.OFF;
|
|
288
|
+
},
|
|
289
|
+
};
|
|
290
|
+
}
|
|
291
|
+
detectedStateInitObject() {
|
|
292
|
+
const map = this.statesMap;
|
|
293
|
+
return {
|
|
294
|
+
setState: this.states[map.actual],
|
|
295
|
+
getState: this.states[map.actual],
|
|
296
|
+
alexaSetter: function (_alexaValue) {
|
|
297
|
+
// should be never called
|
|
298
|
+
return 0;
|
|
299
|
+
},
|
|
300
|
+
alexaGetter: function (value) {
|
|
301
|
+
return value ? DetectionState_1.default.DETECTED : DetectionState_1.default.NOT_DETECTED;
|
|
302
|
+
},
|
|
303
|
+
};
|
|
304
|
+
}
|
|
305
|
+
percentageInitObject() {
|
|
306
|
+
const map = this.statesMap;
|
|
307
|
+
// const range = configuredRangeOrDefault(this.states[map.set]);
|
|
308
|
+
return {
|
|
309
|
+
setState: this.states[map.set],
|
|
310
|
+
getState: this.states[map.actual],
|
|
311
|
+
alexaSetter: function (alexaValue) {
|
|
312
|
+
return ((0, Utils_1.denormalize_0_100)(alexaValue, this.valuesRangeMin, this.valuesRangeMax) || 0);
|
|
313
|
+
},
|
|
314
|
+
alexaGetter: function (value) {
|
|
315
|
+
return (0, Utils_1.normalize_0_100)(value, this.valuesRangeMin, this.valuesRangeMax);
|
|
316
|
+
},
|
|
317
|
+
};
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
exports.default = Control;
|
|
321
|
+
//# sourceMappingURL=Control.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Control.js","sourceRoot":"","sources":["../../../../src/lib/AlexaSmartHomeV3/Controls/Control.ts"],"names":[],"mappings":";;;;;AAAA,2EAAmD;AACnD,4CAAuH;AACvH,+DAAuC;AACvC,iFAAyD;AAEzD,gFAAwD;AACxD,wFAAgE;AAWhE;;;GAGG;AACH,MAAqB,OAAO;IACxB,MAAM,CAAC,SAAS,GAAG;QACf,KAAK;QACL,QAAQ;QACR,QAAQ;QACR,WAAW;QACX,OAAO;QACP,MAAM;QACN,KAAK;QACL,QAAQ;QACR,YAAY;QACZ,YAAY;QACZ,aAAa;QACb,IAAI;QACJ,MAAM;KACT,CAAC;IACc,GAAG,CAAS;IACZ,UAAU,CAAqB;IAC/B,SAAS,CAAqB;IAC9B,OAAO,GAAyD,EAAE,CAAC;IAEnF;;OAEG;IACH,YAAY,eAA0C;QAClD,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,CAAC;QACjC,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC1C,IAAI,CAAC,SAAS,GAAG,IAAI,CAAC,wBAAwB,EAAE,CAAC;QACjD,IAAI,CAAC,GAAG,GAAG,IA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,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAE;YAClC,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAE;YAClC,WAAW,EAAE,UAAU,WAAkC;gBACrD,yBAAyB;gBACzB,OAAO,CAAC,CAAC;YACb,CAAC;YACD,WAAW,EAAE,UAAU,KAAsC;gBACzD,OAAO,KAAK,CAAC,CAAC,CAAC,wBAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,wBAAc,CAAC,YAAY,CAAC;YACzE,CAAC;SACJ,CAAC;IACN,CAAC;IAED,oBAAoB;QAChB,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC;QAC3B,gEAAgE;QAChE,OAAO;YACH,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,CAAE;YAC/B,QAAQ,EAAE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAE;YAClC,WAAW,EAAE,UAAgC,UAAiC;gBAC1E,OAAO,CACH,IAAA,yBAAiB,EACb,UAAoB,EACpB,IAAI,CAAC,cAAwB,EAC7B,IAAI,CAAC,cAAwB,CAChC,IAAI,CAAC,CACT,CAAC;YACN,CAAC;YACD,WAAW,EAAE,UAET,KAAsC;gBAEtC,OAAO,IAAA,uBAAe,EAAC,KAAe,EAAE,IAAI,CAAC,cAAwB,EAAE,IAAI,CAAC,cAAwB,CAAC,CAAC;YAC1G,CAAC;SACJ,CAAC;IACN,CAAC;;AApXL,0BAqXC","sourcesContent":["import AlexaResponse from '../Alexa/AlexaResponse';\nimport { firstLower, className, ensureValueInRange_0_100, denormalize_0_100, normalize_0_100 } from '../Helpers/Utils';\nimport Logger from '../Helpers/Logger';\nimport AdapterProvider from '../Helpers/AdapterProvider';\nimport type { ControlStateInitObject, Base as PropertiesBase } from '../Alexa/Properties/Base';\nimport PowerState from '../Alexa/Properties/PowerState';\nimport DetectionState from '../Alexa/Properties/DetectionState';\nimport type {\n AlexaV3Category,\n AlexaV3DirectiveValue,\n AlexaV3ReportedState,\n AlexaV3Request,\n IotExternalDetectorState,\n IotExternalPatternControl,\n} from '../types';\nimport type { Base as CapabilitiesBase } from '../Alexa/Capabilities/Base';\n\n/**\n * Represents the base functionality for a control in a smart device. A smart device has at least one control.\n * The specific functionality, natively supported capabilities, etc. are defined in derived classes.\n */\nexport default class Control {\n static stateKeys = [\n 'SET',\n 'ACTUAL',\n 'ON_SET',\n 'ON_ACTUAL',\n 'POWER',\n 'MODE',\n 'HUE',\n 'DIMMER',\n 'BRIGHTNESS',\n 'SATURATION',\n 'TEMPERATURE',\n 'ON',\n 'MUTE',\n ];\n public readonly log: Logger;\n public readonly _supported: CapabilitiesBase[];\n public readonly _enforced: CapabilitiesBase[];\n public readonly _states: Record<string, IotExternalDetectorState | undefined> = {};\n\n /**\n * @param detectedControl - The detected control in terms of iobroker type detector.\n */\n constructor(detectedControl: IotExternalPatternControl) {\n this.initStates(detectedControl);\n this._supported = this.initCapabilities();\n this._enforced = this.initEnforcedCapabilities();\n this.log = new Logger(this);\n this.log.silly(`created instance`);\n }\n /**\n * This function maps a passed on control to an array of objects. Each object contains an Alexa capability the control natively supports\n * and at least one property. Every property is initialized with corresponding iobroker state ids and value converters from Alexa to iobroker types\n * and vice versa.\n *\n * @returns Array of objects with natively supported Alexa capabilities and correspondingly configured instances of StateProxies\n */\n initCapabilities(): CapabilitiesBase[] {\n return [];\n }\n /**\n * This function maps a passed on control to an array of objects. Each object contains an Alexa capability the control can handle even\n * though not natively supported (e.g., the light control can handle the Alexa BrightnessController directive by switching\n * itself `ON` on brightness > 0 and `OFF` on brightness == 0)\n * Every capability has at least one property with set up iobroker state ids and value converters from Alexa to iobroker types\n * and vice versa.\n *\n * @returns Array of objects with natively supported Alexa capabilities and correspondingly configured instances of StateProxies\n */\n initEnforcedCapabilities(): CapabilitiesBase[] {\n return [];\n }\n\n get allCapabilities(): CapabilitiesBase[] {\n return this.supported.concat(this.enforced);\n }\n\n static get type(): string {\n return firstLower(className(this.toString()));\n }\n /**\n * Getter for Alexa categories\n */\n get categories(): AlexaV3Category[] {\n return ['OTHER'];\n }\n\n get name(): string {\n return `${this.constructor.name}`;\n }\n /**\n * Getter for _supported\n */\n get supported(): CapabilitiesBase[] {\n return this._supported;\n }\n /**\n * Getter for _enforced\n */\n get enforced(): CapabilitiesBase[] {\n return this._enforced;\n }\n /**\n * This function returns whether the control natively supports the passed on Alexa directive.\n *\n * @param event The event containing the Alexa directive as it comes from AWS Alexa Service\n * @returns True if the control natively supports the directive, false - otherwise\n */\n supports(event: AlexaV3Request): boolean {\n return this.supported.find(capability => capability.matches(event)) !== undefined;\n }\n /**\n * This function returns whether the control though doesn't natively support the passed on Alexa directive, but able to handle it.\n *\n * @param event The event containing the Alexa directive as it comes from AWS Alexa Service\n * @returns True if the control can handle the directive, false - otherwise\n */\n canHandle(event: AlexaV3Request): boolean {\n return this.enforced.find(capability => capability.matches(event)) !== undefined;\n }\n /**\n * This function processes an Alexa directive. Usually the result of the processing is setting an iobroker state to some value\n * as a reaction to an interaction with Alexa via voice, app, etc.\n *\n * @param event The event containing the Alexa directive as it comes from AWS Alexa Service\n * @returns Object containing the response to be sent to Alexa Service\n */\n async handle(event: AlexaV3Request): Promise<AlexaResponse> {\n this.log.debug(`handling Alexa event`);\n this.log.silly(`${JSON.stringify(event)}`);\n\n const property = this.allCapabilities\n .flatMap(item => item.properties)\n .find(property => property.matches(event));\n\n if (property) {\n let alexaValue: AlexaV3DirectiveValue;\n try {\n const setter = this.valueSetter(event);\n alexaValue = await setter(event, property);\n } catch (error) {\n this.log.debug(`${error}`);\n this.log.error(`failed handling Alexa event`);\n\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n return Promise.reject(AlexaResponse.endpointUnreachable(event.directive.header.messageId).get());\n }\n\n // even though the handler successfully processed the Alexa event,\n // we return an error here for ENFORCED capabilities, to prevent\n // reporting multiple successes for the same capability and\n // running into a situation of returning a wrong value back to Alexa\n if (this.enforced.find(capability => capability.matches(event))) {\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n return Promise.reject(\n AlexaResponse.directiveNotSupportedByControl(\n this.name,\n event?.directive?.header?.namespace,\n event?.directive?.header?.messageId,\n event?.directive?.header?.payloadVersion,\n ).get(),\n );\n }\n\n const response = AlexaResponse.handled(\n event,\n property.propertyName,\n property.reportValue(alexaValue),\n property.instance,\n );\n\n // though the processed directive required to change a single value, the response must contain values of all \"relevant\" properties\n // Please refer to this for details: https://developer.amazon.com/en-US/docs/alexa/device-apis/alexa-thermostatcontroller.html#settargettemperature-response-event\n\n // TODO: add values of relevant properties to response\n\n this.log.silly(`${JSON.stringify(response.get())}`);\n return response.get();\n }\n\n const errorResponse = AlexaResponse.directiveNotSupportedByControl(\n this.name,\n event?.directive?.header?.namespace,\n event?.directive?.header?.messageId,\n event?.directive?.header?.payloadVersion,\n );\n this.log.silly(`${JSON.stringify(errorResponse.get())}`);\n // eslint-disable-next-line @typescript-eslint/prefer-promise-reject-errors\n return Promise.reject(errorResponse.get());\n }\n\n valueSetter(\n _event: AlexaV3Request,\n ): (event: AlexaV3Request, property: PropertiesBase) => Promise<AlexaV3DirectiveValue> {\n return this.setValue.bind(this);\n }\n\n async setValue(event: AlexaV3Request, property: PropertiesBase): Promise<AlexaV3DirectiveValue> {\n // extract alexa value from event\n const alexaValue = property.alexaDirectiveValue(event);\n\n // convert alexa value to iobroker value\n let value = property.value(alexaValue);\n\n // if set, the device could support toggle\n if (event.currentState) {\n // console.error(`----------------------------------- command: ${value}, current value: ${JSON.stringify(event.currentState)}`);\n const state = event.currentState.find(item => item.name === property.propertyName);\n if (state && value === true) {\n // it could support toggle.\n // get current value\n const current = property.value(state.value);\n if (current === true) {\n // turn off\n value = false;\n } else if (current !== false) {\n const currentValue = await this.getOrRetrieveCurrentValue(property);\n if (currentValue === true) {\n // turn off\n value = false;\n }\n }\n }\n }\n\n // set iobroker state\n await this.setState(property, value!);\n\n property.currentValue = value;\n // return value as expected by Alexa\n return property.alexaValue(value);\n }\n\n async adjustValue(event: AlexaV3Request, property: PropertiesBase): Promise<AlexaV3DirectiveValue> {\n // extract Alexa delta value from event\n const delta = property.alexaDirectiveValue(event);\n // get current value\n const currentValue = await this.getOrRetrieveCurrentValue(property);\n // convert the current value to Alexa value\n const valueToAdjust = property.alexaValue(currentValue);\n // adjust Alexa value\n const adjustedValue = ensureValueInRange_0_100(\n parseFloat((valueToAdjust as string) || '0') + parseFloat((delta as string) || '0'),\n );\n // convert adjusted value to iobroker value\n const value = property.value(adjustedValue);\n\n // set iobroker state\n await this.setState(property, value as ioBroker.StateValue);\n\n return adjustedValue;\n }\n\n async getOrRetrieveCurrentValue(property: PropertiesBase): Promise<ioBroker.StateValue> {\n if (property.currentValue === undefined) {\n property.currentValue = await AdapterProvider.getState(property.getId);\n }\n\n if (property.currentValue === undefined) {\n throw new Error(`unable to retrieve ${property.getId}`);\n }\n\n return property.currentValue;\n }\n\n async reportState(): Promise<AlexaV3ReportedState[]> {\n this.log.debug(`reporting state`);\n\n const propertiesToReport: AlexaV3ReportedState[] = [];\n\n for (const capability of this.supported) {\n for (const property of capability.properties) {\n try {\n await this.getOrRetrieveCurrentValue(property);\n\n const toReport: AlexaV3ReportedState = {\n namespace: capability.namespace,\n instance: property.instance,\n name: property.propertyName,\n value: property.reportValue(property.alexaValue(property.currentValue)),\n };\n\n if (!toReport.instance) {\n delete toReport.instance;\n }\n\n propertiesToReport.push(toReport);\n } catch (error) {\n this.log.error(`failed reporting state for property ${property.propertyName} of ${this.name}`);\n this.log.debug(`${error}`);\n }\n }\n }\n\n this.log.debug(`${JSON.stringify(propertiesToReport)}`);\n return propertiesToReport;\n }\n\n toString(): string {\n return `${this.constructor.name}`;\n }\n\n initStates(ctrl: IotExternalPatternControl): void {\n for (const stateKey of Control.stateKeys) {\n this._states[stateKey] = ctrl.states.find(s => s.name === stateKey);\n }\n }\n\n get states(): Record<string, IotExternalDetectorState | undefined> {\n return this._states;\n }\n\n get statesMap(): Record<string, string> {\n const map: Record<string, string> = {};\n for (const stateKey of Control.stateKeys) {\n map[stateKey.toLowerCase()] = stateKey;\n }\n return map;\n }\n\n async setState(property: PropertiesBase, value: ioBroker.StateValue): Promise<void> {\n await AdapterProvider.setState(property.setId, value);\n property.currentValue = value;\n }\n\n //-------------------------------------------------------\n // standard property init objects\n //\n\n blankInitObject(): ControlStateInitObject {\n // const states = this.initStates(ctrl);\n const map = this.statesMap;\n return {\n setState: this.states[map.actual]!,\n getState: this.states[map.actual]!,\n };\n }\n\n powerStateInitObject(): ControlStateInitObject {\n // const states = this.initStates(ctrl);\n const map = this.statesMap;\n\n return {\n setState: this.states[map.set]!,\n getState: this.states[map.actual]!,\n alexaSetter: function (alexaValue) {\n return alexaValue === PowerState.ON;\n },\n alexaGetter: function (value) {\n return value ? PowerState.ON : PowerState.OFF;\n },\n };\n }\n\n detectedStateInitObject(): ControlStateInitObject {\n const map = this.statesMap;\n return {\n setState: this.states[map.actual]!,\n getState: this.states[map.actual]!,\n alexaSetter: function (_alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue | undefined {\n // should be never called\n return 0;\n },\n alexaGetter: function (value: ioBroker.StateValue | undefined): AlexaV3DirectiveValue {\n return value ? DetectionState.DETECTED : DetectionState.NOT_DETECTED;\n },\n };\n }\n\n percentageInitObject(): ControlStateInitObject {\n const map = this.statesMap;\n // const range = configuredRangeOrDefault(this.states[map.set]);\n return {\n setState: this.states[map.set]!,\n getState: this.states[map.actual]!,\n alexaSetter: function (this: PropertiesBase, alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue {\n return (\n denormalize_0_100(\n alexaValue as number,\n this.valuesRangeMin as number,\n this.valuesRangeMax as number,\n ) || 0\n );\n },\n alexaGetter: function (\n this: PropertiesBase,\n value: ioBroker.StateValue | undefined,\n ): AlexaV3DirectiveValue {\n return normalize_0_100(value as number, this.valuesRangeMin as number, this.valuesRangeMax as number);\n },\n };\n }\n}\n"]}
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const Capabilities_1 = __importDefault(require("../Alexa/Capabilities"));
|
|
7
|
+
const Utils_1 = require("../Helpers/Utils");
|
|
8
|
+
const AdapterProvider_1 = __importDefault(require("../Helpers/AdapterProvider"));
|
|
9
|
+
const AdjustableControl_1 = __importDefault(require("./AdjustableControl"));
|
|
10
|
+
const Brightness_1 = __importDefault(require("../Alexa/Properties/Brightness"));
|
|
11
|
+
const ColorTemperatureInKelvin_1 = __importDefault(require("../Alexa/Properties/ColorTemperatureInKelvin"));
|
|
12
|
+
const PowerState_1 = __importDefault(require("../Alexa/Properties/PowerState"));
|
|
13
|
+
class Ct extends AdjustableControl_1.default {
|
|
14
|
+
_brightnessCapability;
|
|
15
|
+
_brightness;
|
|
16
|
+
_colorTemperatureCapability;
|
|
17
|
+
_powerControllerCapability;
|
|
18
|
+
_powerState;
|
|
19
|
+
get categories() {
|
|
20
|
+
return ['LIGHT'];
|
|
21
|
+
}
|
|
22
|
+
adjustableProperties() {
|
|
23
|
+
return [ColorTemperatureInKelvin_1.default];
|
|
24
|
+
}
|
|
25
|
+
initCapabilities() {
|
|
26
|
+
const map = this.statesMap;
|
|
27
|
+
const result = [new Capabilities_1.default.ColorController()];
|
|
28
|
+
// if the state DIMMER or BRIGHTNESS configured
|
|
29
|
+
if (this.states[map.dimmer] || this.states[map.brightness]) {
|
|
30
|
+
this._brightnessCapability = new Capabilities_1.default.BrightnessController();
|
|
31
|
+
this._brightness = this._brightnessCapability.brightness;
|
|
32
|
+
result.push(this._brightnessCapability);
|
|
33
|
+
}
|
|
34
|
+
// if the state TEMPERATURE configured
|
|
35
|
+
if (this.states[map.temperature]) {
|
|
36
|
+
this._colorTemperatureCapability = new Capabilities_1.default.ColorTemperatureController();
|
|
37
|
+
result.push(this._colorTemperatureCapability);
|
|
38
|
+
}
|
|
39
|
+
// if the state ON, DIMMER or BRIGHTNESS configured
|
|
40
|
+
if (this.states[map.on] || this._brightness) {
|
|
41
|
+
this._powerControllerCapability = new Capabilities_1.default.PowerController();
|
|
42
|
+
this._powerState = this._powerControllerCapability.powerState;
|
|
43
|
+
result.push(this._powerControllerCapability);
|
|
44
|
+
}
|
|
45
|
+
for (const property of result.flatMap(item => item.properties)) {
|
|
46
|
+
const initObject = this.composeInitObject(property);
|
|
47
|
+
if (initObject) {
|
|
48
|
+
property.init(initObject);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
return result;
|
|
52
|
+
}
|
|
53
|
+
async getOrRetrieveCurrentValue(property) {
|
|
54
|
+
const map = this.statesMap;
|
|
55
|
+
if (property.currentValue === undefined) {
|
|
56
|
+
property.currentValue = await AdapterProvider_1.default.getState(property.getId);
|
|
57
|
+
// convert the non-zero brightness to power = true
|
|
58
|
+
if (property.propertyName === PowerState_1.default.propertyName && !this.states[map.on]) {
|
|
59
|
+
property.currentValue = property.currentValue !== 0;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
if (property.currentValue === undefined) {
|
|
63
|
+
throw new Error(`unable to retrieve ${property.getId}`);
|
|
64
|
+
}
|
|
65
|
+
return property.currentValue;
|
|
66
|
+
}
|
|
67
|
+
async setState(property, value) {
|
|
68
|
+
const map = this.statesMap;
|
|
69
|
+
if (property.propertyName === PowerState_1.default.propertyName) {
|
|
70
|
+
if (this.states[map.on]) {
|
|
71
|
+
await AdapterProvider_1.default.setState(property.setId, value);
|
|
72
|
+
property.currentValue = value;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
if (!this._brightness) {
|
|
76
|
+
throw new Error('No brightness property configured');
|
|
77
|
+
}
|
|
78
|
+
if (!this._powerState) {
|
|
79
|
+
throw new Error('No powerState property configured');
|
|
80
|
+
}
|
|
81
|
+
if (value) {
|
|
82
|
+
// set brightness
|
|
83
|
+
// set byOn to the configured value or range.max otherwise
|
|
84
|
+
const range = (0, Utils_1.configuredRangeOrDefault)(this.states[map.dimmer] || this.states[map.brightness]);
|
|
85
|
+
const smartName = (this.states[map.dimmer] || this.states[map.brightness])?.smartName;
|
|
86
|
+
let byOn;
|
|
87
|
+
if (smartName && typeof smartName === 'object') {
|
|
88
|
+
byOn = smartName.byON;
|
|
89
|
+
}
|
|
90
|
+
else {
|
|
91
|
+
byOn = undefined;
|
|
92
|
+
}
|
|
93
|
+
if (byOn === undefined || byOn === null || isNaN(byOn)) {
|
|
94
|
+
byOn = range.max;
|
|
95
|
+
}
|
|
96
|
+
else {
|
|
97
|
+
byOn = parseFloat(byOn);
|
|
98
|
+
}
|
|
99
|
+
await AdapterProvider_1.default.setState(this._brightness.setId, byOn ?? 100);
|
|
100
|
+
this._brightness.currentValue = byOn;
|
|
101
|
+
this._powerState.currentValue = true;
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
// set brightness to 0 on power OFF
|
|
105
|
+
await AdapterProvider_1.default.setState(this._brightness.setId, 0);
|
|
106
|
+
this._brightness.currentValue = 0;
|
|
107
|
+
this._powerState.currentValue = false;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
else if (property.propertyName === Brightness_1.default.propertyName ||
|
|
112
|
+
property.propertyName === ColorTemperatureInKelvin_1.default.propertyName) {
|
|
113
|
+
await AdapterProvider_1.default.setState(property.setId, value);
|
|
114
|
+
property.currentValue = value;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
async adjustValue(event, property) {
|
|
118
|
+
// extract Alexa delta value from event
|
|
119
|
+
const delta = property.alexaDirectiveValue(event);
|
|
120
|
+
// convert delta to iobroker value
|
|
121
|
+
const value = property.value(delta);
|
|
122
|
+
// set iobroker state
|
|
123
|
+
await this.setState(property, value ?? 0);
|
|
124
|
+
return value;
|
|
125
|
+
}
|
|
126
|
+
composeInitObject(property) {
|
|
127
|
+
const map = this.statesMap;
|
|
128
|
+
if (property.propertyName === PowerState_1.default.propertyName) {
|
|
129
|
+
return {
|
|
130
|
+
setState: this.states[map.on] || this.states[map.dimmer] || this.states[map.brightness],
|
|
131
|
+
getState: this.states[map.on] || this.states[map.dimmer] || this.states[map.brightness],
|
|
132
|
+
alexaSetter: function (alexaValue) {
|
|
133
|
+
return alexaValue === PowerState_1.default.ON;
|
|
134
|
+
},
|
|
135
|
+
alexaGetter: function (value) {
|
|
136
|
+
return value ? PowerState_1.default.ON : PowerState_1.default.OFF;
|
|
137
|
+
},
|
|
138
|
+
};
|
|
139
|
+
}
|
|
140
|
+
if (property.propertyName === Brightness_1.default.propertyName) {
|
|
141
|
+
return {
|
|
142
|
+
setState: this.states[map.dimmer] || this.states[map.brightness],
|
|
143
|
+
getState: this.states[map.dimmer] || this.states[map.brightness],
|
|
144
|
+
alexaSetter: function (alexaValue) {
|
|
145
|
+
return ((0, Utils_1.denormalize_0_100)(alexaValue, this.valuesRangeMin, this.valuesRangeMax) ?? 0);
|
|
146
|
+
},
|
|
147
|
+
alexaGetter: function (value) {
|
|
148
|
+
return (0, Utils_1.normalize_0_100)(value, this.valuesRangeMin, this.valuesRangeMax);
|
|
149
|
+
},
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
if (property.propertyName === ColorTemperatureInKelvin_1.default.propertyName) {
|
|
153
|
+
return {
|
|
154
|
+
setState: this.states[map.temperature],
|
|
155
|
+
getState: this.states[map.temperature],
|
|
156
|
+
alexaSetter: function (alexaValue) {
|
|
157
|
+
if (alexaValue === 1) {
|
|
158
|
+
// increase directive
|
|
159
|
+
const closest = (0, Utils_1.closestFromList)(this.currentValue || this.colorTemperatureTable[0], this.colorTemperatureTable);
|
|
160
|
+
let index = this.colorTemperatureTable.indexOf(closest) + 1;
|
|
161
|
+
index =
|
|
162
|
+
index >= this.colorTemperatureTable.length ? this.colorTemperatureTable.length - 1 : index;
|
|
163
|
+
return this.colorTemperatureTable[index];
|
|
164
|
+
}
|
|
165
|
+
if (alexaValue === -1) {
|
|
166
|
+
// decrease directive
|
|
167
|
+
const closest = (0, Utils_1.closestFromList)(this.currentValue || this.colorTemperatureTable[0], this.colorTemperatureTable);
|
|
168
|
+
let index = this.colorTemperatureTable.indexOf(closest) - 1;
|
|
169
|
+
index = index < 0 ? 0 : index;
|
|
170
|
+
return this.colorTemperatureTable[index];
|
|
171
|
+
}
|
|
172
|
+
return alexaValue;
|
|
173
|
+
},
|
|
174
|
+
alexaGetter: function (value) {
|
|
175
|
+
return value;
|
|
176
|
+
},
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
exports.default = Ct;
|
|
182
|
+
//# sourceMappingURL=Ct.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Ct.js","sourceRoot":"","sources":["../../../../src/lib/AlexaSmartHomeV3/Controls/Ct.ts"],"names":[],"mappings":";;;;;AAAA,yEAAiD;AACjD,4CAAiH;AACjH,iFAAyD;AACzD,4EAAoD;AAIpD,gFAAwD;AACxD,4GAAoF;AAGpF,gFAAwD;AAGxD,MAAqB,EAAG,SAAQ,2BAAiB;IACrC,qBAAqB,CAAmC;IACxD,WAAW,CAAyB;IACpC,2BAA2B,CAAyC;IACpE,0BAA0B,CAA8B;IACxD,WAAW,CAAyB;IAE5C,IAAI,UAAU;QACV,OAAO,CAAC,OAAO,CAAC,CAAC;IACrB,CAAC;IAED,oBAAoB;QAChB,OAAO,CAAC,kCAAwB,CAAC,CAAC;IACtC,CAAC;IAED,gBAAgB;QACZ,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC;QAC3B,MAAM,MAAM,GAAG,CAAC,IAAI,sBAAY,CAAC,eAAe,EAAE,CAAC,CAAC;QAEpD,+CAA+C;QAC/C,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,UAAU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I,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC,EAC9D,IAAI,CAAC,qBAAqB,CAC7B,CAAC;wBACF,IAAI,KAAK,GAAG,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;wBAC5D,KAAK;4BACD,KAAK,IAAI,IAAI,CAAC,qBAAqB,CAAC,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,qBAAqB,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;wBAC/F,OAAO,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;oBAC7C,CAAC;oBACD,IAAI,UAAU,KAAK,CAAC,CAAC,EAAE,CAAC;wBACpB,qBAAqB;wBACrB,MAAM,OAAO,GAAG,IAAA,uBAAe,EAC1B,IAAI,CAAC,YAAuB,IAAI,IAAI,CAAC,qBAAqB,CAAC,CAAC,CAAC,EAC9D,IAAI,CAAC,qBAAqB,CAC7B,CAAC;wBACF,IAAI,KAAK,GAAG,IAAI,CAAC,qBAAqB,CAAC,OAAO,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;wBAC5D,KAAK,GAAG,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;wBAC9B,OAAO,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC;oBAC7C,CAAC;oBAED,OAAO,UAAoB,CAAC;gBAChC,CAAC;gBACD,WAAW,EAAE,UAAU,KAAsC;oBACzD,OAAO,KAAe,CAAC;gBAC3B,CAAC;aACJ,CAAC;QACN,CAAC;IACL,CAAC;CACJ;AAzND,qBAyNC","sourcesContent":["import Capabilities from '../Alexa/Capabilities';\nimport { configuredRangeOrDefault, denormalize_0_100, normalize_0_100, closestFromList } from '../Helpers/Utils';\nimport AdapterProvider from '../Helpers/AdapterProvider';\nimport AdjustableControl from './AdjustableControl';\nimport type { Base as CapabilitiesBase } from '../Alexa/Capabilities/Base';\nimport type { Base as PropertiesBase } from '../Alexa/Properties/Base';\nimport type BrightnessController from '../Alexa/Capabilities/BrightnessController';\nimport Brightness from '../Alexa/Properties/Brightness';\nimport ColorTemperatureInKelvin from '../Alexa/Properties/ColorTemperatureInKelvin';\nimport type ColorTemperatureController from '../Alexa/Capabilities/ColorTemperatureController';\nimport type PowerController from '../Alexa/Capabilities/PowerController';\nimport PowerState from '../Alexa/Properties/PowerState';\nimport type { AlexaV3Category, AlexaV3DirectiveValue, AlexaV3Request, IotExternalDetectorState } from '../types';\n\nexport default class Ct extends AdjustableControl {\n private _brightnessCapability: BrightnessController | undefined;\n private _brightness: Brightness | undefined;\n private _colorTemperatureCapability: ColorTemperatureController | undefined;\n private _powerControllerCapability: PowerController | undefined;\n private _powerState: PowerState | undefined;\n\n get categories(): AlexaV3Category[] {\n return ['LIGHT'];\n }\n\n adjustableProperties(): (typeof PropertiesBase)[] {\n return [ColorTemperatureInKelvin];\n }\n\n initCapabilities(): CapabilitiesBase[] {\n const map = this.statesMap;\n const result = [new Capabilities.ColorController()];\n\n // if the state DIMMER or BRIGHTNESS configured\n if (this.states[map.dimmer] || this.states[map.brightness]) {\n this._brightnessCapability = new Capabilities.BrightnessController();\n this._brightness = this._brightnessCapability.brightness;\n result.push(this._brightnessCapability);\n }\n\n // if the state TEMPERATURE configured\n if (this.states[map.temperature]) {\n this._colorTemperatureCapability = new Capabilities.ColorTemperatureController();\n result.push(this._colorTemperatureCapability);\n }\n\n // if the state ON, DIMMER or BRIGHTNESS configured\n if (this.states[map.on] || this._brightness) {\n this._powerControllerCapability = new Capabilities.PowerController();\n this._powerState = this._powerControllerCapability.powerState;\n result.push(this._powerControllerCapability);\n }\n\n for (const property of result.flatMap(item => item.properties)) {\n const initObject = this.composeInitObject(property);\n if (initObject) {\n property.init(initObject);\n }\n }\n\n return result;\n }\n\n async getOrRetrieveCurrentValue(property: PropertiesBase): Promise<ioBroker.StateValue> {\n const map = this.statesMap;\n\n if (property.currentValue === undefined) {\n property.currentValue = await AdapterProvider.getState(property.getId);\n // convert the non-zero brightness to power = true\n if (property.propertyName === PowerState.propertyName && !this.states[map.on]) {\n property.currentValue = property.currentValue !== 0;\n }\n }\n\n if (property.currentValue === undefined) {\n throw new Error(`unable to retrieve ${property.getId}`);\n }\n\n return property.currentValue;\n }\n\n async setState(property: PropertiesBase, value: ioBroker.StateValue): Promise<void> {\n const map = this.statesMap;\n\n if (property.propertyName === PowerState.propertyName) {\n if (this.states[map.on]) {\n await AdapterProvider.setState(property.setId, value);\n property.currentValue = value;\n } else {\n if (!this._brightness) {\n throw new Error('No brightness property configured');\n }\n if (!this._powerState) {\n throw new Error('No powerState property configured');\n }\n\n if (value) {\n // set brightness\n // set byOn to the configured value or range.max otherwise\n const range = configuredRangeOrDefault(this.states[map.dimmer] || this.states[map.brightness]!);\n const smartName = (this.states[map.dimmer] || this.states[map.brightness])?.smartName;\n let byOn: number | string | undefined | null;\n if (smartName && typeof smartName === 'object') {\n byOn = smartName.byON;\n } else {\n byOn = undefined;\n }\n if (byOn === undefined || byOn === null || isNaN(byOn as unknown as number)) {\n byOn = range.max as number | string | undefined | null;\n } else {\n byOn = parseFloat(byOn);\n }\n await AdapterProvider.setState(this._brightness.setId, byOn ?? 100);\n this._brightness.currentValue = byOn;\n this._powerState.currentValue = true;\n } else {\n // set brightness to 0 on power OFF\n await AdapterProvider.setState(this._brightness.setId, 0);\n this._brightness.currentValue = 0;\n this._powerState.currentValue = false;\n }\n }\n } else if (\n property.propertyName === Brightness.propertyName ||\n property.propertyName === ColorTemperatureInKelvin.propertyName\n ) {\n await AdapterProvider.setState(property.setId, value);\n property.currentValue = value;\n }\n }\n\n async adjustValue(event: AlexaV3Request, property: PropertiesBase): Promise<AlexaV3DirectiveValue> {\n // extract Alexa delta value from event\n const delta = property.alexaDirectiveValue(event);\n\n // convert delta to iobroker value\n const value = property.value(delta);\n\n // set iobroker state\n await this.setState(property, value ?? 0);\n\n return value as AlexaV3DirectiveValue;\n }\n\n composeInitObject(property: PropertiesBase):\n | {\n setState: IotExternalDetectorState;\n getState: IotExternalDetectorState;\n alexaSetter?: (alexaValue: AlexaV3DirectiveValue) => ioBroker.StateValue | undefined;\n alexaGetter?: (value: ioBroker.StateValue | undefined) => AlexaV3DirectiveValue;\n }\n | undefined {\n const map = this.statesMap;\n\n if (property.propertyName === PowerState.propertyName) {\n return {\n setState: this.states[map.on] || this.states[map.dimmer] || this.states[map.brightness]!,\n getState: this.states[map.on] || this.states[map.dimmer] || this.states[map.brightness]!,\n alexaSetter: function (this: PropertiesBase, alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue {\n return alexaValue === PowerState.ON;\n },\n alexaGetter: function (value: ioBroker.StateValue | undefined): AlexaV3DirectiveValue {\n return value ? PowerState.ON : PowerState.OFF;\n },\n };\n }\n\n if (property.propertyName === Brightness.propertyName) {\n return {\n setState: this.states[map.dimmer] || this.states[map.brightness]!,\n getState: this.states[map.dimmer] || this.states[map.brightness]!,\n alexaSetter: function (this: PropertiesBase, alexaValue: AlexaV3DirectiveValue): ioBroker.StateValue {\n return (\n denormalize_0_100(\n alexaValue as number,\n this.valuesRangeMin as number,\n this.valuesRangeMax as number,\n ) ?? 0\n );\n },\n alexaGetter: function (\n this: PropertiesBase,\n value: ioBroker.StateValue | undefined,\n ): AlexaV3DirectiveValue {\n return normalize_0_100(\n value as number,\n this.valuesRangeMin as number,\n this.valuesRangeMax as number,\n );\n },\n };\n }\n\n if (property.propertyName === ColorTemperatureInKelvin.propertyName) {\n return {\n setState: this.states[map.temperature]!,\n getState: this.states[map.temperature]!,\n alexaSetter: function (\n this: ColorTemperatureInKelvin,\n alexaValue: AlexaV3DirectiveValue,\n ): ioBroker.StateValue {\n if (alexaValue === 1) {\n // increase directive\n const closest = closestFromList(\n (this.currentValue as number) || this.colorTemperatureTable[0],\n this.colorTemperatureTable,\n );\n let index = this.colorTemperatureTable.indexOf(closest) + 1;\n index =\n index >= this.colorTemperatureTable.length ? this.colorTemperatureTable.length - 1 : index;\n return this.colorTemperatureTable[index];\n }\n if (alexaValue === -1) {\n // decrease directive\n const closest = closestFromList(\n (this.currentValue as number) || this.colorTemperatureTable[0],\n this.colorTemperatureTable,\n );\n let index = this.colorTemperatureTable.indexOf(closest) - 1;\n index = index < 0 ? 0 : index;\n return this.colorTemperatureTable[index];\n }\n\n return alexaValue as number;\n },\n alexaGetter: function (value: ioBroker.StateValue | undefined): AlexaV3DirectiveValue {\n return value as number;\n },\n };\n }\n }\n}\n"]}
|