iobroker.iot 4.0.1 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -1
- package/admin/assets/{index-Y479CE6x.js → index-BjEWVyqN.js} +1 -1
- package/admin/index_m.html +1 -1
- 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 +553 -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 +15 -15
- package/package.json +2 -2
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
35
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const uuid_1 = require("uuid");
|
|
37
|
+
const Utils = __importStar(require("../Helpers/Utils"));
|
|
38
|
+
/**
|
|
39
|
+
* Helper class to generate an AlexaResponse.
|
|
40
|
+
*/
|
|
41
|
+
class AlexaResponse {
|
|
42
|
+
context;
|
|
43
|
+
iobVersion = '1';
|
|
44
|
+
event;
|
|
45
|
+
static ErrorResponseName = 'ErrorResponse';
|
|
46
|
+
static isErrorResponse(response) {
|
|
47
|
+
return response?.event?.header?.name === AlexaResponse.ErrorResponseName;
|
|
48
|
+
}
|
|
49
|
+
static errorResponse(messageId, payload) {
|
|
50
|
+
return new AlexaResponse({
|
|
51
|
+
name: AlexaResponse.ErrorResponseName,
|
|
52
|
+
payload,
|
|
53
|
+
messageId,
|
|
54
|
+
});
|
|
55
|
+
}
|
|
56
|
+
static endpointUnreachable(messageId) {
|
|
57
|
+
return AlexaResponse.errorResponse(messageId, {
|
|
58
|
+
type: 'ENDPOINT_UNREACHABLE',
|
|
59
|
+
message: 'Unable to reach endpoint.',
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
static directiveNotSupportedByControl(controlName, namespace, messageId, payloadVersion) {
|
|
63
|
+
return AlexaResponse.errorResponse(messageId, {
|
|
64
|
+
type: 'INTERNAL_ERROR',
|
|
65
|
+
message: `Control ${controlName} doesn't support the ${namespace} with payloadVersion ${payloadVersion}`,
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
static directiveNotSupportedByDevice(deviceName, namespace, messageId, payloadVersion) {
|
|
69
|
+
return AlexaResponse.errorResponse(messageId, {
|
|
70
|
+
type: 'INTERNAL_ERROR',
|
|
71
|
+
message: `Device ${deviceName} doesn't support the ${namespace} with payloadVersion ${payloadVersion}`,
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
static nonExistingEndpoint(messageId, endpointId) {
|
|
75
|
+
return AlexaResponse.errorResponse(messageId, {
|
|
76
|
+
type: 'INTERNAL_ERROR',
|
|
77
|
+
message: `No endpoint with id ${endpointId} found`,
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Composes Alexa respond on a successfully processed Alexa directive to change the capability's value of a device
|
|
82
|
+
*/
|
|
83
|
+
static handled(event, propertyName, value, propertyInstance) {
|
|
84
|
+
const response = new AlexaResponse({
|
|
85
|
+
correlationToken: event?.directive?.header?.correlationToken,
|
|
86
|
+
token: event?.directive?.endpoint?.scope?.token,
|
|
87
|
+
endpointId: event?.directive?.endpoint?.endpointId,
|
|
88
|
+
messageId: event?.directive?.header?.messageId,
|
|
89
|
+
});
|
|
90
|
+
response.addContextProperty({
|
|
91
|
+
namespace: event?.directive?.header?.namespace,
|
|
92
|
+
name: propertyName,
|
|
93
|
+
instance: propertyInstance,
|
|
94
|
+
value,
|
|
95
|
+
});
|
|
96
|
+
return response;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Constructor for an Alexa Response.
|
|
100
|
+
*
|
|
101
|
+
* @param opts Contains initialization options for the response
|
|
102
|
+
*/
|
|
103
|
+
constructor(opts) {
|
|
104
|
+
opts ||= {};
|
|
105
|
+
if (opts.context !== undefined) {
|
|
106
|
+
this.context = Utils.defaultIfNullOrEmpty(opts.context, undefined);
|
|
107
|
+
}
|
|
108
|
+
if (opts.event !== undefined) {
|
|
109
|
+
this.event = Utils.defaultIfNullOrEmpty(opts.event, undefined);
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
this.event = {
|
|
113
|
+
header: {
|
|
114
|
+
namespace: Utils.defaultIfNullOrEmpty(opts.namespace, 'Alexa'),
|
|
115
|
+
name: Utils.defaultIfNullOrEmpty(opts.name, 'Response'),
|
|
116
|
+
messageId: Utils.defaultIfNullOrEmpty(opts.messageId, (0, uuid_1.v4)()),
|
|
117
|
+
correlationToken: Utils.defaultIfNullOrEmpty(opts.correlationToken, undefined),
|
|
118
|
+
payloadVersion: Utils.defaultIfNullOrEmpty(opts.payloadVersion, '3'),
|
|
119
|
+
},
|
|
120
|
+
endpoint: {
|
|
121
|
+
scope: {
|
|
122
|
+
type: 'BearerToken',
|
|
123
|
+
token: Utils.defaultIfNullOrEmpty(opts.token, 'INVALID'),
|
|
124
|
+
},
|
|
125
|
+
endpointId: Utils.defaultIfNullOrEmpty(opts.endpointId, 'INVALID'),
|
|
126
|
+
},
|
|
127
|
+
payload: Utils.defaultIfNullOrEmpty(opts.payload, {}),
|
|
128
|
+
};
|
|
129
|
+
if (opts.changeCauseType) {
|
|
130
|
+
this.event.payload.change = {
|
|
131
|
+
cause: {
|
|
132
|
+
type: opts.changeCauseType,
|
|
133
|
+
},
|
|
134
|
+
properties: [],
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
if (!this.event) {
|
|
139
|
+
throw new Error('Event is not defined');
|
|
140
|
+
}
|
|
141
|
+
// No endpoint in an AcceptGrant or Discover request
|
|
142
|
+
if (this.event.header.name === 'AcceptGrant.Response' || this.event.header.name === 'Discover.Response') {
|
|
143
|
+
delete this.event.endpoint;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
addContext() {
|
|
147
|
+
this.context ||= { properties: [] };
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Add a property to the context.
|
|
151
|
+
*
|
|
152
|
+
* @param opts Contains options for the property.
|
|
153
|
+
*/
|
|
154
|
+
addContextProperty(opts) {
|
|
155
|
+
this.addContext();
|
|
156
|
+
const property = {
|
|
157
|
+
namespace: Utils.defaultIfNullOrEmpty(opts.namespace, 'Alexa.EndpointHealth'),
|
|
158
|
+
instance: Utils.defaultIfNullOrEmpty(opts.instance, undefined),
|
|
159
|
+
name: Utils.defaultIfNullOrEmpty(opts.name, 'connectivity'),
|
|
160
|
+
value: Utils.defaultIfNullOrEmpty(opts.value, { value: 'OK' }),
|
|
161
|
+
timeOfSample: Utils.defaultIfNullOrEmpty(opts.timeOfSample, new Date().toISOString()),
|
|
162
|
+
uncertaintyInMilliseconds: Utils.defaultIfNullOrEmpty(opts.uncertaintyInMilliseconds, 0),
|
|
163
|
+
};
|
|
164
|
+
if (!property.instance) {
|
|
165
|
+
delete property.instance;
|
|
166
|
+
}
|
|
167
|
+
this.context.properties.push(property);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Add a property to the payload.
|
|
171
|
+
*
|
|
172
|
+
* @param opts Contains options for the property.
|
|
173
|
+
*/
|
|
174
|
+
addPayloadChangeProperty(opts) {
|
|
175
|
+
opts ||= {};
|
|
176
|
+
const property = {
|
|
177
|
+
namespace: Utils.defaultIfNullOrEmpty(opts.namespace, 'Alexa.EndpointHealth'),
|
|
178
|
+
instance: Utils.defaultIfNullOrEmpty(opts.instance, undefined),
|
|
179
|
+
name: Utils.defaultIfNullOrEmpty(opts.name, 'connectivity'),
|
|
180
|
+
value: Utils.defaultIfNullOrEmpty(opts.value, { value: 'OK' }),
|
|
181
|
+
timeOfSample: Utils.defaultIfNullOrEmpty(opts.timeOfSample, new Date().toISOString()),
|
|
182
|
+
uncertaintyInMilliseconds: Utils.defaultIfNullOrEmpty(opts.uncertaintyInMilliseconds, 0),
|
|
183
|
+
};
|
|
184
|
+
if (!property.instance) {
|
|
185
|
+
delete property.instance;
|
|
186
|
+
}
|
|
187
|
+
if (!this.event) {
|
|
188
|
+
throw new Error('Event is not defined');
|
|
189
|
+
}
|
|
190
|
+
this.event.payload.change ||= { properties: [], cause: { type: 'APP_INTERACTION' } };
|
|
191
|
+
this.event.payload.change.properties.push(property);
|
|
192
|
+
}
|
|
193
|
+
static alexaCapability() {
|
|
194
|
+
return [
|
|
195
|
+
{
|
|
196
|
+
type: 'AlexaInterface',
|
|
197
|
+
interface: 'Alexa',
|
|
198
|
+
version: '3',
|
|
199
|
+
},
|
|
200
|
+
];
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Adds an endpoint to the payload.
|
|
204
|
+
*
|
|
205
|
+
* @param opts Contains options for the endpoint.
|
|
206
|
+
*/
|
|
207
|
+
addPayloadEndpoint(opts) {
|
|
208
|
+
if (!this.event) {
|
|
209
|
+
throw new Error('Event is not defined');
|
|
210
|
+
}
|
|
211
|
+
this.event.payload.endpoints ||= [];
|
|
212
|
+
opts ||= {};
|
|
213
|
+
// construct the proper structure expected for the endpoint
|
|
214
|
+
const endpoint = {
|
|
215
|
+
endpointId: Utils.defaultIfNullOrEmpty(opts.endpointId, 'dummy-endpoint-001'),
|
|
216
|
+
manufacturerName: Utils.defaultIfNullOrEmpty(opts.manufacturerName, 'ioBroker Group'),
|
|
217
|
+
description: Utils.defaultIfNullOrEmpty(opts.description, 'Device controlled by ioBroker'),
|
|
218
|
+
friendlyName: Utils.defaultIfNullOrEmpty(opts.friendlyName, 'ioBroker Stub Endpoint'),
|
|
219
|
+
displayCategories: Utils.defaultIfNullOrEmpty(opts.displayCategories, ['OTHER']),
|
|
220
|
+
capabilities: AlexaResponse.alexaCapability().concat(Utils.defaultIfNullOrEmpty(opts.capabilities, [])),
|
|
221
|
+
cookie: undefined,
|
|
222
|
+
};
|
|
223
|
+
if (Object.prototype.hasOwnProperty.call(opts, 'cookie')) {
|
|
224
|
+
endpoint.cookie = Utils.defaultIfNullOrEmpty(opts.cookie, {});
|
|
225
|
+
}
|
|
226
|
+
this.event.payload.endpoints.push(endpoint);
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Creates a capability for an endpoint within the payload.
|
|
230
|
+
*
|
|
231
|
+
* @param opts Contains options for the endpoint capability.
|
|
232
|
+
*/
|
|
233
|
+
asEndpointCapability(opts) {
|
|
234
|
+
opts ||= {};
|
|
235
|
+
const response = {
|
|
236
|
+
type: Utils.defaultIfNullOrEmpty(opts.type, 'AlexaInterface'),
|
|
237
|
+
interface: Utils.defaultIfNullOrEmpty(opts.interface, 'Alexa'),
|
|
238
|
+
version: Utils.defaultIfNullOrEmpty(opts.version, '3'),
|
|
239
|
+
properties: Utils.defaultIfNullOrEmpty(opts.properties, {}),
|
|
240
|
+
// not all capabilities have the following ones
|
|
241
|
+
instance: Utils.defaultIfNullOrEmpty(opts.instance, undefined),
|
|
242
|
+
configuration: Utils.defaultIfNullOrEmpty(opts.configuration, undefined),
|
|
243
|
+
semantics: Utils.defaultIfNullOrEmpty(opts.semantics, undefined),
|
|
244
|
+
capabilityResources: Utils.defaultIfNullOrEmpty(opts.capabilityResources, undefined),
|
|
245
|
+
};
|
|
246
|
+
if (!response.instance) {
|
|
247
|
+
delete response.instance;
|
|
248
|
+
}
|
|
249
|
+
if (!response.configuration) {
|
|
250
|
+
delete response.configuration;
|
|
251
|
+
}
|
|
252
|
+
if (!response.semantics) {
|
|
253
|
+
delete response.semantics;
|
|
254
|
+
}
|
|
255
|
+
if (!response.capabilityResources) {
|
|
256
|
+
delete response.capabilityResources;
|
|
257
|
+
}
|
|
258
|
+
return response;
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Get the composed Alexa Response.
|
|
262
|
+
*/
|
|
263
|
+
get() {
|
|
264
|
+
return this;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
exports.default = AlexaResponse;
|
|
268
|
+
//# sourceMappingURL=AlexaResponse.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"AlexaResponse.js","sourceRoot":"","sources":["../../../../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utils';\nimport type {\n AlexaV3Capability,\n AlexaV3ContextProperty,\n AlexaV3Directive,\n AlexaV3DirectiveType,\n AlexaV3DiscoverAppliance,\n AlexaV3EndpointID,\n AlexaV3Namespace,\n AlexaV3Payload,\n AlexaV3ReportedState,\n AlexaV3Request,\n} from '../types';\n\n/**\n * Helper class to generate an AlexaResponse.\n */\nexport default class AlexaResponse {\n public context?: {\n properties: AlexaV3ReportedState[];\n };\n\n public iobVersion = '1';\n\n public readonly event?: AlexaV3Directive;\n\n static ErrorResponseName: AlexaV3DirectiveType = 'ErrorResponse';\n\n static isErrorResponse(response: AlexaResponse): boolean {\n return response?.event?.header?.name === AlexaResponse.ErrorResponseName;\n }\n\n static errorResponse(messageId: string, payload: any): AlexaResponse {\n return new AlexaResponse({\n name: AlexaResponse.ErrorResponseName,\n payload,\n messageId,\n });\n }\n\n static endpointUnreachable(messageId: string): AlexaResponse {\n return AlexaResponse.errorResponse(messageId, {\n type: 'ENDPOINT_UNREACHABLE',\n message: 'Unable to reach endpoint.',\n });\n }\n\n static directiveNotSupportedByControl(\n controlName: string,\n namespace: AlexaV3Namespace,\n messageId: string,\n payloadVersion: string,\n ): AlexaResponse {\n return AlexaResponse.errorResponse(messageId, {\n type: 'INTERNAL_ERROR',\n message: `Control ${controlName} doesn't support the ${namespace} with payloadVersion ${payloadVersion}`,\n });\n }\n\n static directiveNotSupportedByDevice(\n deviceName: string,\n namespace: AlexaV3Namespace,\n messageId: string,\n payloadVersion: string,\n ): AlexaResponse {\n return AlexaResponse.errorResponse(messageId, {\n type: 'INTERNAL_ERROR',\n message: `Device ${deviceName} doesn't support the ${namespace} with payloadVersion ${payloadVersion}`,\n });\n }\n\n static nonExistingEndpoint(messageId: string, endpointId: AlexaV3EndpointID | undefined): AlexaResponse {\n return AlexaResponse.errorResponse(messageId, {\n type: 'INTERNAL_ERROR',\n message: `No endpoint with id ${endpointId} found`,\n });\n }\n\n /**\n * Composes Alexa respond on a successfully processed Alexa directive to change the capability's value of a device\n */\n static handled(event: AlexaV3Request, propertyName: string, value: any, propertyInstance?: string): AlexaResponse {\n const response = new AlexaResponse({\n correlationToken: event?.directive?.header?.correlationToken,\n token: event?.directive?.endpoint?.scope?.token,\n endpointId: event?.directive?.endpoint?.endpointId,\n messageId: event?.directive?.header?.messageId,\n });\n\n response.addContextProperty({\n namespace: event?.directive?.header?.namespace,\n name: propertyName,\n instance: propertyInstance,\n value,\n });\n\n return response;\n }\n\n /**\n * Constructor for an Alexa Response.\n *\n * @param opts Contains initialization options for the response\n */\n constructor(opts?: {\n context?: {\n properties: AlexaV3ReportedState[];\n };\n namespace?: AlexaV3Namespace;\n name?: AlexaV3DirectiveType;\n messageId?: string;\n correlationToken?: string;\n payloadVersion?: '3';\n token?: string;\n endpointId?: string;\n payload?: AlexaV3Payload;\n changeCauseType?: 'APP_INTERACTION' | 'PHYSICAL_INTERACTION' | 'VOICE_INTERACTION';\n event?: AlexaV3Directive;\n }) {\n opts ||= {};\n\n if (opts.context !== undefined) {\n this.context = Utils.defaultIfNullOrEmpty(opts.context, undefined);\n }\n\n if (opts.event !== undefined) {\n this.event = Utils.defaultIfNullOrEmpty(opts.event, undefined);\n } else {\n this.event = {\n header: {\n namespace: Utils.defaultIfNullOrEmpty<AlexaV3Namespace>(opts.namespace, 'Alexa'),\n name: Utils.defaultIfNullOrEmpty<AlexaV3DirectiveType>(opts.name, 'Response'),\n messageId: Utils.defaultIfNullOrEmpty(opts.messageId, uuidv4()),\n correlationToken: Utils.defaultIfNullOrEmpty(opts.correlationToken, undefined),\n payloadVersion: Utils.defaultIfNullOrEmpty<'3'>(opts.payloadVersion, '3'),\n },\n endpoint: {\n scope: {\n type: 'BearerToken',\n token: Utils.defaultIfNullOrEmpty(opts.token, 'INVALID'),\n },\n endpointId: Utils.defaultIfNullOrEmpty(opts.endpointId, 'INVALID'),\n },\n payload: Utils.defaultIfNullOrEmpty(opts.payload, {}),\n };\n\n if (opts.changeCauseType) {\n this.event.payload.change = {\n cause: {\n type: opts.changeCauseType,\n },\n properties: [],\n };\n }\n }\n\n if (!this.event) {\n throw new Error('Event is not defined');\n }\n\n // No endpoint in an AcceptGrant or Discover request\n if (this.event.header.name === 'AcceptGrant.Response' || this.event.header.name === 'Discover.Response') {\n delete this.event.endpoint;\n }\n }\n\n addContext(): void {\n this.context ||= { properties: [] };\n }\n\n /**\n * Add a property to the context.\n *\n * @param opts Contains options for the property.\n */\n addContextProperty(opts: {\n namespace?: AlexaV3Namespace;\n instance?: string;\n name?: string;\n value?: any;\n timeOfSample?: string;\n uncertaintyInMilliseconds?: number;\n }): void {\n this.addContext();\n\n const property = {\n namespace: Utils.defaultIfNullOrEmpty(opts.namespace, 'Alexa.EndpointHealth'),\n instance: Utils.defaultIfNullOrEmpty(opts.instance, undefined),\n name: Utils.defaultIfNullOrEmpty(opts.name, 'connectivity'),\n value: Utils.defaultIfNullOrEmpty(opts.value, { value: 'OK' }),\n timeOfSample: Utils.defaultIfNullOrEmpty(opts.timeOfSample, new Date().toISOString()),\n uncertaintyInMilliseconds: Utils.defaultIfNullOrEmpty(opts.uncertaintyInMilliseconds, 0),\n };\n\n if (!property.instance) {\n delete property.instance;\n }\n\n this.context!.properties.push(property);\n }\n\n /**\n * Add a property to the payload.\n *\n * @param opts Contains options for the property.\n */\n addPayloadChangeProperty(opts: AlexaV3ContextProperty): void {\n opts ||= {} as AlexaV3ContextProperty;\n\n const property = {\n namespace: Utils.defaultIfNullOrEmpty(opts.namespace, 'Alexa.EndpointHealth'),\n instance: Utils.defaultIfNullOrEmpty(opts.instance, undefined),\n name: Utils.defaultIfNullOrEmpty(opts.name, 'connectivity'),\n value: Utils.defaultIfNullOrEmpty(opts.value, { value: 'OK' }),\n timeOfSample: Utils.defaultIfNullOrEmpty(opts.timeOfSample, new Date().toISOString()),\n uncertaintyInMilliseconds: Utils.defaultIfNullOrEmpty(opts.uncertaintyInMilliseconds, 0),\n };\n\n if (!property.instance) {\n delete property.instance;\n }\n\n if (!this.event) {\n throw new Error('Event is not defined');\n }\n this.event.payload.change ||= { properties: [], cause: { type: 'APP_INTERACTION' } };\n\n this.event.payload.change.properties.push(property);\n }\n\n static alexaCapability(): AlexaV3Capability[] {\n return [\n {\n type: 'AlexaInterface',\n interface: 'Alexa',\n version: '3',\n },\n ];\n }\n\n /**\n * Adds an endpoint to the payload.\n *\n * @param opts Contains options for the endpoint.\n */\n addPayloadEndpoint(opts: AlexaV3DiscoverAppliance): void {\n if (!this.event) {\n throw new Error('Event is not defined');\n }\n\n this.event.payload.endpoints ||= [];\n\n opts ||= {} as AlexaV3DiscoverAppliance;\n\n // construct the proper structure expected for the endpoint\n const endpoint: AlexaV3DiscoverAppliance = {\n endpointId: Utils.defaultIfNullOrEmpty(opts.endpointId, 'dummy-endpoint-001'),\n manufacturerName: Utils.defaultIfNullOrEmpty(opts.manufacturerName, 'ioBroker Group'),\n description: Utils.defaultIfNullOrEmpty(opts.description, 'Device controlled by ioBroker'),\n friendlyName: Utils.defaultIfNullOrEmpty(opts.friendlyName, 'ioBroker Stub Endpoint'),\n displayCategories: Utils.defaultIfNullOrEmpty(opts.displayCategories, ['OTHER']),\n capabilities: AlexaResponse.alexaCapability().concat(\n Utils.defaultIfNullOrEmpty<AlexaV3Capability[]>(opts.capabilities, []),\n ),\n cookie: undefined,\n };\n\n if (Object.prototype.hasOwnProperty.call(opts, 'cookie')) {\n endpoint.cookie = Utils.defaultIfNullOrEmpty<Record<string, string>>(opts.cookie, {});\n }\n\n this.event.payload.endpoints.push(endpoint);\n }\n\n /**\n * Creates a capability for an endpoint within the payload.\n *\n * @param opts Contains options for the endpoint capability.\n */\n asEndpointCapability(opts?: AlexaV3Capability): AlexaV3Capability {\n opts ||= {} as AlexaV3Capability;\n\n const response = {\n type: Utils.defaultIfNullOrEmpty(opts.type, 'AlexaInterface'),\n interface: Utils.defaultIfNullOrEmpty(opts.interface, 'Alexa'),\n version: Utils.defaultIfNullOrEmpty(opts.version, '3'),\n properties: Utils.defaultIfNullOrEmpty<{\n supported: { name: string }[];\n proactivelyReported?: boolean;\n retrievable?: boolean;\n nonControllable?: boolean;\n }>(\n opts.properties,\n {} as {\n supported: { name: string }[];\n proactivelyReported?: boolean;\n retrievable?: boolean;\n nonControllable?: boolean;\n },\n ),\n // not all capabilities have the following ones\n instance: Utils.defaultIfNullOrEmpty(opts.instance, undefined),\n configuration: Utils.defaultIfNullOrEmpty(opts.configuration, undefined),\n semantics: Utils.defaultIfNullOrEmpty(opts.semantics, undefined),\n capabilityResources: Utils.defaultIfNullOrEmpty(opts.capabilityResources, undefined),\n };\n\n if (!response.instance) {\n delete response.instance;\n }\n if (!response.configuration) {\n delete response.configuration;\n }\n if (!response.semantics) {\n delete response.semantics;\n }\n if (!response.capabilityResources) {\n delete response.capabilityResources;\n }\n\n return response;\n }\n\n /**\n * Get the composed Alexa Response.\n */\n get(): AlexaResponse {\n return this;\n }\n}\n"]}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Base = void 0;
|
|
4
|
+
const Utils_1 = require("../../Helpers/Utils");
|
|
5
|
+
class Base {
|
|
6
|
+
_properties;
|
|
7
|
+
constructor() {
|
|
8
|
+
this._properties = this.initProperties();
|
|
9
|
+
}
|
|
10
|
+
get name() {
|
|
11
|
+
return `${this.constructor.name}`;
|
|
12
|
+
}
|
|
13
|
+
get namespace() {
|
|
14
|
+
return `Alexa.${this.constructor.name}`;
|
|
15
|
+
}
|
|
16
|
+
reportValue(value) {
|
|
17
|
+
return value;
|
|
18
|
+
}
|
|
19
|
+
initProperties() {
|
|
20
|
+
return [];
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Checks whether the capability instance matches, i.e. can handle the event Alexa sends to the skill
|
|
24
|
+
*
|
|
25
|
+
* @param event Contains the Alexa event.
|
|
26
|
+
*/
|
|
27
|
+
matches(event) {
|
|
28
|
+
return (event?.directive?.header?.namespace === this.namespace &&
|
|
29
|
+
event?.directive?.header?.payloadVersion === this.version);
|
|
30
|
+
}
|
|
31
|
+
static get namespace() {
|
|
32
|
+
return `Alexa.${(0, Utils_1.className)(this.toString())}`;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Checks whether the capability object matches, i.e., can handle the event Alexa sends to the skill
|
|
36
|
+
*
|
|
37
|
+
* @param event Contains the Alexa event.
|
|
38
|
+
*/
|
|
39
|
+
static matches(event) {
|
|
40
|
+
return event?.directive?.header?.namespace === this.namespace;
|
|
41
|
+
}
|
|
42
|
+
get properties() {
|
|
43
|
+
return this._properties;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
*
|
|
47
|
+
* @param event Contains the Alexa event.
|
|
48
|
+
* @returns Property to handle on Alexa directive
|
|
49
|
+
*/
|
|
50
|
+
property(event) {
|
|
51
|
+
return this.properties.find(p => p.matches(event));
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Returns object containing all the properties of the smart device capability as it expected by Alexa during discovery
|
|
55
|
+
*/
|
|
56
|
+
get discoverableProperties() {
|
|
57
|
+
return {
|
|
58
|
+
supported: this.properties.map(p => {
|
|
59
|
+
return { name: p.propertyName };
|
|
60
|
+
}),
|
|
61
|
+
proactivelyReported: this.proactivelyReported,
|
|
62
|
+
retrievable: this.retrievable,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Returns whether the smart device proactively reports state changes
|
|
67
|
+
*/
|
|
68
|
+
get proactivelyReported() {
|
|
69
|
+
return true;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Returns whether the smart device handles Alexa ReportState directives
|
|
73
|
+
*/
|
|
74
|
+
get retrievable() {
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
get version() {
|
|
78
|
+
return '3';
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Returns response to Alexa Discovery directive
|
|
82
|
+
*/
|
|
83
|
+
get alexaResponse() {
|
|
84
|
+
return {
|
|
85
|
+
interface: this.namespace,
|
|
86
|
+
version: this.version,
|
|
87
|
+
properties: this.discoverableProperties,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
propertyName(event) {
|
|
91
|
+
return this.property(event)?.propertyName;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Extracts value to be set on the smart device sent in an Alexa directive
|
|
95
|
+
*/
|
|
96
|
+
alexaValue(event) {
|
|
97
|
+
throw new Error(`Method alexaValue is not implemented in ${this.name} capability`);
|
|
98
|
+
// @ts-expect-error fix later!!!!
|
|
99
|
+
return this.property(event)?.alexaValue(event);
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Extracts endpoint id sent in an Alexa directive
|
|
103
|
+
*/
|
|
104
|
+
static endpointId(event) {
|
|
105
|
+
return event.directive.endpoint?.endpointId;
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
exports.Base = Base;
|
|
109
|
+
exports.default = Base;
|
|
110
|
+
//# sourceMappingURL=Base.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Base.js","sourceRoot":"","sources":["../../../../../src/lib/AlexaSmartHomeV3/Alexa/Capabilities/Base.ts"],"names":[],"mappings":";;;AAAA,+CAAgD;AAIhD,MAAa,IAAI;IACG,WAAW,CAAmB;IAE9C;QACI,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,cAAc,EAAE,CAAC;IAC7C,CAAC;IAED,IAAI,IAAI;QACJ,OAAO,GAAG,IAAI,CAAC,WAAW,CAAC,IAAI,EAAE,CAAC;IACtC,CAAC;IAED,IAAI,SAAS;QACT,OAAO,SAAS,IAAI,CAAC,WAAW,CAAC,IAAI,EAAsB,CAAC;IAChE,CAAC;IAED,WAAW,CAAC,KAAuB;QAC/B,OAAO,KAAK,CAAC;IACjB,CAAC;IAED,cAAc;QACV,OAAO,EAAE,CAAC;IACd,CAAC;IAED;;;;OAIG;IACH,OAAO,CAAC,KAAqB;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;YACzB,OAAO,EAAE,IAAI,CAAC,OAAO;YACrB,UAAU,EAAE,IAAI,CAAC,sBAAsB;SAC1C,CAAC;IACN,CAAC;IAED,YAAY,CAAC,KAAqB;QAC9B,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,YAAY,CAAC;IAC9C,CAAC;IAED;;OAEG;IACH,UAAU,CAAC,KAAqB;QAC5B,MAAM,IAAI,KAAK,CAAC,2CAA2C,IAAI,CAAC,IAAI,aAAa,CAAC,CAAC;QACnF,iCAAiC;QACjC,OAAO,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,EAAE,UAAU,CAAC,KAAK,CAAC,CAAC;IACnD,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,KAAqB;QACnC,OAAO,KAAK,CAAC,SAAS,CAAC,QAAQ,EAAE,UAAU,CAAC;IAChD,CAAC;CACJ;AA9HD,oBA8HC;AAED,kBAAe,IAAI,CAAC","sourcesContent":["import { className } from '../../Helpers/Utils';\nimport type { AlexaV3Capability, AlexaV3EndpointID, AlexaV3Namespace, AlexaV3Request } from '../../types';\nimport type { Base as PropertiesBase } from '../Properties/Base';\n\nexport class Base {\n public readonly _properties: PropertiesBase[];\n\n constructor() {\n this._properties = this.initProperties();\n }\n\n get name(): string {\n return `${this.constructor.name}`;\n }\n\n get namespace(): AlexaV3Namespace {\n return `Alexa.${this.constructor.name}` as AlexaV3Namespace;\n }\n\n reportValue(value: number | boolean): any {\n return value;\n }\n\n initProperties(): PropertiesBase[] {\n return [];\n }\n\n /**\n * Checks whether the capability instance matches, i.e. can handle the event Alexa sends to the skill\n *\n * @param event Contains the Alexa event.\n */\n matches(event: AlexaV3Request): boolean {\n return (\n event?.directive?.header?.namespace === this.namespace &&\n event?.directive?.header?.payloadVersion === this.version\n );\n }\n\n static get namespace(): AlexaV3Namespace {\n return `Alexa.${className(this.toString())}` as AlexaV3Namespace;\n }\n\n /**\n * Checks whether the capability object matches, i.e., can handle the event Alexa sends to the skill\n *\n * @param event Contains the Alexa event.\n */\n static matches(event: AlexaV3Request): boolean {\n return event?.directive?.header?.namespace === this.namespace;\n }\n\n get properties(): PropertiesBase[] {\n return this._properties;\n }\n\n /**\n *\n * @param event Contains the Alexa event.\n * @returns Property to handle on Alexa directive\n */\n property(event: AlexaV3Request): PropertiesBase | undefined {\n return this.properties.find(p => p.matches(event));\n }\n\n /**\n * Returns object containing all the properties of the smart device capability as it expected by Alexa during discovery\n */\n get discoverableProperties(): {\n supported: { name: string }[];\n proactivelyReported: boolean;\n retrievable: boolean;\n } {\n return {\n supported: this.properties.map(p => {\n return { name: p.propertyName };\n }),\n proactivelyReported: this.proactivelyReported,\n retrievable: this.retrievable,\n };\n }\n\n /**\n * Returns whether the smart device proactively reports state changes\n */\n get proactivelyReported(): boolean {\n return true;\n }\n\n /**\n * Returns whether the smart device handles Alexa ReportState directives\n */\n get retrievable(): boolean {\n return true;\n }\n\n get version(): string {\n return '3';\n }\n\n /**\n * Returns response to Alexa Discovery directive\n */\n get alexaResponse(): AlexaV3Capability {\n return {\n interface: this.namespace,\n version: this.version,\n properties: this.discoverableProperties,\n };\n }\n\n propertyName(event: AlexaV3Request): string | undefined {\n return this.property(event)?.propertyName;\n }\n\n /**\n * Extracts value to be set on the smart device sent in an Alexa directive\n */\n alexaValue(event: AlexaV3Request): number | boolean | undefined {\n throw new Error(`Method alexaValue is not implemented in ${this.name} capability`);\n // @ts-expect-error fix later!!!!\n return this.property(event)?.alexaValue(event);\n }\n\n /**\n * Extracts endpoint id sent in an Alexa directive\n */\n static endpointId(event: AlexaV3Request): AlexaV3EndpointID | undefined {\n return event.directive.endpoint?.endpointId;\n }\n}\n\nexport default Base;\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 Base_1 = __importDefault(require("./Base"));
|
|
7
|
+
const Brightness_1 = __importDefault(require("../Properties/Brightness"));
|
|
8
|
+
class BrightnessController extends Base_1.default {
|
|
9
|
+
_brightness;
|
|
10
|
+
initProperties() {
|
|
11
|
+
this._brightness = new Brightness_1.default();
|
|
12
|
+
return [this._brightness];
|
|
13
|
+
}
|
|
14
|
+
get brightness() {
|
|
15
|
+
return this._brightness;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = BrightnessController;
|
|
19
|
+
//# sourceMappingURL=BrightnessController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"BrightnessController.js","sourceRoot":"","sources":["../../../../../src/lib/AlexaSmartHomeV3/Alexa/Capabilities/BrightnessController.ts"],"names":[],"mappings":";;;;;AAAA,kDAA0B;AAE1B,0EAAkD;AAElD,MAAqB,oBAAqB,SAAQ,cAAI;IAC1C,WAAW,CAAyB;IAE5C,cAAc;QACV,IAAI,CAAC,WAAW,GAAG,IAAI,oBAAU,EAAE,CAAC;QACpC,OAAO,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC9B,CAAC;IAED,IAAI,UAAU;QACV,OAAO,IAAI,CAAC,WAAY,CAAC;IAC7B,CAAC;CACJ;AAXD,uCAWC","sourcesContent":["import Base from './Base';\nimport type { Base as PropertiesBase } from '../Properties/Base';\nimport Brightness from '../Properties/Brightness';\n\nexport default class BrightnessController extends Base {\n private _brightness: Brightness | undefined;\n\n initProperties(): PropertiesBase[] {\n this._brightness = new Brightness();\n return [this._brightness];\n }\n\n get brightness(): PropertiesBase {\n return this._brightness!;\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
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 Properties_1 = __importDefault(require("../Properties"));
|
|
7
|
+
const Base_1 = __importDefault(require("./Base"));
|
|
8
|
+
class ColorController extends Base_1.default {
|
|
9
|
+
initProperties() {
|
|
10
|
+
return [new Properties_1.default.Color()];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.default = ColorController;
|
|
14
|
+
//# sourceMappingURL=ColorController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColorController.js","sourceRoot":"","sources":["../../../../../src/lib/AlexaSmartHomeV3/Alexa/Capabilities/ColorController.ts"],"names":[],"mappings":";;;;;AAAA,+DAAuC;AACvC,kDAA0B;AAG1B,MAAqB,eAAgB,SAAQ,cAAI;IAC7C,cAAc;QACV,OAAO,CAAC,IAAI,oBAAU,CAAC,KAAK,EAAE,CAAC,CAAC;IACpC,CAAC;CACJ;AAJD,kCAIC","sourcesContent":["import Properties from '../Properties';\nimport Base from './Base';\nimport type { Base as PropertiesBase } from '../Properties/Base';\n\nexport default class ColorController extends Base {\n initProperties(): PropertiesBase[] {\n return [new Properties.Color()];\n }\n}\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
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 Base_1 = __importDefault(require("./Base"));
|
|
7
|
+
const ColorTemperatureInKelvin_1 = __importDefault(require("../Properties/ColorTemperatureInKelvin"));
|
|
8
|
+
class ColorTemperatureController extends Base_1.default {
|
|
9
|
+
_colorTemperatureInKelvin;
|
|
10
|
+
initProperties() {
|
|
11
|
+
this._colorTemperatureInKelvin = new ColorTemperatureInKelvin_1.default();
|
|
12
|
+
return [this._colorTemperatureInKelvin];
|
|
13
|
+
}
|
|
14
|
+
get colorTemperatureInKelvin() {
|
|
15
|
+
return this._colorTemperatureInKelvin;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
exports.default = ColorTemperatureController;
|
|
19
|
+
//# sourceMappingURL=ColorTemperatureController.js.map
|
package/build-backend/lib/AlexaSmartHomeV3/Alexa/Capabilities/ColorTemperatureController.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ColorTemperatureController.js","sourceRoot":"","sources":["../../../../../src/lib/AlexaSmartHomeV3/Alexa/Capabilities/ColorTemperatureController.ts"],"names":[],"mappings":";;;;;AAAA,kDAA0B;AAE1B,sGAA8E;AAE9E,MAAqB,0BAA2B,SAAQ,cAAI;IAChD,yBAAyB,CAAuC;IAExE,cAAc;QACV,IAAI,CAAC,yBAAyB,GAAG,IAAI,kCAAwB,EAAE,CAAC;QAChE,OAAO,CAAC,IAAI,CAAC,yBAAyB,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI,wBAAwB;QACxB,OAAO,IAAI,CAAC,yBAA0B,CAAC;IAC3C,CAAC;CACJ;AAXD,6CAWC","sourcesContent":["import Base from './Base';\nimport type { Base as PropertiesBase } from '../Properties/Base';\nimport ColorTemperatureInKelvin from '../Properties/ColorTemperatureInKelvin';\n\nexport default class ColorTemperatureController extends Base {\n private _colorTemperatureInKelvin: ColorTemperatureInKelvin | undefined;\n\n initProperties(): PropertiesBase[] {\n this._colorTemperatureInKelvin = new ColorTemperatureInKelvin();\n return [this._colorTemperatureInKelvin];\n }\n\n get colorTemperatureInKelvin(): PropertiesBase {\n return this._colorTemperatureInKelvin!;\n }\n}\n"]}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
exports.ContactSensor = void 0;
|
|
7
|
+
const Base_1 = __importDefault(require("./Base"));
|
|
8
|
+
const Properties_1 = __importDefault(require("../Properties"));
|
|
9
|
+
class ContactSensor extends Base_1.default {
|
|
10
|
+
initProperties() {
|
|
11
|
+
return [new Properties_1.default.DetectionState()];
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
exports.ContactSensor = ContactSensor;
|
|
15
|
+
exports.default = ContactSensor;
|
|
16
|
+
//# sourceMappingURL=ContactSensor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ContactSensor.js","sourceRoot":"","sources":["../../../../../src/lib/AlexaSmartHomeV3/Alexa/Capabilities/ContactSensor.ts"],"names":[],"mappings":";;;;;;AAAA,kDAA0B;AAC1B,+DAAuC;AAGvC,MAAa,aAAc,SAAQ,cAAI;IACnC,cAAc;QACV,OAAO,CAAC,IAAI,oBAAU,CAAC,cAAc,EAAE,CAAC,CAAC;IAC7C,CAAC;CACJ;AAJD,sCAIC;AAED,kBAAe,aAAa,CAAC","sourcesContent":["import Base from './Base';\nimport Properties from '../Properties';\nimport type { Base as PropertiesBase } from '../Properties/Base';\n\nexport class ContactSensor extends Base {\n initProperties(): PropertiesBase[] {\n return [new Properties.DetectionState()];\n }\n}\n\nexport default ContactSensor;\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
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 Properties_1 = __importDefault(require("../Properties"));
|
|
7
|
+
const Base_1 = __importDefault(require("./Base"));
|
|
8
|
+
class LockController extends Base_1.default {
|
|
9
|
+
initProperties() {
|
|
10
|
+
return [new Properties_1.default.LockState()];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.default = LockController;
|
|
14
|
+
//# sourceMappingURL=LockController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LockController.js","sourceRoot":"","sources":["../../../../../src/lib/AlexaSmartHomeV3/Alexa/Capabilities/LockController.ts"],"names":[],"mappings":";;;;;AAAA,+DAAuC;AACvC,kDAA0B;AAG1B,MAAqB,cAAe,SAAQ,cAAI;IAC5C,cAAc;QACV,OAAO,CAAC,IAAI,oBAAU,CAAC,SAAS,EAAE,CAAC,CAAC;IACxC,CAAC;CACJ;AAJD,iCAIC","sourcesContent":["import Properties from '../Properties';\nimport Base from './Base';\nimport type { Base as PropertiesBase } from '../Properties/Base';\n\nexport default class LockController extends Base {\n initProperties(): PropertiesBase[] {\n return [new Properties.LockState()];\n }\n}\n"]}
|
|
@@ -0,0 +1,68 @@
|
|
|
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 Base_1 = __importDefault(require("./Base"));
|
|
7
|
+
const Mode_1 = __importDefault(require("../Properties/Mode"));
|
|
8
|
+
class ModeController extends Base_1.default {
|
|
9
|
+
_property;
|
|
10
|
+
initProperties() {
|
|
11
|
+
this._property = new Mode_1.default();
|
|
12
|
+
return [this._property];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Returns response to Alexa Discovery directive
|
|
16
|
+
*/
|
|
17
|
+
get alexaResponse() {
|
|
18
|
+
return {
|
|
19
|
+
interface: this.namespace,
|
|
20
|
+
instance: this.instance,
|
|
21
|
+
version: this.version,
|
|
22
|
+
properties: this.discoverableProperties,
|
|
23
|
+
configuration: this.configurationAsDiscoveryResponse,
|
|
24
|
+
semantics: this.semanticsAsDiscoveryResponse,
|
|
25
|
+
capabilityResources: this.capabilityResourcesAsDiscoveryResponse,
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
get discoverableProperties() {
|
|
29
|
+
return {
|
|
30
|
+
supported: this.properties.map(p => {
|
|
31
|
+
return { name: p.propertyName };
|
|
32
|
+
}),
|
|
33
|
+
proactivelyReported: this.proactivelyReported,
|
|
34
|
+
retrievable: this.retrievable,
|
|
35
|
+
nonControllable: false,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
get capabilityResourcesAsDiscoveryResponse() {
|
|
39
|
+
return { friendlyNames: this.friendlyNames };
|
|
40
|
+
}
|
|
41
|
+
get friendlyNames() {
|
|
42
|
+
return [
|
|
43
|
+
{
|
|
44
|
+
'@type': 'asset',
|
|
45
|
+
value: {
|
|
46
|
+
assetId: 'Alexa.Setting.Mode',
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
];
|
|
50
|
+
}
|
|
51
|
+
get instance() {
|
|
52
|
+
return `${this._property.instance}`;
|
|
53
|
+
}
|
|
54
|
+
get configurationAsDiscoveryResponse() {
|
|
55
|
+
return {
|
|
56
|
+
ordered: false,
|
|
57
|
+
supportedModes: this._property.supportedModes.flatMap(mode => mode.discoveryResponse),
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
get semanticsAsDiscoveryResponse() {
|
|
61
|
+
return {
|
|
62
|
+
actionMappings: this._property.supportedModes.flatMap(mode => mode.actionMappings),
|
|
63
|
+
stateMappings: this._property.supportedModes.flatMap(mode => mode.stateMappings),
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
exports.default = ModeController;
|
|
68
|
+
//# sourceMappingURL=ModeController.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ModeController.js","sourceRoot":"","sources":["../../../../../src/lib/AlexaSmartHomeV3/Alexa/Capabilities/ModeController.ts"],"names":[],"mappings":";;;;;AAAA,kDAA0B;AAE1B,8DAAsC;AAStC,MAAqB,cAAe,SAAQ,cAAI;IACpC,SAAS,CAAmB;IAEpC,cAAc;QACV,IAAI,CAAC,SAAS,GAAG,IAAI,cAAI,EAAE,CAAC;QAC5B,OAAO,CAAC,IAAI,CAAC,SAAS,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I,CAAC,SAAU,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,cAAc,CAAC;YACnF,aAAa,EAAE,IAAI,CAAC,SAAU,CAAC,cAAc,CAAC,OAAO,CAAC,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,aAAa,CAAC;SACpF,CAAC;IACN,CAAC;CACJ;AA/ED,iCA+EC","sourcesContent":["import Base from './Base';\nimport type { Base as PropertiesBase } from '../Properties/Base';\nimport Mode from '../Properties/Mode';\nimport type {\n AlexaV3ActionMapping,\n AlexaV3Capability,\n AlexaV3DiscoveryResponse,\n AlexaV3FriendlyName,\n AlexaV3StateMapping,\n} from '../../types';\n\nexport default class ModeController extends Base {\n private _property: Mode | undefined;\n\n initProperties(): PropertiesBase[] {\n this._property = new Mode();\n return [this._property];\n }\n\n /**\n * Returns response to Alexa Discovery directive\n */\n get alexaResponse(): AlexaV3Capability {\n return {\n interface: this.namespace,\n instance: this.instance,\n version: this.version,\n properties: this.discoverableProperties,\n configuration: this.configurationAsDiscoveryResponse,\n semantics: this.semanticsAsDiscoveryResponse,\n capabilityResources: this.capabilityResourcesAsDiscoveryResponse,\n };\n }\n\n get discoverableProperties(): {\n supported: { name: string }[];\n proactivelyReported: boolean;\n retrievable: boolean;\n nonControllable: false;\n } {\n return {\n supported: this.properties.map(p => {\n return { name: p.propertyName };\n }),\n proactivelyReported: this.proactivelyReported,\n retrievable: this.retrievable,\n nonControllable: false,\n };\n }\n\n get capabilityResourcesAsDiscoveryResponse(): {\n friendlyNames: AlexaV3FriendlyName[];\n } {\n return { friendlyNames: this.friendlyNames };\n }\n\n get friendlyNames(): AlexaV3FriendlyName[] {\n return [\n {\n '@type': 'asset',\n value: {\n assetId: 'Alexa.Setting.Mode',\n },\n },\n ];\n }\n\n get instance(): string {\n return `${this._property!.instance}`;\n }\n\n get configurationAsDiscoveryResponse(): {\n ordered: boolean;\n supportedModes: AlexaV3DiscoveryResponse[];\n } {\n return {\n ordered: false,\n supportedModes: this._property!.supportedModes.flatMap(mode => mode.discoveryResponse),\n };\n }\n\n get semanticsAsDiscoveryResponse(): {\n actionMappings: AlexaV3ActionMapping[];\n stateMappings: AlexaV3StateMapping[];\n } {\n return {\n actionMappings: this._property!.supportedModes.flatMap(mode => mode.actionMappings),\n stateMappings: this._property!.supportedModes.flatMap(mode => mode.stateMappings),\n };\n }\n}\n"]}
|
|
@@ -0,0 +1,14 @@
|
|
|
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 Properties_1 = __importDefault(require("../Properties"));
|
|
7
|
+
const Base_1 = __importDefault(require("./Base"));
|
|
8
|
+
class MotionSensor extends Base_1.default {
|
|
9
|
+
initProperties() {
|
|
10
|
+
return [new Properties_1.default.DetectionState()];
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
exports.default = MotionSensor;
|
|
14
|
+
//# sourceMappingURL=MotionSensor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"MotionSensor.js","sourceRoot":"","sources":["../../../../../src/lib/AlexaSmartHomeV3/Alexa/Capabilities/MotionSensor.ts"],"names":[],"mappings":";;;;;AAAA,+DAAuC;AACvC,kDAA0B;AAG1B,MAAqB,YAAa,SAAQ,cAAI;IAC1C,cAAc;QACV,OAAO,CAAC,IAAI,oBAAU,CAAC,cAAc,EAAE,CAAC,CAAC;IAC7C,CAAC;CACJ;AAJD,+BAIC","sourcesContent":["import Properties from '../Properties';\nimport Base from './Base';\nimport type { Base as PropertiesBase } from '../Properties/Base';\n\nexport default class MotionSensor extends Base {\n initProperties(): PropertiesBase[] {\n return [new Properties.DetectionState()];\n }\n}\n"]}
|