lavva.exalushome 2.0.112 → 2.0.113
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/build/exalushome-library-bundle.js +1 -1
- package/build/exalushome-library-bundle.js.map +1 -1
- package/build/js/Api.js +112 -112
- package/build/js/Api.js.map +1 -1
- package/build/js/AsyncLock.js +15 -15
- package/build/js/AsyncSemaphore.js +44 -44
- package/build/js/AsyncSemaphore.js.map +1 -1
- package/build/js/CancelationTokenSource.js +18 -18
- package/build/js/DataFrame.js +86 -86
- package/build/js/DependencyContainer.js +87 -87
- package/build/js/DependencyContainer.js.map +1 -1
- package/build/js/Event.js +24 -24
- package/build/js/Event.js.map +1 -1
- package/build/js/Guid.js +8 -8
- package/build/js/Helpers.js +132 -132
- package/build/js/Helpers.js.map +1 -1
- package/build/js/IDIService.js +1 -1
- package/build/js/INetworkService.js +41 -41
- package/build/js/Services/AppStateService.js +217 -217
- package/build/js/Services/AppStateService.js.map +1 -1
- package/build/js/Services/Chat/ChatImplementations/ControllerChat/ControllerChat.js +224 -224
- package/build/js/Services/Chat/ChatImplementations/ControllerChat/ControllerChat.js.map +1 -1
- package/build/js/Services/Chat/ChatImplementations/ControllerChat/IControllerChat.js +33 -33
- package/build/js/Services/Chat/ChatImplementations/FamillyChat/FamillyChat.js +147 -147
- package/build/js/Services/Chat/ChatImplementations/FamillyChat/FamillyChat.js.map +1 -1
- package/build/js/Services/Chat/ChatImplementations/FamillyChat/IFamillyChat.js +1 -1
- package/build/js/Services/Chat/ChatImplementations/GptChat/GptChat.js +184 -184
- package/build/js/Services/Chat/ChatImplementations/GptChat/GptChat.js.map +1 -1
- package/build/js/Services/Chat/ChatImplementations/GptChat/IGptChat.js +26 -26
- package/build/js/Services/Chat/ChatService.js +43 -43
- package/build/js/Services/Chat/ChatService.js.map +1 -1
- package/build/js/Services/Chat/IChatService.js +6 -6
- package/build/js/Services/Controller/ConnectedAppsService.js +117 -117
- package/build/js/Services/Controller/ConnectedAppsService.js.map +1 -1
- package/build/js/Services/Controller/ControllerConfigurationService.js +319 -319
- package/build/js/Services/Controller/ControllerConfigurationService.js.map +1 -1
- package/build/js/Services/Controller/ControllerExtensionsService.js +148 -148
- package/build/js/Services/Controller/ControllerExtensionsService.js.map +1 -1
- package/build/js/Services/Controller/FindControllerService.js +155 -155
- package/build/js/Services/Controller/FindControllerService.js.map +1 -1
- package/build/js/Services/Controller/GeolocationService.js +111 -111
- package/build/js/Services/Controller/GeolocationService.js.map +1 -1
- package/build/js/Services/Controller/IConnectedAppsService.js +24 -24
- package/build/js/Services/Controller/IControllerConfigurationService.js +1 -1
- package/build/js/Services/Controller/IControllerExtensionsService.js +1 -1
- package/build/js/Services/Controller/IGeolocationService.js +20 -20
- package/build/js/Services/DataMigrationService.js +169 -169
- package/build/js/Services/DataMigrationService.js.map +1 -1
- package/build/js/Services/Devices/ChannelsGroupsService.js +696 -696
- package/build/js/Services/Devices/ChannelsGroupsService.js.map +1 -1
- package/build/js/Services/Devices/Device.js +248 -248
- package/build/js/Services/Devices/Device.js.map +1 -1
- package/build/js/Services/Devices/DeviceChannel.js +304 -304
- package/build/js/Services/Devices/DeviceChannel.js.map +1 -1
- package/build/js/Services/Devices/DevicesService.js +1184 -1184
- package/build/js/Services/Devices/DevicesService.js.map +1 -1
- package/build/js/Services/Devices/IChannelsGroupsService.js +109 -109
- package/build/js/Services/Devices/IChannelsGroupsService.js.map +1 -1
- package/build/js/Services/Devices/IDevice.js +197 -197
- package/build/js/Services/Devices/IDeviceChannel.js +48 -48
- package/build/js/Services/Devices/IDeviceConfigService.js +1 -1
- package/build/js/Services/Devices/IDeviceState.d.ts +7 -1
- package/build/js/Services/Devices/IDeviceState.js +970 -963
- package/build/js/Services/Devices/IDeviceState.js.map +1 -1
- package/build/js/Services/Devices/IDeviceTask.js +36 -36
- package/build/js/Services/Devices/IDevicesService.js +9 -9
- package/build/js/Services/Devices/IManuallyPairedDevicesProtocolService.js +1 -1
- package/build/js/Services/Devices/IManuallyPairedDevicesService.js +1 -1
- package/build/js/Services/Devices/ManuallyPairedDevicesService.js +68 -68
- package/build/js/Services/Devices/ManuallyPairedDevicesService.js.map +1 -1
- package/build/js/Services/Devices/TaskExecutionResult.js +9 -9
- package/build/js/Services/Devices/Tasks/DeviceTask.js +42 -42
- package/build/js/Services/Devices/Tasks/Tasks.js +216 -216
- package/build/js/Services/Devices/dist/DevicesService.d.ts +17 -17
- package/build/js/Services/ExalusConnectionService.js +498 -498
- package/build/js/Services/ExalusConnectionService.js.map +1 -1
- package/build/js/Services/FieldChangeResult.js +51 -51
- package/build/js/Services/IAppStateService.js +66 -66
- package/build/js/Services/IExalusConnectionService.js +31 -31
- package/build/js/Services/ILocalStorageService.js +1 -1
- package/build/js/Services/IRemoteStorageService.js +8 -8
- package/build/js/Services/LocalNetworkExalusConnectionService.js +289 -289
- package/build/js/Services/LocalNetworkExalusConnectionService.js.map +1 -1
- package/build/js/Services/LocalStorageService.js +38 -38
- package/build/js/Services/LocalStorageService.js.map +1 -1
- package/build/js/Services/Logging/ILoggerService.js +8 -8
- package/build/js/Services/Logging/LoggerService.js +132 -132
- package/build/js/Services/Logging/LoggerService.js.map +1 -1
- package/build/js/Services/PictureInPicture.js +28 -28
- package/build/js/Services/PictureInPicture.js.map +1 -1
- package/build/js/Services/Pictures/IPicture.js +6 -6
- package/build/js/Services/Pictures/IPicturesService.js +1 -1
- package/build/js/Services/Pictures/Picture.js +50 -50
- package/build/js/Services/Pictures/PicturesService.js +441 -441
- package/build/js/Services/Pictures/PicturesService.js.map +1 -1
- package/build/js/Services/RemoteStorageService.js +122 -122
- package/build/js/Services/RemoteStorageService.js.map +1 -1
- package/build/js/Services/Scenes/IScenesService.js +7 -7
- package/build/js/Services/Scenes/LeftArgumentTypes.js +166 -166
- package/build/js/Services/Scenes/LeftArgumentTypes.js.map +1 -1
- package/build/js/Services/Scenes/SceneTaskTypes.js +32 -32
- package/build/js/Services/Scenes/Scenes.js +134 -134
- package/build/js/Services/Scenes/ScenesBuilder.js +1097 -1097
- package/build/js/Services/Scenes/ScenesBuilder.js.map +1 -1
- package/build/js/Services/Scenes/ScenesService.js +1131 -1131
- package/build/js/Services/Scenes/ScenesService.js.map +1 -1
- package/build/js/Services/Scenes/dist/ScenesService.d.ts +5 -5
- package/build/js/Services/Session/ISessionService.js +8 -8
- package/build/js/Services/Session/SessionService.js +222 -222
- package/build/js/Services/Session/SessionService.js.map +1 -1
- package/build/js/Services/StatesHistory/IStatesHistoryService.js +12 -12
- package/build/js/Services/StatesHistory/StatesHistory.js +75 -75
- package/build/js/Services/StatesHistory/StatesHistoryService.js +235 -235
- package/build/js/Services/StatesHistory/StatesHistoryService.js.map +1 -1
- package/build/js/Services/SupportedDevices/ISupportedDevicesService.js +115 -115
- package/build/js/Services/SupportedDevices/SupportedDevicesService.js +26 -26
- package/build/js/Services/Updates/CustomUpdateActions/ICustomUpdateActions.js +1 -1
- package/build/js/Services/Updates/IUpdateInfo.js +62 -62
- package/build/js/Services/Updates/IUpdatesProvider.js +48 -48
- package/build/js/Services/Updates/IUpdatesService.js +139 -139
- package/build/js/Services/Updates/UpdateProviderServices/IControllerModulesUpdatesProviderService.js +1 -1
- package/build/js/Services/Updates/UpdateProviderServices/IDeviceUpdateProviderService.js +1 -1
- package/build/js/Services/Updates/UpdateProviderServices/IUpdateProviderService.js +1 -1
- package/build/js/Services/Updates/UpdatesProvider.js +212 -212
- package/build/js/Services/Updates/UpdatesProvider.js.map +1 -1
- package/build/js/Services/Updates/UpdatesService.js +1487 -1487
- package/build/js/Services/Updates/UpdatesService.js.map +1 -1
- package/build/js/Services/Updates/dist/UpdatesService.d.ts +9 -9
- package/build/js/Services/Users/IUser.js +21 -21
- package/build/js/Services/Users/IUsersService.js +1 -1
- package/build/js/Services/Users/User.js +104 -104
- package/build/js/Services/Users/UsersService.js +302 -302
- package/build/js/Services/Users/UsersService.js.map +1 -1
- package/build/js/Services/WebApi/IWebApiCacheService.js +1 -1
- package/build/js/Services/WebApi/WebApiCacheService.js +42 -42
- package/build/js/Services/WebApi/WebApiCacheService.js.map +1 -1
- package/build/js/TypedEvent.js +23 -23
- package/build/js/TypedEvent.js.map +1 -1
- package/build/js/dist/Api.d.ts +12 -12
- package/build/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,1098 +1,1098 @@
|
|
|
1
|
-
import { Api } from "../../Api";
|
|
2
|
-
import { Guid } from "../../Guid";
|
|
3
|
-
import { Helpers } from "../../Helpers";
|
|
4
|
-
import { DeviceResponseType, DeviceTaskType } from "../Devices/IDevice";
|
|
5
|
-
import { EnergyMeasurementParameter } from "../Devices/IDeviceState";
|
|
6
|
-
import { DeviceControlFeature } from "../Devices/IDeviceTask";
|
|
7
|
-
import { LightRGBW, SetBlindMicroventilation, SetBlindOpenCloseTime, SetBlindPosition, SetFacadePosition, SetLightBrightness, SetLightBrightnessDynamicly, SetLightColor, SetLightTemperature, SetTemperature, TurnOnWithTime } from "../Devices/Tasks/Tasks";
|
|
8
|
-
import { LoggerService } from "../Logging/LoggerService";
|
|
9
|
-
import { ConditionInfoArgument, DeviceStateComparisonMethod, DeviceStateComparisonParams } from "./LeftArgumentTypes";
|
|
10
|
-
import { LockType } from "./SceneTaskTypes";
|
|
11
|
-
import { ConditionsTypes, DeviceStateType, HandledType, SceneTaskTypeNum, UnsupportedScenesDeviceState } from "./Scenes";
|
|
12
|
-
import { ScenesService } from "./ScenesService";
|
|
13
|
-
export class SequenceBuilder {
|
|
14
|
-
constructor(sequenceName, sequenceIcon = "Cube") {
|
|
15
|
-
this._result = null;
|
|
16
|
-
this._tmp = new SequenceRequestData();
|
|
17
|
-
this._tmpTask = null;
|
|
18
|
-
this._prevSeqGuid = "";
|
|
19
|
-
this._currentSeqGuid = "";
|
|
20
|
-
this._editingExistingSequence = false;
|
|
21
|
-
this._rawExistingSequenceTasks = null;
|
|
22
|
-
//Saved in case when we remove first argument by method RemoveArgument
|
|
23
|
-
this._sequenceName = "";
|
|
24
|
-
this._sequenceIcon = "";
|
|
25
|
-
this._service = Api.Get(ScenesService.ServiceName);
|
|
26
|
-
if (sequenceName) {
|
|
27
|
-
this._sequenceName = sequenceName;
|
|
28
|
-
this._sequenceIcon = sequenceIcon;
|
|
29
|
-
this._tmp.Guid = Guid.NewGuid();
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
/**
|
|
33
|
-
* Sets current (new or in edit) sequence name
|
|
34
|
-
* @param name name
|
|
35
|
-
*/
|
|
36
|
-
SetSequenceName(name) {
|
|
37
|
-
this._sequenceName = name;
|
|
38
|
-
if (this._editingExistingSequence && this._result != null) {
|
|
39
|
-
this._result.Name = name;
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
/**
|
|
43
|
-
* Sets current (new or in edit) sequence icon
|
|
44
|
-
* @param icon icon
|
|
45
|
-
*/
|
|
46
|
-
SetSequenceIcon(icon) {
|
|
47
|
-
this._sequenceIcon = icon;
|
|
48
|
-
if (this._editingExistingSequence && this._result != null) {
|
|
49
|
-
this._result.Icon = icon;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Gets next sequence from sequence chain
|
|
54
|
-
*/
|
|
55
|
-
GetNext() {
|
|
56
|
-
if (this._result == null)
|
|
57
|
-
return null;
|
|
58
|
-
if (this._currentSeqGuid == "") {
|
|
59
|
-
this._currentSeqGuid = this._result.Guid;
|
|
60
|
-
return this._service.MapSequence(JSON.parse(JSON.stringify(this._result)), true);
|
|
61
|
-
}
|
|
62
|
-
else {
|
|
63
|
-
const result = this.FindArgumentWithGuid(this._result, this._currentSeqGuid);
|
|
64
|
-
if (result == null) {
|
|
65
|
-
return null;
|
|
66
|
-
}
|
|
67
|
-
else {
|
|
68
|
-
if (result.RightArgumentType == ArgumentTypeNum.Condition) {
|
|
69
|
-
this._prevSeqGuid = this._currentSeqGuid;
|
|
70
|
-
this._currentSeqGuid = result.RightArgument.Guid;
|
|
71
|
-
return this._service.MapSequence(JSON.parse(JSON.stringify(result.RightArgument)), true);
|
|
72
|
-
}
|
|
73
|
-
else
|
|
74
|
-
return null;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Method allows to clone builder with all sqeuence atributes and tasks.
|
|
80
|
-
* Function re-generate all guids in chain and reset navigation to first element.
|
|
81
|
-
* @returns cloned builder (new object)
|
|
82
|
-
*/
|
|
83
|
-
CloneCurrentBuilder() {
|
|
84
|
-
const regenerateArgumentsGuids = (builder) => {
|
|
85
|
-
const regenerateGuids = (sequence) => {
|
|
86
|
-
sequence.Guid = Guid.NewGuid();
|
|
87
|
-
if (sequence.RightArgumentType == ArgumentTypeNum.Condition) {
|
|
88
|
-
regenerateGuids(sequence.RightArgument);
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
if (builder._result != null)
|
|
92
|
-
regenerateGuids(builder._result);
|
|
93
|
-
if (this._tmp != null)
|
|
94
|
-
this._tmp.Guid = Guid.NewGuid();
|
|
95
|
-
};
|
|
96
|
-
var clonedBuilder = new SequenceBuilder();
|
|
97
|
-
clonedBuilder._currentSeqGuid = "";
|
|
98
|
-
clonedBuilder._prevSeqGuid = "";
|
|
99
|
-
clonedBuilder._editingExistingSequence = structuredClone(this._editingExistingSequence);
|
|
100
|
-
clonedBuilder._rawExistingSequenceTasks = structuredClone(this._rawExistingSequenceTasks);
|
|
101
|
-
clonedBuilder._result = structuredClone(this._result);
|
|
102
|
-
clonedBuilder._sequenceIcon = structuredClone(this._sequenceIcon);
|
|
103
|
-
clonedBuilder._sequenceName = structuredClone(this._sequenceName);
|
|
104
|
-
;
|
|
105
|
-
clonedBuilder._tmp = structuredClone(this._tmp);
|
|
106
|
-
regenerateArgumentsGuids(clonedBuilder);
|
|
107
|
-
return clonedBuilder;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Gets previous sequence from sequence chain
|
|
111
|
-
*/
|
|
112
|
-
GetPrevious() {
|
|
113
|
-
let prevGuid = "";
|
|
114
|
-
const findArgumentWithGuidAndReturnPrevGuid = (sequence, sequenceGuid) => {
|
|
115
|
-
if (sequence.Guid == sequenceGuid) {
|
|
116
|
-
return { sequence: sequence, prevGuid: prevGuid };
|
|
117
|
-
}
|
|
118
|
-
else if (sequence.RightArgumentType == ArgumentTypeNum.Condition) {
|
|
119
|
-
prevGuid = sequence.Guid;
|
|
120
|
-
return findArgumentWithGuidAndReturnPrevGuid(sequence.RightArgument, sequenceGuid);
|
|
121
|
-
}
|
|
122
|
-
else
|
|
123
|
-
return null;
|
|
124
|
-
};
|
|
125
|
-
if (this._result == null)
|
|
126
|
-
return null;
|
|
127
|
-
if (this._currentSeqGuid == "" || this._prevSeqGuid == "")
|
|
128
|
-
return null;
|
|
129
|
-
const result = findArgumentWithGuidAndReturnPrevGuid(this._result, this._prevSeqGuid);
|
|
130
|
-
if (result == null) {
|
|
131
|
-
return null;
|
|
132
|
-
}
|
|
133
|
-
else {
|
|
134
|
-
this._currentSeqGuid = result.sequence.Guid;
|
|
135
|
-
this._prevSeqGuid = result.prevGuid;
|
|
136
|
-
return this._service.MapSequence(JSON.parse(JSON.stringify(result.sequence)), true);
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
/**
|
|
140
|
-
* Gets sequence by guid
|
|
141
|
-
* @param sequenceGuid sequence guid
|
|
142
|
-
*/
|
|
143
|
-
GetByGuid(sequenceGuid) {
|
|
144
|
-
if (this._result == null)
|
|
145
|
-
return null;
|
|
146
|
-
const arg = this.FindArgumentWithGuid(this._result, sequenceGuid);
|
|
147
|
-
if (arg == null)
|
|
148
|
-
return null;
|
|
149
|
-
return this._service.MapSequence(arg);
|
|
150
|
-
}
|
|
151
|
-
EditCurrentSequence(sequence) {
|
|
152
|
-
const findLastArgumentAndGetRawTasks = (sequence) => {
|
|
153
|
-
if (sequence.RightArgumentType == ArgumentTypeNum.Null) {
|
|
154
|
-
this._rawExistingSequenceTasks = JSON.parse(JSON.stringify(sequence.Tasks));
|
|
155
|
-
}
|
|
156
|
-
else
|
|
157
|
-
return findLastArgumentAndGetRawTasks(sequence.RightArgument);
|
|
158
|
-
};
|
|
159
|
-
this._editingExistingSequence = true;
|
|
160
|
-
findLastArgumentAndGetRawTasks(sequence._rawRequestData);
|
|
161
|
-
if (Object.hasOwn(sequence._rawRequestData, "Condition")) {
|
|
162
|
-
this._result = sequence._rawRequestData.Condition;
|
|
163
|
-
}
|
|
164
|
-
else {
|
|
165
|
-
this._result = sequence._rawRequestData;
|
|
166
|
-
}
|
|
167
|
-
//Getting raw tasks from last argument
|
|
168
|
-
return {
|
|
169
|
-
GetNext: () => this.GetNext(),
|
|
170
|
-
GetPrevious: () => this.GetPrevious(),
|
|
171
|
-
GetByGuid: (sequenceGuid) => this.GetByGuid(sequenceGuid),
|
|
172
|
-
RemoveSequence: (sequenceGuid) => this.RemoveSequenceByGuid(sequenceGuid),
|
|
173
|
-
ArgumentAsAstronomicalClockWithOffset: (arg, atMeetCondition, comparasion) => this.ArgumentAsAstronomicalClockWithOffset(arg, atMeetCondition, comparasion),
|
|
174
|
-
ArgumentAsDaysOfWeek: (arg, atMeetCondition, comparison) => this.ArgumentAsDaysOfWeek(arg, atMeetCondition, comparison),
|
|
175
|
-
ArgumentAsDeviceState: (arg, atMeetCondition, atMeetConditionTimeout, comparison = ConditionsTypes.Equal) => this.ArgumentAsDeviceState(arg, atMeetCondition, atMeetConditionTimeout, comparison),
|
|
176
|
-
ArgumentAsTime: (arg, atMeetCondition, comparison = ConditionsTypes.Equal) => this.ArgumentAsTime(arg, atMeetCondition, comparison),
|
|
177
|
-
ArgumentAsTimeSpan: (arg, comparison) => this.ArgumentAsTimeSpan(arg, comparison),
|
|
178
|
-
ArgumentAsSceneExecuted: (arg) => this.ArgumentAsSceneExecuted(arg),
|
|
179
|
-
RemoveTask: (taskGuid) => this.RemoveTask(taskGuid),
|
|
180
|
-
};
|
|
181
|
-
}
|
|
182
|
-
/**
|
|
183
|
-
* Function creates argument of type AstronomicalClockWithOffse in the argument chain
|
|
184
|
-
* @param arg
|
|
185
|
-
* @returns function that adds argument to end of chain
|
|
186
|
-
*/
|
|
187
|
-
ArgumentAsAstronomicalClockWithOffset(arg, atMeetCondition, comparasion) {
|
|
188
|
-
this._tmp.Guid = Guid.NewGuid();
|
|
189
|
-
this._tmp.HandledType = HandledType.AstronomicalClockWithOffset;
|
|
190
|
-
this._tmp.LeftArgumentType = ArgumentTypeNum.ArgumentAsAstronomicalClockWithOffset;
|
|
191
|
-
this._tmp.AtMeetCondition = atMeetCondition;
|
|
192
|
-
if (atMeetCondition && (comparasion != null && comparasion != ConditionsTypes.Equal)) {
|
|
193
|
-
throw new BadParametersScenesBuilderException("AtmeetCondition supports only comparation type 'Equal'.");
|
|
194
|
-
}
|
|
195
|
-
if (arg.Offset < -3600 || arg.Offset > 3600)
|
|
196
|
-
throw new BadParametersScenesBuilderException("Offset must be in range between -3600 and 3600 seconds.");
|
|
197
|
-
if (atMeetCondition)
|
|
198
|
-
this._tmp.ConditionType = ConditionsTypes.Equal;
|
|
199
|
-
else if (comparasion != null)
|
|
200
|
-
this._tmp.ConditionType = comparasion;
|
|
201
|
-
else
|
|
202
|
-
throw new BadParametersScenesBuilderException("Comparasion type must be provided if atMeetCondition is false!");
|
|
203
|
-
this._tmp.LeftArgument.Argument = arg;
|
|
204
|
-
this._tmp.LeftArgument.HandledType = ArgumentTypeNum.ArgumentAsAstronomicalClockWithOffset;
|
|
205
|
-
return {
|
|
206
|
-
AddArgument: () => this.AddSequence(),
|
|
207
|
-
EditArgument: (sequenceGuid) => this.EditSequence(sequenceGuid)
|
|
208
|
-
};
|
|
209
|
-
}
|
|
210
|
-
ArgumentAsActionWithEmptyCondition() {
|
|
211
|
-
this._tmp.Guid = Guid.NewGuid();
|
|
212
|
-
this._tmp.HandledType = HandledType.Unknown;
|
|
213
|
-
this._tmp.LeftArgumentType = ArgumentTypeNum.Null;
|
|
214
|
-
this._tmp.ConditionType = ConditionsTypes.Equal;
|
|
215
|
-
this._tmp.LeftArgument.Argument = null;
|
|
216
|
-
this._tmp.LeftArgument.HandledType = ArgumentTypeNum.Null;
|
|
217
|
-
this._tmp.Name = this._sequenceName;
|
|
218
|
-
this._tmp.Icon = this._sequenceIcon;
|
|
219
|
-
this._tmp.AtMeetCondition = false;
|
|
220
|
-
return {
|
|
221
|
-
AddArgument: () => this.AddSequence(),
|
|
222
|
-
EditArgument: (sequenceGuid) => this.EditSequence(sequenceGuid)
|
|
223
|
-
};
|
|
224
|
-
}
|
|
225
|
-
/**
|
|
226
|
-
* Function creates argument of type DayOfWeekArgument in the argument chain
|
|
227
|
-
* @param arg
|
|
228
|
-
* @param atMeetCondition
|
|
229
|
-
* @param comparison
|
|
230
|
-
* @returns function that adds argument to end of chain
|
|
231
|
-
*/
|
|
232
|
-
ArgumentAsDaysOfWeek(arg, atMeetCondition, comparison = ConditionsTypes.Equal) {
|
|
233
|
-
this._tmp.Guid = Guid.NewGuid();
|
|
234
|
-
this._tmp.HandledType = HandledType.DaysOfWeek;
|
|
235
|
-
this._tmp.LeftArgumentType = ArgumentTypeNum.ArgumentAsDaysOfWeek;
|
|
236
|
-
this._tmp.ConditionType = comparison;
|
|
237
|
-
this._tmp.LeftArgument.Argument = arg;
|
|
238
|
-
this._tmp.LeftArgument.HandledType = ArgumentTypeNum.ArgumentAsDaysOfWeek;
|
|
239
|
-
this._tmp.AtMeetCondition = atMeetCondition;
|
|
240
|
-
return {
|
|
241
|
-
AddArgument: () => this.AddSequence(),
|
|
242
|
-
EditArgument: (sequenceGuid) => this.EditSequence(sequenceGuid)
|
|
243
|
-
};
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Function creates argument of type SimpleTimeSpanArgument in the argument chain
|
|
247
|
-
* @param arg
|
|
248
|
-
* @param comparison
|
|
249
|
-
* @returns function that adds argument to end of chain
|
|
250
|
-
*/
|
|
251
|
-
ArgumentAsTimeSpan(arg, comparison = ConditionsTypes.Equal) {
|
|
252
|
-
this._tmp.Guid = Guid.NewGuid();
|
|
253
|
-
this._tmp.HandledType = HandledType.Timer;
|
|
254
|
-
this._tmp.LeftArgumentType = ArgumentTypeNum.ArgumentAsTimeSpan;
|
|
255
|
-
this._tmp.ConditionType = comparison;
|
|
256
|
-
this._tmp.AtMeetCondition = true;
|
|
257
|
-
this._tmp.LeftArgument.Argument = arg;
|
|
258
|
-
this._tmp.LeftArgument.HandledType = ArgumentTypeNum.ArgumentAsTimeSpan;
|
|
259
|
-
return {
|
|
260
|
-
AddArgument: () => this.AddSequence(),
|
|
261
|
-
EditArgument: (sequenceGuid) => this.EditSequence(sequenceGuid)
|
|
262
|
-
};
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Function creates argument of type ArgumentAsTime in the argument chain
|
|
266
|
-
* @param arg
|
|
267
|
-
* @param atMeetCondition
|
|
268
|
-
* @param comparison
|
|
269
|
-
* @returns function that adds argument to end of chain
|
|
270
|
-
*/
|
|
271
|
-
ArgumentAsTime(arg, atMeetCondition, comparison = ConditionsTypes.Equal) {
|
|
272
|
-
this._tmp.Guid = Guid.NewGuid();
|
|
273
|
-
this._tmp.HandledType = HandledType.Time;
|
|
274
|
-
this._tmp.LeftArgumentType = ArgumentTypeNum.ArgumentAsTime;
|
|
275
|
-
this._tmp.ConditionType = comparison;
|
|
276
|
-
this._tmp.AtMeetCondition = atMeetCondition;
|
|
277
|
-
this._tmp.LeftArgument.Argument = arg;
|
|
278
|
-
this._tmp.LeftArgument.HandledType = ArgumentTypeNum.ArgumentAsTime;
|
|
279
|
-
return {
|
|
280
|
-
AddArgument: () => this.AddSequence(),
|
|
281
|
-
EditArgument: (sequenceGuid) => this.EditSequence(sequenceGuid)
|
|
282
|
-
};
|
|
283
|
-
}
|
|
284
|
-
/**
|
|
285
|
-
* Function creates argument of type DeviceStateArgument in the argument chain
|
|
286
|
-
* @param arg
|
|
287
|
-
* @param atMeetCondition
|
|
288
|
-
* @param atMeetConditionTimeout
|
|
289
|
-
* @param comparison
|
|
290
|
-
* @returns function that adds argument to end of chain
|
|
291
|
-
*/
|
|
292
|
-
ArgumentAsDeviceState(arg, atMeetCondition, atMeetConditionTimeout, comparison = ConditionsTypes.Equal) {
|
|
293
|
-
this._tmp.Guid = Guid.NewGuid();
|
|
294
|
-
this._tmp.HandledType = HandledType.DeviceState;
|
|
295
|
-
this._tmp.LeftArgumentType = ArgumentTypeNum.ArgumentAsDeviceState;
|
|
296
|
-
this._tmp.ConditionType = comparison;
|
|
297
|
-
this._tmp.AtMeetCondition = atMeetCondition;
|
|
298
|
-
this._tmp.ConditionTimeout = atMeetConditionTimeout;
|
|
299
|
-
this._tmp.LeftArgument.Argument = this.GenerateDeviceStateArgument(arg);
|
|
300
|
-
this._tmp.LeftArgument.HandledType = ArgumentTypeNum.ArgumentAsDeviceState;
|
|
301
|
-
return {
|
|
302
|
-
AddArgument: () => this.AddSequence(),
|
|
303
|
-
EditArgument: (sequenceGuid) => this.EditSequence(sequenceGuid)
|
|
304
|
-
};
|
|
305
|
-
}
|
|
306
|
-
/**
|
|
307
|
-
* Function creates argument of type ArgumentAsSceneExecuted - this argument waits until given scene will be executed, then returns 'true' and allow to execute check rest of arguments in chain.
|
|
308
|
-
* @param arg
|
|
309
|
-
*/
|
|
310
|
-
ArgumentAsSceneExecuted(arg) {
|
|
311
|
-
this._tmp.Guid = Guid.NewGuid();
|
|
312
|
-
this._tmp.HandledType = HandledType.SceneExecuted;
|
|
313
|
-
this._tmp.LeftArgumentType = ArgumentTypeNum.ArgumentAsConditionInfo;
|
|
314
|
-
this._tmp.ConditionType = ConditionsTypes.Equal;
|
|
315
|
-
this._tmp.AtMeetCondition = true;
|
|
316
|
-
const argumentData = new ConditionInfoArgument();
|
|
317
|
-
argumentData.DeviceGuid = arg.DeviceGuid;
|
|
318
|
-
this._tmp.LeftArgument.Argument = argumentData;
|
|
319
|
-
this._tmp.LeftArgument.HandledType = ArgumentTypeNum.ArgumentAsConditionInfo;
|
|
320
|
-
return {
|
|
321
|
-
AddArgument: () => this.AddSequence(),
|
|
322
|
-
EditArgument: (sequenceGuid) => this.EditSequence(sequenceGuid)
|
|
323
|
-
};
|
|
324
|
-
}
|
|
325
|
-
GenerateDeviceStateArgument(arg) {
|
|
326
|
-
const result = new LeftArgumentDeviceStateRequestData();
|
|
327
|
-
result.Channel = arg.GetCheckDeviceState().Channel;
|
|
328
|
-
result.ComparisonMethod = arg.ComparisonMethod;
|
|
329
|
-
let rawParams = {};
|
|
330
|
-
let paramsIterable = arg.GetComparisonParams().entries();
|
|
331
|
-
for (const [param, paramVal] of paramsIterable) {
|
|
332
|
-
rawParams = Object.assign(Object.assign({}, rawParams), { [DeviceStateComparisonParams[param]]: paramVal.Value });
|
|
333
|
-
}
|
|
334
|
-
result.ComparisonParams = rawParams;
|
|
335
|
-
result.DeviceGuid = arg.DeviceGuid;
|
|
336
|
-
result.DeviceStateType = this.MapResponseTypeToDeviceStateType(arg.Type);
|
|
337
|
-
switch (arg.Type) {
|
|
338
|
-
case DeviceResponseType.BatteryState: {
|
|
339
|
-
result.CheckedDeviceState.State = arg.GetCheckDeviceState().State;
|
|
340
|
-
result.CheckedDeviceState.Percentage = arg.GetCheckDeviceState().Percentage;
|
|
341
|
-
break;
|
|
342
|
-
}
|
|
343
|
-
case DeviceResponseType.BinarySensorState: {
|
|
344
|
-
result.CheckedDeviceState.State = arg.GetCheckDeviceState().State;
|
|
345
|
-
break;
|
|
346
|
-
}
|
|
347
|
-
case DeviceResponseType.BlindPosition: {
|
|
348
|
-
result.CheckedDeviceState.Position = arg.GetCheckDeviceState().Position;
|
|
349
|
-
break;
|
|
350
|
-
}
|
|
351
|
-
case DeviceResponseType.LightBrightness: {
|
|
352
|
-
result.CheckedDeviceState.Brightness = arg.GetCheckDeviceState().Brightness;
|
|
353
|
-
break;
|
|
354
|
-
}
|
|
355
|
-
case DeviceResponseType.MeasuredBrightness: {
|
|
356
|
-
result.CheckedDeviceState.Brightness = arg.GetCheckDeviceState().Brightness;
|
|
357
|
-
break;
|
|
358
|
-
}
|
|
359
|
-
case DeviceResponseType.RemoteButtonState: {
|
|
360
|
-
result.CheckedDeviceState.State = arg.GetCheckDeviceState().State;
|
|
361
|
-
break;
|
|
362
|
-
}
|
|
363
|
-
case DeviceResponseType.ChannelOnOffState: {
|
|
364
|
-
result.CheckedDeviceState.State = arg.GetCheckDeviceState().State;
|
|
365
|
-
break;
|
|
366
|
-
}
|
|
367
|
-
case DeviceResponseType.DoorBellState: {
|
|
368
|
-
result.CheckedDeviceState.State = arg.GetCheckDeviceState().State;
|
|
369
|
-
break;
|
|
370
|
-
}
|
|
371
|
-
case DeviceResponseType.MeasuredEnergy: {
|
|
372
|
-
let rawParams = {};
|
|
373
|
-
let paramsIterable = arg.GetCheckDeviceState().MeasurementParameters.entries();
|
|
374
|
-
for (const [param, paramVal] of paramsIterable) {
|
|
375
|
-
rawParams = Object.assign(Object.assign({}, rawParams), { [EnergyMeasurementParameter[param]]: paramVal });
|
|
376
|
-
}
|
|
377
|
-
result.CheckedDeviceState.MeasurementParameters = rawParams;
|
|
378
|
-
break;
|
|
379
|
-
}
|
|
380
|
-
case DeviceResponseType.FloodSensorState: {
|
|
381
|
-
result.CheckedDeviceState.State = arg.GetCheckDeviceState().State;
|
|
382
|
-
break;
|
|
383
|
-
}
|
|
384
|
-
case DeviceResponseType.GatePosition: {
|
|
385
|
-
result.CheckedDeviceState.Position = arg.GetCheckDeviceState().Position;
|
|
386
|
-
result.CheckedDeviceState.PositionType = arg.GetCheckDeviceState().PositionType;
|
|
387
|
-
break;
|
|
388
|
-
}
|
|
389
|
-
case DeviceResponseType.LightColor: {
|
|
390
|
-
const st = arg.GetCheckDeviceState();
|
|
391
|
-
result.CheckedDeviceState.R = st.R;
|
|
392
|
-
result.CheckedDeviceState.G = st.G;
|
|
393
|
-
result.CheckedDeviceState.B = st.B;
|
|
394
|
-
break;
|
|
395
|
-
}
|
|
396
|
-
case DeviceResponseType.LightWarmth: {
|
|
397
|
-
result.CheckedDeviceState.Temperature = arg.GetCheckDeviceState().Temperature;
|
|
398
|
-
break;
|
|
399
|
-
}
|
|
400
|
-
case DeviceResponseType.ReedState: {
|
|
401
|
-
result.CheckedDeviceState.State = arg.GetCheckDeviceState().State;
|
|
402
|
-
break;
|
|
403
|
-
}
|
|
404
|
-
case DeviceResponseType.SmokeSensorState:
|
|
405
|
-
throw new UnsupportedScenesDeviceState("Unsupported device state!");
|
|
406
|
-
case DeviceResponseType.MeasuredTemperature: {
|
|
407
|
-
result.CheckedDeviceState.Temperature = arg.GetCheckDeviceState().Temperature;
|
|
408
|
-
break;
|
|
409
|
-
}
|
|
410
|
-
case DeviceResponseType.HumiditySensorState: {
|
|
411
|
-
result.CheckedDeviceState.Humidity = arg.GetCheckDeviceState().Humidity;
|
|
412
|
-
break;
|
|
413
|
-
}
|
|
414
|
-
case DeviceResponseType.BlindRemoteButtonState: {
|
|
415
|
-
result.CheckedDeviceState.State = arg.GetCheckDeviceState().State;
|
|
416
|
-
break;
|
|
417
|
-
}
|
|
418
|
-
case DeviceResponseType.LightRGBWState: {
|
|
419
|
-
let st = arg.GetCheckDeviceState();
|
|
420
|
-
result.CheckedDeviceState.R = st.R;
|
|
421
|
-
result.CheckedDeviceState.G = st.G;
|
|
422
|
-
result.CheckedDeviceState.B = st.B;
|
|
423
|
-
result.CheckedDeviceState.W = st.W;
|
|
424
|
-
break;
|
|
425
|
-
}
|
|
426
|
-
case DeviceResponseType.FacadeRemoteButtonState: {
|
|
427
|
-
result.CheckedDeviceState.State = arg.GetCheckDeviceState().State;
|
|
428
|
-
break;
|
|
429
|
-
}
|
|
430
|
-
case DeviceResponseType.MovementSensorState: {
|
|
431
|
-
let st = arg.GetCheckDeviceState();
|
|
432
|
-
result.CheckedDeviceState.Movement = st.Movement;
|
|
433
|
-
result.CheckedDeviceState.Intensity = st.Intensity;
|
|
434
|
-
break;
|
|
435
|
-
}
|
|
436
|
-
case DeviceResponseType.PressureSensorState: {
|
|
437
|
-
result.CheckedDeviceState.Pressure = arg.GetCheckDeviceState().Pressure;
|
|
438
|
-
result.CheckedDeviceState.PressureType = arg.GetCheckDeviceState().PressureType;
|
|
439
|
-
break;
|
|
440
|
-
}
|
|
441
|
-
case DeviceResponseType.WindSpeedState: {
|
|
442
|
-
result.CheckedDeviceState.Value = arg.GetCheckDeviceState().Value;
|
|
443
|
-
break;
|
|
444
|
-
}
|
|
445
|
-
case DeviceResponseType.CurrentWindThreshold: {
|
|
446
|
-
result.CheckedDeviceState.WindThreshold = arg.GetCheckDeviceState().WindThreshold;
|
|
447
|
-
break;
|
|
448
|
-
}
|
|
449
|
-
case DeviceResponseType.Unknown:
|
|
450
|
-
result.CheckedDeviceState = {};
|
|
451
|
-
break;
|
|
452
|
-
default:
|
|
453
|
-
throw new UnsupportedScenesDeviceState("Unsupported device state!");
|
|
454
|
-
}
|
|
455
|
-
return result;
|
|
456
|
-
}
|
|
457
|
-
MapResponseTypeToDeviceStateType(responseType) {
|
|
458
|
-
switch (responseType) {
|
|
459
|
-
case DeviceResponseType.BatteryState:
|
|
460
|
-
return DeviceStateType.BatteryState;
|
|
461
|
-
case DeviceResponseType.BinarySensorState:
|
|
462
|
-
return DeviceStateType.BinarySensor;
|
|
463
|
-
case DeviceResponseType.BlindPosition:
|
|
464
|
-
return DeviceStateType.BlindPosition;
|
|
465
|
-
case DeviceResponseType.LightBrightness:
|
|
466
|
-
return DeviceStateType.LightBrightness;
|
|
467
|
-
case DeviceResponseType.RemoteButtonState:
|
|
468
|
-
return DeviceStateType.ButtonState;
|
|
469
|
-
case DeviceResponseType.ChannelOnOffState:
|
|
470
|
-
return DeviceStateType.ChannelOnOff;
|
|
471
|
-
case DeviceResponseType.DoorBellState:
|
|
472
|
-
return DeviceStateType.DoorBell;
|
|
473
|
-
case DeviceResponseType.MeasuredEnergy:
|
|
474
|
-
return DeviceStateType.Energy;
|
|
475
|
-
case DeviceResponseType.FloodSensorState:
|
|
476
|
-
return DeviceStateType.FloodSensor;
|
|
477
|
-
case DeviceResponseType.GatePosition:
|
|
478
|
-
return DeviceStateType.GatePosition;
|
|
479
|
-
case DeviceResponseType.MeasuredBrightness:
|
|
480
|
-
return DeviceStateType.Brightness;
|
|
481
|
-
case DeviceResponseType.LightColor:
|
|
482
|
-
return DeviceStateType.LightColor;
|
|
483
|
-
case DeviceResponseType.LightWarmth:
|
|
484
|
-
return DeviceStateType.LightTemperature;
|
|
485
|
-
case DeviceResponseType.ReedState:
|
|
486
|
-
return DeviceStateType.ReedState;
|
|
487
|
-
case DeviceResponseType.SmokeSensorState:
|
|
488
|
-
return DeviceStateType.SmokeSensor;
|
|
489
|
-
case DeviceResponseType.MeasuredTemperature:
|
|
490
|
-
return DeviceStateType.Temperature;
|
|
491
|
-
case DeviceResponseType.HumiditySensorState:
|
|
492
|
-
return DeviceStateType.Humidity;
|
|
493
|
-
case DeviceResponseType.BlindRemoteButtonState:
|
|
494
|
-
return DeviceStateType.BlindsControlButton;
|
|
495
|
-
case DeviceResponseType.FacadeRemoteButtonState:
|
|
496
|
-
return DeviceStateType.FacadeControlButton;
|
|
497
|
-
case DeviceResponseType.MovementSensorState:
|
|
498
|
-
return DeviceStateType.Movement;
|
|
499
|
-
case DeviceResponseType.PressureSensorState:
|
|
500
|
-
return DeviceStateType.AirPressure;
|
|
501
|
-
case DeviceResponseType.WindSpeedState:
|
|
502
|
-
return DeviceStateType.WindSpeed;
|
|
503
|
-
case DeviceResponseType.CurrentWindThreshold:
|
|
504
|
-
return DeviceStateType.WindThreshold;
|
|
505
|
-
default:
|
|
506
|
-
return DeviceStateType.Unknown;
|
|
507
|
-
}
|
|
508
|
-
}
|
|
509
|
-
/**
|
|
510
|
-
* Function adds argument to the end of argument chain
|
|
511
|
-
* @returns Functions that coud create another argument, function that coud commit argument chain, current argument data.
|
|
512
|
-
*/
|
|
513
|
-
AddSequence() {
|
|
514
|
-
const findLastRightArgumentAndAddContition = (sequence, newData) => {
|
|
515
|
-
if (sequence.RightArgumentType == ArgumentTypeNum.Null) {
|
|
516
|
-
sequence.RightArgumentType = ArgumentTypeNum.Condition;
|
|
517
|
-
sequence.RightArgument = newData;
|
|
518
|
-
if (this._editingExistingSequence) {
|
|
519
|
-
if (this._rawExistingSequenceTasks != null) {
|
|
520
|
-
newData.Tasks = JSON.parse(JSON.stringify(this._rawExistingSequenceTasks));
|
|
521
|
-
sequence.Tasks = new TasksRequestData();
|
|
522
|
-
}
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
else
|
|
526
|
-
return findLastRightArgumentAndAddContition(sequence.RightArgument, newData);
|
|
527
|
-
};
|
|
528
|
-
//result null - root sequence
|
|
529
|
-
if (this._result == null) {
|
|
530
|
-
this._tmp.Name = this._sequenceName;
|
|
531
|
-
this._tmp.Icon = this._sequenceIcon;
|
|
532
|
-
this._result = this._tmp;
|
|
533
|
-
this._result.AtMeetCondition = true;
|
|
534
|
-
}
|
|
535
|
-
else
|
|
536
|
-
findLastRightArgumentAndAddContition(this._result, this._tmp);
|
|
537
|
-
const sequneceData = this._service.MapSequence(JSON.parse(JSON.stringify(this._tmp)));
|
|
538
|
-
this._tmp = new SequenceRequestData();
|
|
539
|
-
return {
|
|
540
|
-
GetNext: () => this.GetNext(),
|
|
541
|
-
GetPrevious: () => this.GetPrevious(),
|
|
542
|
-
GetByGuid: (sequenceGuid) => this.GetByGuid(sequenceGuid),
|
|
543
|
-
RemoveSequenceByGuid: (argumentGuid) => this.RemoveSequenceByGuid(argumentGuid),
|
|
544
|
-
Commit: () => this.Commit(),
|
|
545
|
-
ArgumentAsActionWithEmptyCondition: () => this.ArgumentAsActionWithEmptyCondition(),
|
|
546
|
-
ArgumentAsAstronomicalClockWithOffset: (arg, atMeetCondition, comparasion) => this.ArgumentAsAstronomicalClockWithOffset(arg, atMeetCondition, comparasion),
|
|
547
|
-
ArgumentAsDaysOfWeek: (arg, atMeetCondition, comparison) => this.ArgumentAsDaysOfWeek(arg, atMeetCondition, comparison),
|
|
548
|
-
ArgumentAsDeviceState: (arg, atMeetCondition, atMeetConditionTimeout, comparison = ConditionsTypes.Equal) => this.ArgumentAsDeviceState(arg, atMeetCondition, atMeetConditionTimeout, comparison),
|
|
549
|
-
ArgumentAsTime: (arg, atMeetCondition, comparison = ConditionsTypes.Equal) => this.ArgumentAsTime(arg, atMeetCondition, comparison),
|
|
550
|
-
ArgumentAsTimeSpan: (arg, comparison) => this.ArgumentAsTimeSpan(arg, comparison),
|
|
551
|
-
ArgumentAsSceneExecuted: (arg) => this.ArgumentAsSceneExecuted(arg),
|
|
552
|
-
SequenceData: sequneceData
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
EditSequence(sequenceGuid) {
|
|
556
|
-
const findLastArgumentWithGuidAndEditCondition = (sequence, newData) => {
|
|
557
|
-
if (sequence.Guid == sequenceGuid && sequence.ObjectType == ArgumentTypeNum.Condition) {
|
|
558
|
-
//Remap properties (needs in this format to keep reference to this._result, we changing only sequence properties without deattach root) newData is reference to this._tmp
|
|
559
|
-
sequence.AtMeetCondition = newData.AtMeetCondition;
|
|
560
|
-
sequence.ConditionTimeout = newData.ConditionTimeout;
|
|
561
|
-
sequence.ConditionType = newData.ConditionType;
|
|
562
|
-
sequence.ExecuteOnce = newData.ExecuteOnce;
|
|
563
|
-
sequence.HandledType = newData.HandledType;
|
|
564
|
-
sequence.IsDisabled = newData.IsDisabled;
|
|
565
|
-
sequence.LeftArgument = newData.LeftArgument;
|
|
566
|
-
sequence.LeftArgumentType = newData.LeftArgumentType;
|
|
567
|
-
sequence.ObjectType = newData.ObjectType;
|
|
568
|
-
sequence.Tasks = newData.Tasks;
|
|
569
|
-
//Keep settings that are not edited in this scope
|
|
570
|
-
newData.Guid = sequence.Guid;
|
|
571
|
-
newData.Icon = sequence.Icon;
|
|
572
|
-
newData.Name = sequence.Name;
|
|
573
|
-
}
|
|
574
|
-
else if (sequence.RightArgumentType == ArgumentTypeNum.Condition)
|
|
575
|
-
return findLastArgumentWithGuidAndEditCondition(sequence.RightArgument, newData);
|
|
576
|
-
else
|
|
577
|
-
throw new SequenceNotFoundScenesBuilderException(`Cannot edit sequence with given GUID ${sequenceGuid} - sequence not foud in chain`);
|
|
578
|
-
};
|
|
579
|
-
if (this._result == null)
|
|
580
|
-
throw new SequenceNotFoundScenesBuilderException(`Cannot edit sequence with given GUID ${sequenceGuid} - sequence not initialized (no root element)`);
|
|
581
|
-
findLastArgumentWithGuidAndEditCondition(this._result, this._tmp);
|
|
582
|
-
const sequneceData = this._service.MapSequence(JSON.parse(JSON.stringify(this._tmp)));
|
|
583
|
-
this._tmp = new SequenceRequestData();
|
|
584
|
-
console.log(`new tmp guid: ${this._tmp.Guid}`);
|
|
585
|
-
if (!this._result.AtMeetCondition)
|
|
586
|
-
this._result.AtMeetCondition = true;
|
|
587
|
-
return {
|
|
588
|
-
GetNext: () => this.GetNext(),
|
|
589
|
-
GetPrevious: () => this.GetPrevious(),
|
|
590
|
-
GetByGuid: (sequenceGuid) => this.GetByGuid(sequenceGuid),
|
|
591
|
-
RemoveSequenceByGuid: (sequenceGuid) => this.RemoveSequenceByGuid(sequenceGuid),
|
|
592
|
-
Commit: () => this.Commit(),
|
|
593
|
-
ArgumentAsActionWithEmptyCondition: () => this.ArgumentAsActionWithEmptyCondition(),
|
|
594
|
-
ArgumentAsAstronomicalClockWithOffset: (arg, atMeetCondition, comparasion) => this.ArgumentAsAstronomicalClockWithOffset(arg, atMeetCondition, comparasion),
|
|
595
|
-
ArgumentAsDaysOfWeek: (arg, atMeetCondition, comparison) => this.ArgumentAsDaysOfWeek(arg, atMeetCondition, comparison),
|
|
596
|
-
ArgumentAsDeviceState: (arg, atMeetCondition, atMeetConditionTimeout, comparison = ConditionsTypes.Equal) => this.ArgumentAsDeviceState(arg, atMeetCondition, atMeetConditionTimeout, comparison),
|
|
597
|
-
ArgumentAsTime: (arg, atMeetCondition, comparison = ConditionsTypes.Equal) => this.ArgumentAsTime(arg, atMeetCondition, comparison),
|
|
598
|
-
ArgumentAsTimeSpan: (arg, comparison) => this.ArgumentAsTimeSpan(arg, comparison),
|
|
599
|
-
ArgumentAsSceneExecuted: (arg) => this.ArgumentAsSceneExecuted(arg),
|
|
600
|
-
SequenceData: sequneceData
|
|
601
|
-
};
|
|
602
|
-
}
|
|
603
|
-
RemoveSequenceByGuid(sequenceGuid) {
|
|
604
|
-
let refToHead;
|
|
605
|
-
const fixNavigation = (sequence, sequenceGuid) => {
|
|
606
|
-
//navigation never used, don't need fix
|
|
607
|
-
if (this._currentSeqGuid == "" && this._prevSeqGuid == "")
|
|
608
|
-
return;
|
|
609
|
-
if (this._currentSeqGuid == sequenceGuid) {
|
|
610
|
-
this._currentSeqGuid = sequence.RightArgumentType == ArgumentTypeNum.Condition ? sequence.RightArgument.Guid : "";
|
|
611
|
-
this._prevSeqGuid = refToHead != null ? refToHead.Guid : "";
|
|
612
|
-
}
|
|
613
|
-
else if (this._prevSeqGuid == sequenceGuid) {
|
|
614
|
-
this._prevSeqGuid = refToHead != null ? refToHead.Guid : "";
|
|
615
|
-
}
|
|
616
|
-
};
|
|
617
|
-
const findRightArgumentAndRemoveArg = (sequence, sequenceGuid) => {
|
|
618
|
-
//Argument to remove
|
|
619
|
-
if (sequence.Guid == sequenceGuid) {
|
|
620
|
-
//no ref to head - root argument
|
|
621
|
-
if (refToHead == null)
|
|
622
|
-
this._result = null;
|
|
623
|
-
else {
|
|
624
|
-
refToHead.RightArgument = sequence.RightArgument;
|
|
625
|
-
refToHead.RightArgumentType = sequence.RightArgumentType;
|
|
626
|
-
}
|
|
627
|
-
fixNavigation(sequence, sequenceGuid);
|
|
628
|
-
}
|
|
629
|
-
else {
|
|
630
|
-
refToHead = sequence;
|
|
631
|
-
if (sequence.RightArgumentType == ArgumentTypeNum.Null)
|
|
632
|
-
throw new SequenceNotFoundScenesBuilderException(`Cannot remove sequence, sequence with given guid ${sequenceGuid} not found!`);
|
|
633
|
-
return findRightArgumentAndRemoveArg(sequence.RightArgument, sequenceGuid);
|
|
634
|
-
}
|
|
635
|
-
};
|
|
636
|
-
if (this._result == null)
|
|
637
|
-
throw new SequenceNotFoundScenesBuilderException("Cannot remove sequence, sequence not configured!");
|
|
638
|
-
//Removing root argument
|
|
639
|
-
if (this._result.Guid == sequenceGuid && this._result.RightArgumentType != ArgumentTypeNum.Null) {
|
|
640
|
-
this._result.RightArgument.Name = this._result.Name;
|
|
641
|
-
this._result.RightArgument.Icon = this._result.Icon;
|
|
642
|
-
this._result.RightArgument.Guid = this._result.Guid;
|
|
643
|
-
this._result = this._result.RightArgument;
|
|
644
|
-
this._result.AtMeetCondition = true;
|
|
645
|
-
fixNavigation(this._result, sequenceGuid);
|
|
646
|
-
}
|
|
647
|
-
else {
|
|
648
|
-
//Removing nested arguments
|
|
649
|
-
findRightArgumentAndRemoveArg(this._result, sequenceGuid);
|
|
650
|
-
}
|
|
651
|
-
return {
|
|
652
|
-
GetNext: () => this.GetNext(),
|
|
653
|
-
GetPrevious: () => this.GetPrevious(),
|
|
654
|
-
GetByGuid: (sequenceGuid) => this.GetByGuid(sequenceGuid),
|
|
655
|
-
RemoveSequenceByGuid: (sequenceGuid) => this.RemoveSequenceByGuid(sequenceGuid),
|
|
656
|
-
Commit: () => this.Commit(),
|
|
657
|
-
ArgumentAsActionWithEmptyCondition: () => this.ArgumentAsActionWithEmptyCondition(),
|
|
658
|
-
ArgumentAsAstronomicalClockWithOffset: (arg, atMeetCondition, comparasion) => this.ArgumentAsAstronomicalClockWithOffset(arg, atMeetCondition, comparasion),
|
|
659
|
-
ArgumentAsDaysOfWeek: (arg, atMeetCondition, comparison) => this.ArgumentAsDaysOfWeek(arg, atMeetCondition, comparison),
|
|
660
|
-
ArgumentAsDeviceState: (arg, atMeetCondition, atMeetConditionTimeout, comparison = ConditionsTypes.Equal) => this.ArgumentAsDeviceState(arg, atMeetCondition, atMeetConditionTimeout, comparison),
|
|
661
|
-
ArgumentAsTime: (arg, atMeetCondition, comparison = ConditionsTypes.Equal) => this.ArgumentAsTime(arg, atMeetCondition, comparison),
|
|
662
|
-
ArgumentAsTimeSpan: (arg, comparison) => this.ArgumentAsTimeSpan(arg, comparison),
|
|
663
|
-
ArgumentAsSceneExecuted: (arg) => this.ArgumentAsSceneExecuted(arg),
|
|
664
|
-
SequenceData: null
|
|
665
|
-
};
|
|
666
|
-
}
|
|
667
|
-
/**
|
|
668
|
-
* Functions commits modifications of arguments chain
|
|
669
|
-
* @returns
|
|
670
|
-
*/
|
|
671
|
-
Commit() {
|
|
672
|
-
const findLastRightArgumentAndMoveTasks = (sequence) => {
|
|
673
|
-
//Last arg
|
|
674
|
-
if (sequence.RightArgumentType == ArgumentTypeNum.Null) {
|
|
675
|
-
if (this._rawExistingSequenceTasks != null)
|
|
676
|
-
sequence.Tasks = this._rawExistingSequenceTasks;
|
|
677
|
-
}
|
|
678
|
-
else
|
|
679
|
-
return findLastRightArgumentAndMoveTasks(sequence.RightArgument);
|
|
680
|
-
};
|
|
681
|
-
if (this._result == null)
|
|
682
|
-
throw new SequenceNotFoundScenesBuilderException("Sequence are not initialized! Not found root sequence.");
|
|
683
|
-
//Move tasks to last argument - required while editing (removing or adding argument)
|
|
684
|
-
if (this._editingExistingSequence)
|
|
685
|
-
findLastRightArgumentAndMoveTasks(this._result);
|
|
686
|
-
return {
|
|
687
|
-
DeviceTask: (task) => this.DeviceTask(task),
|
|
688
|
-
DelayTask: (delay) => this.DelayTask(delay),
|
|
689
|
-
NotifyTask: (notification) => this.NotifyTask(notification),
|
|
690
|
-
LockExecutionTask: (lockTask) => this.LockExecutionTask(lockTask),
|
|
691
|
-
RemoveTask: (taskGuid) => this.RemoveTask(taskGuid),
|
|
692
|
-
Build: () => this.Build(),
|
|
693
|
-
BuildToISequence: () => this._service.MapSequence(JSON.parse(JSON.stringify(this._result)))
|
|
694
|
-
};
|
|
695
|
-
}
|
|
696
|
-
DeviceTask(task) {
|
|
697
|
-
this._tmpTask = this.ParseDeviceTask(task);
|
|
698
|
-
if (this._result == null)
|
|
699
|
-
throw new Error("No context!");
|
|
700
|
-
return {
|
|
701
|
-
AddTask: () => this.AddTask(),
|
|
702
|
-
EditTask: (taskId) => this.EditTask(taskId),
|
|
703
|
-
TaskId: Helpers.GenerateMd5(JSON.stringify(this._tmpTask)),
|
|
704
|
-
};
|
|
705
|
-
}
|
|
706
|
-
ParseDeviceTask(task) {
|
|
707
|
-
const tsk = new DeviceTaskRequestData();
|
|
708
|
-
tsk.Channel = task.Channel;
|
|
709
|
-
tsk.DeviceGuid = task.DeviceGuid;
|
|
710
|
-
tsk.ControlFeature = this.MapTaskTypeToControlFeature(task.TaskType);
|
|
711
|
-
tsk.Data = {};
|
|
712
|
-
tsk.Data.Channel = task.Channel;
|
|
713
|
-
if (task.TaskType == DeviceTaskType.SetBlindPosition || task instanceof SetBlindPosition) {
|
|
714
|
-
tsk.Data.Position = task.Position;
|
|
715
|
-
tsk.Data.Action = task.Action;
|
|
716
|
-
}
|
|
717
|
-
else if (task.TaskType == DeviceTaskType.SetLightColor || task instanceof SetLightColor) {
|
|
718
|
-
tsk.Data.R = task.R;
|
|
719
|
-
tsk.Data.G = task.G;
|
|
720
|
-
tsk.Data.B = task.B;
|
|
721
|
-
}
|
|
722
|
-
else if (task.TaskType == DeviceTaskType.SetLightTemperature || task instanceof SetLightTemperature) {
|
|
723
|
-
tsk.Data.Temperature = task.Temperature;
|
|
724
|
-
}
|
|
725
|
-
else if (task.TaskType == DeviceTaskType.SetLightBrightness || task instanceof SetLightBrightness) {
|
|
726
|
-
tsk.Data.Brightness = task.Brightness;
|
|
727
|
-
}
|
|
728
|
-
else if (task.TaskType == DeviceTaskType.SetTemperature || task instanceof SetTemperature) {
|
|
729
|
-
tsk.Data.Temperature = task.Temperature;
|
|
730
|
-
}
|
|
731
|
-
else if (task.TaskType == DeviceTaskType.TurnOnWithTime || task instanceof TurnOnWithTime) {
|
|
732
|
-
tsk.Data.SwitchOffDelaySeconds = task.SwitchOffDelaySeconds;
|
|
733
|
-
}
|
|
734
|
-
else if (task.TaskType == DeviceTaskType.SetLightBrightnessDynamicly || task instanceof SetLightBrightnessDynamicly) {
|
|
735
|
-
tsk.Data.Brightness = task.Brightness;
|
|
736
|
-
}
|
|
737
|
-
else if (task.TaskType == DeviceTaskType.SetBlindOpenCloseTime || task instanceof SetBlindOpenCloseTime) {
|
|
738
|
-
tsk.Data.CloseTime = task.Data.CloseTime;
|
|
739
|
-
tsk.Data.OpenTime = task.Data.OpenTime;
|
|
740
|
-
}
|
|
741
|
-
else if (task.TaskType == DeviceTaskType.SetBlindMicroventilation || task instanceof SetBlindMicroventilation) {
|
|
742
|
-
tsk.Data.Position = task.Position;
|
|
743
|
-
}
|
|
744
|
-
else if (task.TaskType == DeviceTaskType.SetFacadePosition || task instanceof SetFacadePosition) {
|
|
745
|
-
tsk.Data.FacadeAction = task.FacadeAction;
|
|
746
|
-
tsk.Data.Position = task.Position;
|
|
747
|
-
tsk.Data.Tilt = task.Tilt;
|
|
748
|
-
}
|
|
749
|
-
else if (task.TaskType == DeviceTaskType.LightRGBW || task instanceof LightRGBW) {
|
|
750
|
-
tsk.Data.R = task.Data.R;
|
|
751
|
-
tsk.Data.G = task.Data.G;
|
|
752
|
-
tsk.Data.B = task.Data.B;
|
|
753
|
-
tsk.Data.W = task.Data.W;
|
|
754
|
-
tsk.Data.Brightness = task.Data.Brightness;
|
|
755
|
-
}
|
|
756
|
-
//else
|
|
757
|
-
// throw new Error(`Unsupported device task, task type: ${task.TaskType} task object: ${task}!`);
|
|
758
|
-
return tsk;
|
|
759
|
-
}
|
|
760
|
-
DelayTask(delay) {
|
|
761
|
-
const task = new DelayTaskRequestData();
|
|
762
|
-
task.Delay = delay.Delay.Value;
|
|
763
|
-
this._tmpTask = task;
|
|
764
|
-
if (this._result == null)
|
|
765
|
-
throw new Error("No context!");
|
|
766
|
-
return {
|
|
767
|
-
AddTask: () => this.AddTask(),
|
|
768
|
-
EditTask: (taskGuid) => this.EditTask(taskGuid),
|
|
769
|
-
TaskId: Helpers.GenerateMd5(JSON.stringify(task)),
|
|
770
|
-
};
|
|
771
|
-
}
|
|
772
|
-
NotifyTask(notification) {
|
|
773
|
-
throw new UnsupportedArgumentScenesBuilderException("Funcionality will be available in the future.");
|
|
774
|
-
}
|
|
775
|
-
LockExecutionTask(lockTask) {
|
|
776
|
-
const task = new LockTaskTaskRequestData();
|
|
777
|
-
task.LockType = lockTask.LockType;
|
|
778
|
-
if (task.LockType == LockType.Timeout) {
|
|
779
|
-
if (task.LockEndHour != "00:00:00")
|
|
780
|
-
throw new UnsupportedArgumentScenesBuilderException("Parameter LockEndHour at lock type `Timeout` must be default!");
|
|
781
|
-
}
|
|
782
|
-
task.LockStartHour = lockTask.LockStartHour.Value;
|
|
783
|
-
task.LockEndHour = lockTask.LockEndHour.Value;
|
|
784
|
-
task.ResetLockScenesGuids = lockTask.ResetLockScenesGuids;
|
|
785
|
-
this._tmpTask = task;
|
|
786
|
-
if (this._result == null)
|
|
787
|
-
throw new Error("No context!");
|
|
788
|
-
return {
|
|
789
|
-
AddTask: () => this.AddTask(),
|
|
790
|
-
EditTask: (taskGuid) => this.EditTask(taskGuid),
|
|
791
|
-
TaskId: Helpers.GenerateMd5(JSON.stringify(task)),
|
|
792
|
-
};
|
|
793
|
-
}
|
|
794
|
-
AddTask() {
|
|
795
|
-
const findLastRightArgumentAndAddTask = (sequence) => {
|
|
796
|
-
//Last arg
|
|
797
|
-
if (sequence.RightArgumentType == ArgumentTypeNum.Null) {
|
|
798
|
-
if (this._tmpTask == null)
|
|
799
|
-
throw Error("No task context!");
|
|
800
|
-
if (sequence.Tasks.DevicesTasks === undefined || sequence.Tasks.DevicesTasks === null)
|
|
801
|
-
sequence.Tasks.DevicesTasks = [];
|
|
802
|
-
if (this._tmpTask instanceof DeviceTaskRequestData)
|
|
803
|
-
sequence.Tasks.DevicesTasks.push(structuredClone(this._tmpTask));
|
|
804
|
-
sequence.Tasks.ControllerTasks.push(structuredClone(this._tmpTask));
|
|
805
|
-
this._tmpTask = null;
|
|
806
|
-
Api.Get(LoggerService.ServiceName).Debug(`Task added to sequence: \n${JSON.stringify(this._tmpTask)} \ntasks on a list: \n${JSON.stringify(sequence.Tasks)}`);
|
|
807
|
-
}
|
|
808
|
-
else
|
|
809
|
-
return findLastRightArgumentAndAddTask(sequence.RightArgument);
|
|
810
|
-
};
|
|
811
|
-
if (this._result == null)
|
|
812
|
-
throw new Error("No context!");
|
|
813
|
-
findLastRightArgumentAndAddTask(this._result);
|
|
814
|
-
return {
|
|
815
|
-
DeviceTask: (task) => this.DeviceTask(task),
|
|
816
|
-
DelayTask: (delay) => this.DelayTask(delay),
|
|
817
|
-
NotifyTask: (notification) => this.NotifyTask(notification),
|
|
818
|
-
LockExecutionTask: (lockTask) => this.LockExecutionTask(lockTask),
|
|
819
|
-
RemoveTask: (taskId) => this.RemoveTask(taskId),
|
|
820
|
-
Build: () => this.Build(),
|
|
821
|
-
BuildToISequence: () => this._service.MapSequence(JSON.parse(JSON.stringify(this._result))),
|
|
822
|
-
};
|
|
823
|
-
}
|
|
824
|
-
EditTask(taskId) {
|
|
825
|
-
const findLastRightArgumentAndEditTask = (sequence) => {
|
|
826
|
-
//Last arg
|
|
827
|
-
if (sequence.RightArgumentType == ArgumentTypeNum.Null) {
|
|
828
|
-
if (this._tmpTask == null)
|
|
829
|
-
throw Error("No task context!");
|
|
830
|
-
if (sequence.Tasks.ControllerTasks == null || sequence.Tasks.ControllerTasks.length == 0)
|
|
831
|
-
throw new TaskNotFoundScenesBuilderException("Task not found, cannot edit!");
|
|
832
|
-
if (this._tmpTask instanceof DeviceTaskRequestData && sequence.Tasks.DevicesTasks != null)
|
|
833
|
-
sequence.Tasks.DevicesTasks = sequence.Tasks.DevicesTasks.map(dTask => Helpers.GenerateMd5(JSON.stringify(dTask)) == taskId ? structuredClone(this._tmpTask) : dTask);
|
|
834
|
-
sequence.Tasks.ControllerTasks = sequence.Tasks.ControllerTasks.map(cTask => Helpers.GenerateMd5(JSON.stringify(cTask)) == taskId ? structuredClone(this._tmpTask) : cTask);
|
|
835
|
-
this._tmpTask = null;
|
|
836
|
-
Api.Get(LoggerService.ServiceName).Debug(`Task edited in sequence: \n${JSON.stringify(this._tmpTask)} \ntasks on a list: \n${JSON.stringify(sequence.Tasks)}`);
|
|
837
|
-
}
|
|
838
|
-
else
|
|
839
|
-
return findLastRightArgumentAndEditTask(sequence.RightArgument);
|
|
840
|
-
};
|
|
841
|
-
if (this._result == null)
|
|
842
|
-
throw new Error("No context!");
|
|
843
|
-
findLastRightArgumentAndEditTask(this._result);
|
|
844
|
-
return {
|
|
845
|
-
DeviceTask: (task) => this.DeviceTask(task),
|
|
846
|
-
DelayTask: (delay) => this.DelayTask(delay),
|
|
847
|
-
NotifyTask: (notification) => this.NotifyTask(notification),
|
|
848
|
-
LockExecutionTask: (lockTask) => this.LockExecutionTask(lockTask),
|
|
849
|
-
RemoveTask: (taskGuid) => this.RemoveTask(taskGuid),
|
|
850
|
-
Build: () => this.Build(),
|
|
851
|
-
BuildToISequence: () => this._service.MapSequence(JSON.parse(JSON.stringify(this._result))),
|
|
852
|
-
};
|
|
853
|
-
}
|
|
854
|
-
RemoveTask(taskId) {
|
|
855
|
-
const findLastRightArgumentAndRemoveTask = (sequence, taskId) => {
|
|
856
|
-
//Last arg
|
|
857
|
-
if (sequence.RightArgumentType == ArgumentTypeNum.Null) {
|
|
858
|
-
const newTasks = sequence.Tasks.ControllerTasks.filter(t => Helpers.GenerateMd5(JSON.stringify(t)) != taskId);
|
|
859
|
-
if (newTasks == null)
|
|
860
|
-
sequence.Tasks.ControllerTasks = [];
|
|
861
|
-
else
|
|
862
|
-
sequence.Tasks.ControllerTasks = newTasks;
|
|
863
|
-
if (sequence.Tasks.DevicesTasks.any()) {
|
|
864
|
-
const newTasks = sequence.Tasks.DevicesTasks.filter(t => Helpers.GenerateMd5(JSON.stringify(t)) != taskId);
|
|
865
|
-
if (newTasks == null)
|
|
866
|
-
sequence.Tasks.DevicesTasks = [];
|
|
867
|
-
else
|
|
868
|
-
sequence.Tasks.DevicesTasks = newTasks;
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
else
|
|
872
|
-
return findLastRightArgumentAndRemoveTask(sequence.RightArgument, taskId);
|
|
873
|
-
};
|
|
874
|
-
if (this._result == null)
|
|
875
|
-
throw Error("Cannot remove task, sequence not configured!");
|
|
876
|
-
findLastRightArgumentAndRemoveTask(this._result, taskId);
|
|
877
|
-
}
|
|
878
|
-
MapTaskTypeToControlFeature(taskType) {
|
|
879
|
-
switch (taskType) {
|
|
880
|
-
case DeviceTaskType.Unknown:
|
|
881
|
-
throw new BadParametersScenesBuilderException("Unsupported task type!");
|
|
882
|
-
case DeviceTaskType.SetBlindPosition:
|
|
883
|
-
return DeviceControlFeature.SetBlindPosition;
|
|
884
|
-
case DeviceTaskType.SetBlindPositionSimple:
|
|
885
|
-
return DeviceControlFeature.SetBlindPosition;
|
|
886
|
-
case DeviceTaskType.SetBlindMicroventilation:
|
|
887
|
-
return DeviceControlFeature.SetBlindMicroventilation;
|
|
888
|
-
case DeviceTaskType.TurnOff:
|
|
889
|
-
return DeviceControlFeature.TurnOff;
|
|
890
|
-
case DeviceTaskType.TurnOn:
|
|
891
|
-
return DeviceControlFeature.TurnOn;
|
|
892
|
-
case DeviceTaskType.TurnOnWithTime:
|
|
893
|
-
return DeviceControlFeature.TurnOnWithTimeout;
|
|
894
|
-
case DeviceTaskType.TogleState:
|
|
895
|
-
return DeviceControlFeature.ToggleState;
|
|
896
|
-
case DeviceTaskType.SetLightBrightnessDynamicly:
|
|
897
|
-
return DeviceControlFeature.SetLightBrightnessDynamicly;
|
|
898
|
-
case DeviceTaskType.SetLightBrightness:
|
|
899
|
-
return DeviceControlFeature.SetLightBrightness;
|
|
900
|
-
case DeviceTaskType.SetLightColor:
|
|
901
|
-
return DeviceControlFeature.SetLightColor;
|
|
902
|
-
case DeviceTaskType.SetLightTemperature:
|
|
903
|
-
return DeviceControlFeature.SetLightTemperature;
|
|
904
|
-
case DeviceTaskType.PairDevice:
|
|
905
|
-
throw new BadParametersScenesBuilderException("Unsupported task type!");
|
|
906
|
-
case DeviceTaskType.UnpairDevice:
|
|
907
|
-
throw new BadParametersScenesBuilderException("Unsupported task type!");
|
|
908
|
-
case DeviceTaskType.IdentifyDevice:
|
|
909
|
-
return DeviceControlFeature.IdentifyDevice;
|
|
910
|
-
case DeviceTaskType.GetChannelsState:
|
|
911
|
-
return DeviceControlFeature.GetState;
|
|
912
|
-
case DeviceTaskType.GetPowerMeasurements:
|
|
913
|
-
throw new BadParametersScenesBuilderException("Unsupported task type!");
|
|
914
|
-
case DeviceTaskType.GetAvailableData:
|
|
915
|
-
throw new BadParametersScenesBuilderException("Unsupported task type!");
|
|
916
|
-
case DeviceTaskType.MultipleDataRequest:
|
|
917
|
-
throw new BadParametersScenesBuilderException("Unsupported task type!");
|
|
918
|
-
case DeviceTaskType.SetBlindOpenCloseTime:
|
|
919
|
-
return DeviceControlFeature.SetBlindOpenCloseTime;
|
|
920
|
-
case DeviceTaskType.SetTemperature:
|
|
921
|
-
return DeviceControlFeature.SetTemperature;
|
|
922
|
-
case DeviceTaskType.ChangeGatePositionPulse:
|
|
923
|
-
return DeviceControlFeature.GatePulse;
|
|
924
|
-
case DeviceTaskType.ChangeGatewayPositionPulse:
|
|
925
|
-
return DeviceControlFeature.GatewayPulse;
|
|
926
|
-
case DeviceTaskType.SetFacadePosition:
|
|
927
|
-
return DeviceControlFeature.SetFacadePositionAndTilt;
|
|
928
|
-
case DeviceTaskType.GetFacadeType:
|
|
929
|
-
return DeviceControlFeature.SetFacadePositionAndTilt;
|
|
930
|
-
case DeviceTaskType.LightRGBW:
|
|
931
|
-
return DeviceControlFeature.LightRGBW;
|
|
932
|
-
default:
|
|
933
|
-
throw new BadParametersScenesBuilderException("Unsupported task type!");
|
|
934
|
-
}
|
|
935
|
-
}
|
|
936
|
-
/**
|
|
937
|
-
* Function builds SequenceRequestData object, this obj. can be send via API to controller to modify or add sequence
|
|
938
|
-
* SequenceRequestData should be pass to EditSequenceAsync(sequence: SequenceRequestData) or CreateSequenceAsync(sequence: SequenceRequestData) methods in ScenesService;
|
|
939
|
-
* @returns
|
|
940
|
-
*/
|
|
941
|
-
Build() {
|
|
942
|
-
const findLastRightArgumentAndRemoveTaskGuid = (sequence) => {
|
|
943
|
-
//Last arg
|
|
944
|
-
if (sequence.RightArgumentType == ArgumentTypeNum.Null) {
|
|
945
|
-
sequence.Tasks.ControllerTasks = sequence.Tasks.ControllerTasks.map(t => {
|
|
946
|
-
if (Object.hasOwn(t, "_taskGuid"))
|
|
947
|
-
delete t["_taskGuid"];
|
|
948
|
-
return t;
|
|
949
|
-
});
|
|
950
|
-
}
|
|
951
|
-
else
|
|
952
|
-
return findLastRightArgumentAndRemoveTaskGuid(sequence.RightArgument);
|
|
953
|
-
};
|
|
954
|
-
if (this._result != null) {
|
|
955
|
-
//Removing taskGuid for internal purposes
|
|
956
|
-
findLastRightArgumentAndRemoveTaskGuid(this._result);
|
|
957
|
-
return this._result;
|
|
958
|
-
}
|
|
959
|
-
else
|
|
960
|
-
throw Error("Cannot build sequence, sequence not configured!");
|
|
961
|
-
}
|
|
962
|
-
FindArgumentWithGuid(sequence, sequenceGuid) {
|
|
963
|
-
if (sequence.Guid == sequenceGuid) {
|
|
964
|
-
return sequence;
|
|
965
|
-
}
|
|
966
|
-
else if (sequence.RightArgumentType == ArgumentTypeNum.Condition)
|
|
967
|
-
return this.FindArgumentWithGuid(sequence.RightArgument, sequenceGuid);
|
|
968
|
-
else
|
|
969
|
-
return null;
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
export class SequenceRequestData {
|
|
973
|
-
constructor() {
|
|
974
|
-
this.Tasks = new TasksRequestData();
|
|
975
|
-
this.Guid = "";
|
|
976
|
-
this.ObjectType = 1;
|
|
977
|
-
this.Name = "";
|
|
978
|
-
this.Icon = "";
|
|
979
|
-
this.AtMeetCondition = false;
|
|
980
|
-
this.ExecuteOnce = false;
|
|
981
|
-
this.IsDisabled = false;
|
|
982
|
-
this.HandledType = HandledType.Unknown;
|
|
983
|
-
this.ConditionType = ConditionsTypes.Unknown;
|
|
984
|
-
this.ConditionTimeout = 0;
|
|
985
|
-
this.LeftArgumentType = ArgumentTypeNum.Null;
|
|
986
|
-
this.RightArgumentType = ArgumentTypeNum.Null;
|
|
987
|
-
this.LeftArgument = new LeftArgumentRequestData({}, ArgumentTypeNum.Null);
|
|
988
|
-
this.RightArgument = new EmptySequenceRequestData();
|
|
989
|
-
}
|
|
990
|
-
}
|
|
991
|
-
class EmptySequenceRequestData {
|
|
992
|
-
constructor() {
|
|
993
|
-
this.HandledType = 0;
|
|
994
|
-
this.Argument = null;
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
class LeftArgumentRequestData {
|
|
998
|
-
constructor(argument, handledType) {
|
|
999
|
-
this.Argument = argument;
|
|
1000
|
-
this.HandledType = handledType;
|
|
1001
|
-
}
|
|
1002
|
-
}
|
|
1003
|
-
class LeftArgumentDeviceStateRequestData {
|
|
1004
|
-
constructor() {
|
|
1005
|
-
this.DeviceStateType = DeviceStateType.Unknown;
|
|
1006
|
-
this.Channel = 0;
|
|
1007
|
-
this.DeviceGuid = "";
|
|
1008
|
-
this.ComparisonMethod = DeviceStateComparisonMethod.Default;
|
|
1009
|
-
this.ComparisonParams = null;
|
|
1010
|
-
this.CheckedDeviceState = {};
|
|
1011
|
-
}
|
|
1012
|
-
}
|
|
1013
|
-
class TasksRequestData {
|
|
1014
|
-
constructor() {
|
|
1015
|
-
this.ControllerTasks = [];
|
|
1016
|
-
this.DevicesTasks = [];
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
class ControllerTaskRequestData {
|
|
1020
|
-
constructor() {
|
|
1021
|
-
this.RunParallel = false;
|
|
1022
|
-
this.TaskType = SceneTaskTypeNum.Unknown;
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
class DeviceTaskRequestData extends ControllerTaskRequestData {
|
|
1026
|
-
constructor() {
|
|
1027
|
-
super(...arguments);
|
|
1028
|
-
this.TaskType = SceneTaskTypeNum.DeviceTask;
|
|
1029
|
-
this.DeviceGuid = "";
|
|
1030
|
-
this.Channel = 0;
|
|
1031
|
-
this.ControlFeature = DeviceControlFeature.TurnOn;
|
|
1032
|
-
}
|
|
1033
|
-
}
|
|
1034
|
-
class DelayTaskRequestData extends ControllerTaskRequestData {
|
|
1035
|
-
constructor() {
|
|
1036
|
-
super(...arguments);
|
|
1037
|
-
this.TaskType = SceneTaskTypeNum.DelayTask;
|
|
1038
|
-
this.Delay = "00:00:00";
|
|
1039
|
-
}
|
|
1040
|
-
}
|
|
1041
|
-
class LockTaskTaskRequestData extends ControllerTaskRequestData {
|
|
1042
|
-
constructor() {
|
|
1043
|
-
super(...arguments);
|
|
1044
|
-
this.TaskType = SceneTaskTypeNum.LockExecution;
|
|
1045
|
-
this.LockType = LockType.Timeout;
|
|
1046
|
-
this.LockStartHour = "00:00:00";
|
|
1047
|
-
this.LockEndHour = "00:00:00";
|
|
1048
|
-
this.ResetLockScenesGuids = [];
|
|
1049
|
-
}
|
|
1050
|
-
}
|
|
1051
|
-
var ArgumentTypeNum;
|
|
1052
|
-
(function (ArgumentTypeNum) {
|
|
1053
|
-
ArgumentTypeNum[ArgumentTypeNum["Null"] = 0] = "Null";
|
|
1054
|
-
ArgumentTypeNum[ArgumentTypeNum["Condition"] = 1] = "Condition";
|
|
1055
|
-
ArgumentTypeNum[ArgumentTypeNum["ConditionGroup"] = 2] = "ConditionGroup";
|
|
1056
|
-
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsInt"] = 3] = "ArgumentAsInt";
|
|
1057
|
-
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsTimeSpan"] = 4] = "ArgumentAsTimeSpan";
|
|
1058
|
-
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsBoolean"] = 5] = "ArgumentAsBoolean";
|
|
1059
|
-
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsTimeout"] = 6] = "ArgumentAsTimeout";
|
|
1060
|
-
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsDayOfWeek"] = 7] = "ArgumentAsDayOfWeek";
|
|
1061
|
-
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsDaysOfWeek"] = 8] = "ArgumentAsDaysOfWeek";
|
|
1062
|
-
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsAstronomicalClock"] = 9] = "ArgumentAsAstronomicalClock";
|
|
1063
|
-
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsTime"] = 10] = "ArgumentAsTime";
|
|
1064
|
-
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsDeviceState"] = 11] = "ArgumentAsDeviceState";
|
|
1065
|
-
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsNumber"] = 12] = "ArgumentAsNumber";
|
|
1066
|
-
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsAstronomicalClockWithOffset"] = 13] = "ArgumentAsAstronomicalClockWithOffset";
|
|
1067
|
-
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsConditionInfo"] = 14] = "ArgumentAsConditionInfo";
|
|
1068
|
-
})(ArgumentTypeNum || (ArgumentTypeNum = {}));
|
|
1069
|
-
//Errors
|
|
1070
|
-
export class BadParametersScenesBuilderException extends Error {
|
|
1071
|
-
constructor(message) {
|
|
1072
|
-
super(message);
|
|
1073
|
-
this.message = message;
|
|
1074
|
-
this.name = "BadParametersScenesBuilderException";
|
|
1075
|
-
}
|
|
1076
|
-
}
|
|
1077
|
-
export class SequenceNotFoundScenesBuilderException extends Error {
|
|
1078
|
-
constructor(message) {
|
|
1079
|
-
super(message);
|
|
1080
|
-
this.message = message;
|
|
1081
|
-
this.name = "SequenceNotFoundScenesBuilderException";
|
|
1082
|
-
}
|
|
1083
|
-
}
|
|
1084
|
-
export class TaskNotFoundScenesBuilderException extends Error {
|
|
1085
|
-
constructor(message) {
|
|
1086
|
-
super(message);
|
|
1087
|
-
this.message = message;
|
|
1088
|
-
this.name = "TaskNotFoundScenesBuilderException";
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
export class UnsupportedArgumentScenesBuilderException extends Error {
|
|
1092
|
-
constructor(message) {
|
|
1093
|
-
super(message);
|
|
1094
|
-
this.message = message;
|
|
1095
|
-
this.name = "UnsupportedArgumentScenesBuilderException";
|
|
1096
|
-
}
|
|
1097
|
-
}
|
|
1
|
+
import { Api } from "../../Api";
|
|
2
|
+
import { Guid } from "../../Guid";
|
|
3
|
+
import { Helpers } from "../../Helpers";
|
|
4
|
+
import { DeviceResponseType, DeviceTaskType } from "../Devices/IDevice";
|
|
5
|
+
import { EnergyMeasurementParameter } from "../Devices/IDeviceState";
|
|
6
|
+
import { DeviceControlFeature } from "../Devices/IDeviceTask";
|
|
7
|
+
import { LightRGBW, SetBlindMicroventilation, SetBlindOpenCloseTime, SetBlindPosition, SetFacadePosition, SetLightBrightness, SetLightBrightnessDynamicly, SetLightColor, SetLightTemperature, SetTemperature, TurnOnWithTime } from "../Devices/Tasks/Tasks";
|
|
8
|
+
import { LoggerService } from "../Logging/LoggerService";
|
|
9
|
+
import { ConditionInfoArgument, DeviceStateComparisonMethod, DeviceStateComparisonParams } from "./LeftArgumentTypes";
|
|
10
|
+
import { LockType } from "./SceneTaskTypes";
|
|
11
|
+
import { ConditionsTypes, DeviceStateType, HandledType, SceneTaskTypeNum, UnsupportedScenesDeviceState } from "./Scenes";
|
|
12
|
+
import { ScenesService } from "./ScenesService";
|
|
13
|
+
export class SequenceBuilder {
|
|
14
|
+
constructor(sequenceName, sequenceIcon = "Cube") {
|
|
15
|
+
this._result = null;
|
|
16
|
+
this._tmp = new SequenceRequestData();
|
|
17
|
+
this._tmpTask = null;
|
|
18
|
+
this._prevSeqGuid = "";
|
|
19
|
+
this._currentSeqGuid = "";
|
|
20
|
+
this._editingExistingSequence = false;
|
|
21
|
+
this._rawExistingSequenceTasks = null;
|
|
22
|
+
//Saved in case when we remove first argument by method RemoveArgument
|
|
23
|
+
this._sequenceName = "";
|
|
24
|
+
this._sequenceIcon = "";
|
|
25
|
+
this._service = Api.Get(ScenesService.ServiceName);
|
|
26
|
+
if (sequenceName) {
|
|
27
|
+
this._sequenceName = sequenceName;
|
|
28
|
+
this._sequenceIcon = sequenceIcon;
|
|
29
|
+
this._tmp.Guid = Guid.NewGuid();
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Sets current (new or in edit) sequence name
|
|
34
|
+
* @param name name
|
|
35
|
+
*/
|
|
36
|
+
SetSequenceName(name) {
|
|
37
|
+
this._sequenceName = name;
|
|
38
|
+
if (this._editingExistingSequence && this._result != null) {
|
|
39
|
+
this._result.Name = name;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Sets current (new or in edit) sequence icon
|
|
44
|
+
* @param icon icon
|
|
45
|
+
*/
|
|
46
|
+
SetSequenceIcon(icon) {
|
|
47
|
+
this._sequenceIcon = icon;
|
|
48
|
+
if (this._editingExistingSequence && this._result != null) {
|
|
49
|
+
this._result.Icon = icon;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Gets next sequence from sequence chain
|
|
54
|
+
*/
|
|
55
|
+
GetNext() {
|
|
56
|
+
if (this._result == null)
|
|
57
|
+
return null;
|
|
58
|
+
if (this._currentSeqGuid == "") {
|
|
59
|
+
this._currentSeqGuid = this._result.Guid;
|
|
60
|
+
return this._service.MapSequence(JSON.parse(JSON.stringify(this._result)), true);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
const result = this.FindArgumentWithGuid(this._result, this._currentSeqGuid);
|
|
64
|
+
if (result == null) {
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
if (result.RightArgumentType == ArgumentTypeNum.Condition) {
|
|
69
|
+
this._prevSeqGuid = this._currentSeqGuid;
|
|
70
|
+
this._currentSeqGuid = result.RightArgument.Guid;
|
|
71
|
+
return this._service.MapSequence(JSON.parse(JSON.stringify(result.RightArgument)), true);
|
|
72
|
+
}
|
|
73
|
+
else
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Method allows to clone builder with all sqeuence atributes and tasks.
|
|
80
|
+
* Function re-generate all guids in chain and reset navigation to first element.
|
|
81
|
+
* @returns cloned builder (new object)
|
|
82
|
+
*/
|
|
83
|
+
CloneCurrentBuilder() {
|
|
84
|
+
const regenerateArgumentsGuids = (builder) => {
|
|
85
|
+
const regenerateGuids = (sequence) => {
|
|
86
|
+
sequence.Guid = Guid.NewGuid();
|
|
87
|
+
if (sequence.RightArgumentType == ArgumentTypeNum.Condition) {
|
|
88
|
+
regenerateGuids(sequence.RightArgument);
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
if (builder._result != null)
|
|
92
|
+
regenerateGuids(builder._result);
|
|
93
|
+
if (this._tmp != null)
|
|
94
|
+
this._tmp.Guid = Guid.NewGuid();
|
|
95
|
+
};
|
|
96
|
+
var clonedBuilder = new SequenceBuilder();
|
|
97
|
+
clonedBuilder._currentSeqGuid = "";
|
|
98
|
+
clonedBuilder._prevSeqGuid = "";
|
|
99
|
+
clonedBuilder._editingExistingSequence = structuredClone(this._editingExistingSequence);
|
|
100
|
+
clonedBuilder._rawExistingSequenceTasks = structuredClone(this._rawExistingSequenceTasks);
|
|
101
|
+
clonedBuilder._result = structuredClone(this._result);
|
|
102
|
+
clonedBuilder._sequenceIcon = structuredClone(this._sequenceIcon);
|
|
103
|
+
clonedBuilder._sequenceName = structuredClone(this._sequenceName);
|
|
104
|
+
;
|
|
105
|
+
clonedBuilder._tmp = structuredClone(this._tmp);
|
|
106
|
+
regenerateArgumentsGuids(clonedBuilder);
|
|
107
|
+
return clonedBuilder;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Gets previous sequence from sequence chain
|
|
111
|
+
*/
|
|
112
|
+
GetPrevious() {
|
|
113
|
+
let prevGuid = "";
|
|
114
|
+
const findArgumentWithGuidAndReturnPrevGuid = (sequence, sequenceGuid) => {
|
|
115
|
+
if (sequence.Guid == sequenceGuid) {
|
|
116
|
+
return { sequence: sequence, prevGuid: prevGuid };
|
|
117
|
+
}
|
|
118
|
+
else if (sequence.RightArgumentType == ArgumentTypeNum.Condition) {
|
|
119
|
+
prevGuid = sequence.Guid;
|
|
120
|
+
return findArgumentWithGuidAndReturnPrevGuid(sequence.RightArgument, sequenceGuid);
|
|
121
|
+
}
|
|
122
|
+
else
|
|
123
|
+
return null;
|
|
124
|
+
};
|
|
125
|
+
if (this._result == null)
|
|
126
|
+
return null;
|
|
127
|
+
if (this._currentSeqGuid == "" || this._prevSeqGuid == "")
|
|
128
|
+
return null;
|
|
129
|
+
const result = findArgumentWithGuidAndReturnPrevGuid(this._result, this._prevSeqGuid);
|
|
130
|
+
if (result == null) {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
else {
|
|
134
|
+
this._currentSeqGuid = result.sequence.Guid;
|
|
135
|
+
this._prevSeqGuid = result.prevGuid;
|
|
136
|
+
return this._service.MapSequence(JSON.parse(JSON.stringify(result.sequence)), true);
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Gets sequence by guid
|
|
141
|
+
* @param sequenceGuid sequence guid
|
|
142
|
+
*/
|
|
143
|
+
GetByGuid(sequenceGuid) {
|
|
144
|
+
if (this._result == null)
|
|
145
|
+
return null;
|
|
146
|
+
const arg = this.FindArgumentWithGuid(this._result, sequenceGuid);
|
|
147
|
+
if (arg == null)
|
|
148
|
+
return null;
|
|
149
|
+
return this._service.MapSequence(arg);
|
|
150
|
+
}
|
|
151
|
+
EditCurrentSequence(sequence) {
|
|
152
|
+
const findLastArgumentAndGetRawTasks = (sequence) => {
|
|
153
|
+
if (sequence.RightArgumentType == ArgumentTypeNum.Null) {
|
|
154
|
+
this._rawExistingSequenceTasks = JSON.parse(JSON.stringify(sequence.Tasks));
|
|
155
|
+
}
|
|
156
|
+
else
|
|
157
|
+
return findLastArgumentAndGetRawTasks(sequence.RightArgument);
|
|
158
|
+
};
|
|
159
|
+
this._editingExistingSequence = true;
|
|
160
|
+
findLastArgumentAndGetRawTasks(sequence._rawRequestData);
|
|
161
|
+
if (Object.hasOwn(sequence._rawRequestData, "Condition")) {
|
|
162
|
+
this._result = sequence._rawRequestData.Condition;
|
|
163
|
+
}
|
|
164
|
+
else {
|
|
165
|
+
this._result = sequence._rawRequestData;
|
|
166
|
+
}
|
|
167
|
+
//Getting raw tasks from last argument
|
|
168
|
+
return {
|
|
169
|
+
GetNext: () => this.GetNext(),
|
|
170
|
+
GetPrevious: () => this.GetPrevious(),
|
|
171
|
+
GetByGuid: (sequenceGuid) => this.GetByGuid(sequenceGuid),
|
|
172
|
+
RemoveSequence: (sequenceGuid) => this.RemoveSequenceByGuid(sequenceGuid),
|
|
173
|
+
ArgumentAsAstronomicalClockWithOffset: (arg, atMeetCondition, comparasion) => this.ArgumentAsAstronomicalClockWithOffset(arg, atMeetCondition, comparasion),
|
|
174
|
+
ArgumentAsDaysOfWeek: (arg, atMeetCondition, comparison) => this.ArgumentAsDaysOfWeek(arg, atMeetCondition, comparison),
|
|
175
|
+
ArgumentAsDeviceState: (arg, atMeetCondition, atMeetConditionTimeout, comparison = ConditionsTypes.Equal) => this.ArgumentAsDeviceState(arg, atMeetCondition, atMeetConditionTimeout, comparison),
|
|
176
|
+
ArgumentAsTime: (arg, atMeetCondition, comparison = ConditionsTypes.Equal) => this.ArgumentAsTime(arg, atMeetCondition, comparison),
|
|
177
|
+
ArgumentAsTimeSpan: (arg, comparison) => this.ArgumentAsTimeSpan(arg, comparison),
|
|
178
|
+
ArgumentAsSceneExecuted: (arg) => this.ArgumentAsSceneExecuted(arg),
|
|
179
|
+
RemoveTask: (taskGuid) => this.RemoveTask(taskGuid),
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Function creates argument of type AstronomicalClockWithOffse in the argument chain
|
|
184
|
+
* @param arg
|
|
185
|
+
* @returns function that adds argument to end of chain
|
|
186
|
+
*/
|
|
187
|
+
ArgumentAsAstronomicalClockWithOffset(arg, atMeetCondition, comparasion) {
|
|
188
|
+
this._tmp.Guid = Guid.NewGuid();
|
|
189
|
+
this._tmp.HandledType = HandledType.AstronomicalClockWithOffset;
|
|
190
|
+
this._tmp.LeftArgumentType = ArgumentTypeNum.ArgumentAsAstronomicalClockWithOffset;
|
|
191
|
+
this._tmp.AtMeetCondition = atMeetCondition;
|
|
192
|
+
if (atMeetCondition && (comparasion != null && comparasion != ConditionsTypes.Equal)) {
|
|
193
|
+
throw new BadParametersScenesBuilderException("AtmeetCondition supports only comparation type 'Equal'.");
|
|
194
|
+
}
|
|
195
|
+
if (arg.Offset < -3600 || arg.Offset > 3600)
|
|
196
|
+
throw new BadParametersScenesBuilderException("Offset must be in range between -3600 and 3600 seconds.");
|
|
197
|
+
if (atMeetCondition)
|
|
198
|
+
this._tmp.ConditionType = ConditionsTypes.Equal;
|
|
199
|
+
else if (comparasion != null)
|
|
200
|
+
this._tmp.ConditionType = comparasion;
|
|
201
|
+
else
|
|
202
|
+
throw new BadParametersScenesBuilderException("Comparasion type must be provided if atMeetCondition is false!");
|
|
203
|
+
this._tmp.LeftArgument.Argument = arg;
|
|
204
|
+
this._tmp.LeftArgument.HandledType = ArgumentTypeNum.ArgumentAsAstronomicalClockWithOffset;
|
|
205
|
+
return {
|
|
206
|
+
AddArgument: () => this.AddSequence(),
|
|
207
|
+
EditArgument: (sequenceGuid) => this.EditSequence(sequenceGuid)
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
ArgumentAsActionWithEmptyCondition() {
|
|
211
|
+
this._tmp.Guid = Guid.NewGuid();
|
|
212
|
+
this._tmp.HandledType = HandledType.Unknown;
|
|
213
|
+
this._tmp.LeftArgumentType = ArgumentTypeNum.Null;
|
|
214
|
+
this._tmp.ConditionType = ConditionsTypes.Equal;
|
|
215
|
+
this._tmp.LeftArgument.Argument = null;
|
|
216
|
+
this._tmp.LeftArgument.HandledType = ArgumentTypeNum.Null;
|
|
217
|
+
this._tmp.Name = this._sequenceName;
|
|
218
|
+
this._tmp.Icon = this._sequenceIcon;
|
|
219
|
+
this._tmp.AtMeetCondition = false;
|
|
220
|
+
return {
|
|
221
|
+
AddArgument: () => this.AddSequence(),
|
|
222
|
+
EditArgument: (sequenceGuid) => this.EditSequence(sequenceGuid)
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* Function creates argument of type DayOfWeekArgument in the argument chain
|
|
227
|
+
* @param arg
|
|
228
|
+
* @param atMeetCondition
|
|
229
|
+
* @param comparison
|
|
230
|
+
* @returns function that adds argument to end of chain
|
|
231
|
+
*/
|
|
232
|
+
ArgumentAsDaysOfWeek(arg, atMeetCondition, comparison = ConditionsTypes.Equal) {
|
|
233
|
+
this._tmp.Guid = Guid.NewGuid();
|
|
234
|
+
this._tmp.HandledType = HandledType.DaysOfWeek;
|
|
235
|
+
this._tmp.LeftArgumentType = ArgumentTypeNum.ArgumentAsDaysOfWeek;
|
|
236
|
+
this._tmp.ConditionType = comparison;
|
|
237
|
+
this._tmp.LeftArgument.Argument = arg;
|
|
238
|
+
this._tmp.LeftArgument.HandledType = ArgumentTypeNum.ArgumentAsDaysOfWeek;
|
|
239
|
+
this._tmp.AtMeetCondition = atMeetCondition;
|
|
240
|
+
return {
|
|
241
|
+
AddArgument: () => this.AddSequence(),
|
|
242
|
+
EditArgument: (sequenceGuid) => this.EditSequence(sequenceGuid)
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Function creates argument of type SimpleTimeSpanArgument in the argument chain
|
|
247
|
+
* @param arg
|
|
248
|
+
* @param comparison
|
|
249
|
+
* @returns function that adds argument to end of chain
|
|
250
|
+
*/
|
|
251
|
+
ArgumentAsTimeSpan(arg, comparison = ConditionsTypes.Equal) {
|
|
252
|
+
this._tmp.Guid = Guid.NewGuid();
|
|
253
|
+
this._tmp.HandledType = HandledType.Timer;
|
|
254
|
+
this._tmp.LeftArgumentType = ArgumentTypeNum.ArgumentAsTimeSpan;
|
|
255
|
+
this._tmp.ConditionType = comparison;
|
|
256
|
+
this._tmp.AtMeetCondition = true;
|
|
257
|
+
this._tmp.LeftArgument.Argument = arg;
|
|
258
|
+
this._tmp.LeftArgument.HandledType = ArgumentTypeNum.ArgumentAsTimeSpan;
|
|
259
|
+
return {
|
|
260
|
+
AddArgument: () => this.AddSequence(),
|
|
261
|
+
EditArgument: (sequenceGuid) => this.EditSequence(sequenceGuid)
|
|
262
|
+
};
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Function creates argument of type ArgumentAsTime in the argument chain
|
|
266
|
+
* @param arg
|
|
267
|
+
* @param atMeetCondition
|
|
268
|
+
* @param comparison
|
|
269
|
+
* @returns function that adds argument to end of chain
|
|
270
|
+
*/
|
|
271
|
+
ArgumentAsTime(arg, atMeetCondition, comparison = ConditionsTypes.Equal) {
|
|
272
|
+
this._tmp.Guid = Guid.NewGuid();
|
|
273
|
+
this._tmp.HandledType = HandledType.Time;
|
|
274
|
+
this._tmp.LeftArgumentType = ArgumentTypeNum.ArgumentAsTime;
|
|
275
|
+
this._tmp.ConditionType = comparison;
|
|
276
|
+
this._tmp.AtMeetCondition = atMeetCondition;
|
|
277
|
+
this._tmp.LeftArgument.Argument = arg;
|
|
278
|
+
this._tmp.LeftArgument.HandledType = ArgumentTypeNum.ArgumentAsTime;
|
|
279
|
+
return {
|
|
280
|
+
AddArgument: () => this.AddSequence(),
|
|
281
|
+
EditArgument: (sequenceGuid) => this.EditSequence(sequenceGuid)
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
/**
|
|
285
|
+
* Function creates argument of type DeviceStateArgument in the argument chain
|
|
286
|
+
* @param arg
|
|
287
|
+
* @param atMeetCondition
|
|
288
|
+
* @param atMeetConditionTimeout
|
|
289
|
+
* @param comparison
|
|
290
|
+
* @returns function that adds argument to end of chain
|
|
291
|
+
*/
|
|
292
|
+
ArgumentAsDeviceState(arg, atMeetCondition, atMeetConditionTimeout, comparison = ConditionsTypes.Equal) {
|
|
293
|
+
this._tmp.Guid = Guid.NewGuid();
|
|
294
|
+
this._tmp.HandledType = HandledType.DeviceState;
|
|
295
|
+
this._tmp.LeftArgumentType = ArgumentTypeNum.ArgumentAsDeviceState;
|
|
296
|
+
this._tmp.ConditionType = comparison;
|
|
297
|
+
this._tmp.AtMeetCondition = atMeetCondition;
|
|
298
|
+
this._tmp.ConditionTimeout = atMeetConditionTimeout;
|
|
299
|
+
this._tmp.LeftArgument.Argument = this.GenerateDeviceStateArgument(arg);
|
|
300
|
+
this._tmp.LeftArgument.HandledType = ArgumentTypeNum.ArgumentAsDeviceState;
|
|
301
|
+
return {
|
|
302
|
+
AddArgument: () => this.AddSequence(),
|
|
303
|
+
EditArgument: (sequenceGuid) => this.EditSequence(sequenceGuid)
|
|
304
|
+
};
|
|
305
|
+
}
|
|
306
|
+
/**
|
|
307
|
+
* Function creates argument of type ArgumentAsSceneExecuted - this argument waits until given scene will be executed, then returns 'true' and allow to execute check rest of arguments in chain.
|
|
308
|
+
* @param arg
|
|
309
|
+
*/
|
|
310
|
+
ArgumentAsSceneExecuted(arg) {
|
|
311
|
+
this._tmp.Guid = Guid.NewGuid();
|
|
312
|
+
this._tmp.HandledType = HandledType.SceneExecuted;
|
|
313
|
+
this._tmp.LeftArgumentType = ArgumentTypeNum.ArgumentAsConditionInfo;
|
|
314
|
+
this._tmp.ConditionType = ConditionsTypes.Equal;
|
|
315
|
+
this._tmp.AtMeetCondition = true;
|
|
316
|
+
const argumentData = new ConditionInfoArgument();
|
|
317
|
+
argumentData.DeviceGuid = arg.DeviceGuid;
|
|
318
|
+
this._tmp.LeftArgument.Argument = argumentData;
|
|
319
|
+
this._tmp.LeftArgument.HandledType = ArgumentTypeNum.ArgumentAsConditionInfo;
|
|
320
|
+
return {
|
|
321
|
+
AddArgument: () => this.AddSequence(),
|
|
322
|
+
EditArgument: (sequenceGuid) => this.EditSequence(sequenceGuid)
|
|
323
|
+
};
|
|
324
|
+
}
|
|
325
|
+
GenerateDeviceStateArgument(arg) {
|
|
326
|
+
const result = new LeftArgumentDeviceStateRequestData();
|
|
327
|
+
result.Channel = arg.GetCheckDeviceState().Channel;
|
|
328
|
+
result.ComparisonMethod = arg.ComparisonMethod;
|
|
329
|
+
let rawParams = {};
|
|
330
|
+
let paramsIterable = arg.GetComparisonParams().entries();
|
|
331
|
+
for (const [param, paramVal] of paramsIterable) {
|
|
332
|
+
rawParams = Object.assign(Object.assign({}, rawParams), { [DeviceStateComparisonParams[param]]: paramVal.Value });
|
|
333
|
+
}
|
|
334
|
+
result.ComparisonParams = rawParams;
|
|
335
|
+
result.DeviceGuid = arg.DeviceGuid;
|
|
336
|
+
result.DeviceStateType = this.MapResponseTypeToDeviceStateType(arg.Type);
|
|
337
|
+
switch (arg.Type) {
|
|
338
|
+
case DeviceResponseType.BatteryState: {
|
|
339
|
+
result.CheckedDeviceState.State = arg.GetCheckDeviceState().State;
|
|
340
|
+
result.CheckedDeviceState.Percentage = arg.GetCheckDeviceState().Percentage;
|
|
341
|
+
break;
|
|
342
|
+
}
|
|
343
|
+
case DeviceResponseType.BinarySensorState: {
|
|
344
|
+
result.CheckedDeviceState.State = arg.GetCheckDeviceState().State;
|
|
345
|
+
break;
|
|
346
|
+
}
|
|
347
|
+
case DeviceResponseType.BlindPosition: {
|
|
348
|
+
result.CheckedDeviceState.Position = arg.GetCheckDeviceState().Position;
|
|
349
|
+
break;
|
|
350
|
+
}
|
|
351
|
+
case DeviceResponseType.LightBrightness: {
|
|
352
|
+
result.CheckedDeviceState.Brightness = arg.GetCheckDeviceState().Brightness;
|
|
353
|
+
break;
|
|
354
|
+
}
|
|
355
|
+
case DeviceResponseType.MeasuredBrightness: {
|
|
356
|
+
result.CheckedDeviceState.Brightness = arg.GetCheckDeviceState().Brightness;
|
|
357
|
+
break;
|
|
358
|
+
}
|
|
359
|
+
case DeviceResponseType.RemoteButtonState: {
|
|
360
|
+
result.CheckedDeviceState.State = arg.GetCheckDeviceState().State;
|
|
361
|
+
break;
|
|
362
|
+
}
|
|
363
|
+
case DeviceResponseType.ChannelOnOffState: {
|
|
364
|
+
result.CheckedDeviceState.State = arg.GetCheckDeviceState().State;
|
|
365
|
+
break;
|
|
366
|
+
}
|
|
367
|
+
case DeviceResponseType.DoorBellState: {
|
|
368
|
+
result.CheckedDeviceState.State = arg.GetCheckDeviceState().State;
|
|
369
|
+
break;
|
|
370
|
+
}
|
|
371
|
+
case DeviceResponseType.MeasuredEnergy: {
|
|
372
|
+
let rawParams = {};
|
|
373
|
+
let paramsIterable = arg.GetCheckDeviceState().MeasurementParameters.entries();
|
|
374
|
+
for (const [param, paramVal] of paramsIterable) {
|
|
375
|
+
rawParams = Object.assign(Object.assign({}, rawParams), { [EnergyMeasurementParameter[param]]: paramVal });
|
|
376
|
+
}
|
|
377
|
+
result.CheckedDeviceState.MeasurementParameters = rawParams;
|
|
378
|
+
break;
|
|
379
|
+
}
|
|
380
|
+
case DeviceResponseType.FloodSensorState: {
|
|
381
|
+
result.CheckedDeviceState.State = arg.GetCheckDeviceState().State;
|
|
382
|
+
break;
|
|
383
|
+
}
|
|
384
|
+
case DeviceResponseType.GatePosition: {
|
|
385
|
+
result.CheckedDeviceState.Position = arg.GetCheckDeviceState().Position;
|
|
386
|
+
result.CheckedDeviceState.PositionType = arg.GetCheckDeviceState().PositionType;
|
|
387
|
+
break;
|
|
388
|
+
}
|
|
389
|
+
case DeviceResponseType.LightColor: {
|
|
390
|
+
const st = arg.GetCheckDeviceState();
|
|
391
|
+
result.CheckedDeviceState.R = st.R;
|
|
392
|
+
result.CheckedDeviceState.G = st.G;
|
|
393
|
+
result.CheckedDeviceState.B = st.B;
|
|
394
|
+
break;
|
|
395
|
+
}
|
|
396
|
+
case DeviceResponseType.LightWarmth: {
|
|
397
|
+
result.CheckedDeviceState.Temperature = arg.GetCheckDeviceState().Temperature;
|
|
398
|
+
break;
|
|
399
|
+
}
|
|
400
|
+
case DeviceResponseType.ReedState: {
|
|
401
|
+
result.CheckedDeviceState.State = arg.GetCheckDeviceState().State;
|
|
402
|
+
break;
|
|
403
|
+
}
|
|
404
|
+
case DeviceResponseType.SmokeSensorState:
|
|
405
|
+
throw new UnsupportedScenesDeviceState("Unsupported device state!");
|
|
406
|
+
case DeviceResponseType.MeasuredTemperature: {
|
|
407
|
+
result.CheckedDeviceState.Temperature = arg.GetCheckDeviceState().Temperature;
|
|
408
|
+
break;
|
|
409
|
+
}
|
|
410
|
+
case DeviceResponseType.HumiditySensorState: {
|
|
411
|
+
result.CheckedDeviceState.Humidity = arg.GetCheckDeviceState().Humidity;
|
|
412
|
+
break;
|
|
413
|
+
}
|
|
414
|
+
case DeviceResponseType.BlindRemoteButtonState: {
|
|
415
|
+
result.CheckedDeviceState.State = arg.GetCheckDeviceState().State;
|
|
416
|
+
break;
|
|
417
|
+
}
|
|
418
|
+
case DeviceResponseType.LightRGBWState: {
|
|
419
|
+
let st = arg.GetCheckDeviceState();
|
|
420
|
+
result.CheckedDeviceState.R = st.R;
|
|
421
|
+
result.CheckedDeviceState.G = st.G;
|
|
422
|
+
result.CheckedDeviceState.B = st.B;
|
|
423
|
+
result.CheckedDeviceState.W = st.W;
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
case DeviceResponseType.FacadeRemoteButtonState: {
|
|
427
|
+
result.CheckedDeviceState.State = arg.GetCheckDeviceState().State;
|
|
428
|
+
break;
|
|
429
|
+
}
|
|
430
|
+
case DeviceResponseType.MovementSensorState: {
|
|
431
|
+
let st = arg.GetCheckDeviceState();
|
|
432
|
+
result.CheckedDeviceState.Movement = st.Movement;
|
|
433
|
+
result.CheckedDeviceState.Intensity = st.Intensity;
|
|
434
|
+
break;
|
|
435
|
+
}
|
|
436
|
+
case DeviceResponseType.PressureSensorState: {
|
|
437
|
+
result.CheckedDeviceState.Pressure = arg.GetCheckDeviceState().Pressure;
|
|
438
|
+
result.CheckedDeviceState.PressureType = arg.GetCheckDeviceState().PressureType;
|
|
439
|
+
break;
|
|
440
|
+
}
|
|
441
|
+
case DeviceResponseType.WindSpeedState: {
|
|
442
|
+
result.CheckedDeviceState.Value = arg.GetCheckDeviceState().Value;
|
|
443
|
+
break;
|
|
444
|
+
}
|
|
445
|
+
case DeviceResponseType.CurrentWindThreshold: {
|
|
446
|
+
result.CheckedDeviceState.WindThreshold = arg.GetCheckDeviceState().WindThreshold;
|
|
447
|
+
break;
|
|
448
|
+
}
|
|
449
|
+
case DeviceResponseType.Unknown:
|
|
450
|
+
result.CheckedDeviceState = {};
|
|
451
|
+
break;
|
|
452
|
+
default:
|
|
453
|
+
throw new UnsupportedScenesDeviceState("Unsupported device state!");
|
|
454
|
+
}
|
|
455
|
+
return result;
|
|
456
|
+
}
|
|
457
|
+
MapResponseTypeToDeviceStateType(responseType) {
|
|
458
|
+
switch (responseType) {
|
|
459
|
+
case DeviceResponseType.BatteryState:
|
|
460
|
+
return DeviceStateType.BatteryState;
|
|
461
|
+
case DeviceResponseType.BinarySensorState:
|
|
462
|
+
return DeviceStateType.BinarySensor;
|
|
463
|
+
case DeviceResponseType.BlindPosition:
|
|
464
|
+
return DeviceStateType.BlindPosition;
|
|
465
|
+
case DeviceResponseType.LightBrightness:
|
|
466
|
+
return DeviceStateType.LightBrightness;
|
|
467
|
+
case DeviceResponseType.RemoteButtonState:
|
|
468
|
+
return DeviceStateType.ButtonState;
|
|
469
|
+
case DeviceResponseType.ChannelOnOffState:
|
|
470
|
+
return DeviceStateType.ChannelOnOff;
|
|
471
|
+
case DeviceResponseType.DoorBellState:
|
|
472
|
+
return DeviceStateType.DoorBell;
|
|
473
|
+
case DeviceResponseType.MeasuredEnergy:
|
|
474
|
+
return DeviceStateType.Energy;
|
|
475
|
+
case DeviceResponseType.FloodSensorState:
|
|
476
|
+
return DeviceStateType.FloodSensor;
|
|
477
|
+
case DeviceResponseType.GatePosition:
|
|
478
|
+
return DeviceStateType.GatePosition;
|
|
479
|
+
case DeviceResponseType.MeasuredBrightness:
|
|
480
|
+
return DeviceStateType.Brightness;
|
|
481
|
+
case DeviceResponseType.LightColor:
|
|
482
|
+
return DeviceStateType.LightColor;
|
|
483
|
+
case DeviceResponseType.LightWarmth:
|
|
484
|
+
return DeviceStateType.LightTemperature;
|
|
485
|
+
case DeviceResponseType.ReedState:
|
|
486
|
+
return DeviceStateType.ReedState;
|
|
487
|
+
case DeviceResponseType.SmokeSensorState:
|
|
488
|
+
return DeviceStateType.SmokeSensor;
|
|
489
|
+
case DeviceResponseType.MeasuredTemperature:
|
|
490
|
+
return DeviceStateType.Temperature;
|
|
491
|
+
case DeviceResponseType.HumiditySensorState:
|
|
492
|
+
return DeviceStateType.Humidity;
|
|
493
|
+
case DeviceResponseType.BlindRemoteButtonState:
|
|
494
|
+
return DeviceStateType.BlindsControlButton;
|
|
495
|
+
case DeviceResponseType.FacadeRemoteButtonState:
|
|
496
|
+
return DeviceStateType.FacadeControlButton;
|
|
497
|
+
case DeviceResponseType.MovementSensorState:
|
|
498
|
+
return DeviceStateType.Movement;
|
|
499
|
+
case DeviceResponseType.PressureSensorState:
|
|
500
|
+
return DeviceStateType.AirPressure;
|
|
501
|
+
case DeviceResponseType.WindSpeedState:
|
|
502
|
+
return DeviceStateType.WindSpeed;
|
|
503
|
+
case DeviceResponseType.CurrentWindThreshold:
|
|
504
|
+
return DeviceStateType.WindThreshold;
|
|
505
|
+
default:
|
|
506
|
+
return DeviceStateType.Unknown;
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
/**
|
|
510
|
+
* Function adds argument to the end of argument chain
|
|
511
|
+
* @returns Functions that coud create another argument, function that coud commit argument chain, current argument data.
|
|
512
|
+
*/
|
|
513
|
+
AddSequence() {
|
|
514
|
+
const findLastRightArgumentAndAddContition = (sequence, newData) => {
|
|
515
|
+
if (sequence.RightArgumentType == ArgumentTypeNum.Null) {
|
|
516
|
+
sequence.RightArgumentType = ArgumentTypeNum.Condition;
|
|
517
|
+
sequence.RightArgument = newData;
|
|
518
|
+
if (this._editingExistingSequence) {
|
|
519
|
+
if (this._rawExistingSequenceTasks != null) {
|
|
520
|
+
newData.Tasks = JSON.parse(JSON.stringify(this._rawExistingSequenceTasks));
|
|
521
|
+
sequence.Tasks = new TasksRequestData();
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
else
|
|
526
|
+
return findLastRightArgumentAndAddContition(sequence.RightArgument, newData);
|
|
527
|
+
};
|
|
528
|
+
//result null - root sequence
|
|
529
|
+
if (this._result == null) {
|
|
530
|
+
this._tmp.Name = this._sequenceName;
|
|
531
|
+
this._tmp.Icon = this._sequenceIcon;
|
|
532
|
+
this._result = this._tmp;
|
|
533
|
+
this._result.AtMeetCondition = true;
|
|
534
|
+
}
|
|
535
|
+
else
|
|
536
|
+
findLastRightArgumentAndAddContition(this._result, this._tmp);
|
|
537
|
+
const sequneceData = this._service.MapSequence(JSON.parse(JSON.stringify(this._tmp)));
|
|
538
|
+
this._tmp = new SequenceRequestData();
|
|
539
|
+
return {
|
|
540
|
+
GetNext: () => this.GetNext(),
|
|
541
|
+
GetPrevious: () => this.GetPrevious(),
|
|
542
|
+
GetByGuid: (sequenceGuid) => this.GetByGuid(sequenceGuid),
|
|
543
|
+
RemoveSequenceByGuid: (argumentGuid) => this.RemoveSequenceByGuid(argumentGuid),
|
|
544
|
+
Commit: () => this.Commit(),
|
|
545
|
+
ArgumentAsActionWithEmptyCondition: () => this.ArgumentAsActionWithEmptyCondition(),
|
|
546
|
+
ArgumentAsAstronomicalClockWithOffset: (arg, atMeetCondition, comparasion) => this.ArgumentAsAstronomicalClockWithOffset(arg, atMeetCondition, comparasion),
|
|
547
|
+
ArgumentAsDaysOfWeek: (arg, atMeetCondition, comparison) => this.ArgumentAsDaysOfWeek(arg, atMeetCondition, comparison),
|
|
548
|
+
ArgumentAsDeviceState: (arg, atMeetCondition, atMeetConditionTimeout, comparison = ConditionsTypes.Equal) => this.ArgumentAsDeviceState(arg, atMeetCondition, atMeetConditionTimeout, comparison),
|
|
549
|
+
ArgumentAsTime: (arg, atMeetCondition, comparison = ConditionsTypes.Equal) => this.ArgumentAsTime(arg, atMeetCondition, comparison),
|
|
550
|
+
ArgumentAsTimeSpan: (arg, comparison) => this.ArgumentAsTimeSpan(arg, comparison),
|
|
551
|
+
ArgumentAsSceneExecuted: (arg) => this.ArgumentAsSceneExecuted(arg),
|
|
552
|
+
SequenceData: sequneceData
|
|
553
|
+
};
|
|
554
|
+
}
|
|
555
|
+
EditSequence(sequenceGuid) {
|
|
556
|
+
const findLastArgumentWithGuidAndEditCondition = (sequence, newData) => {
|
|
557
|
+
if (sequence.Guid == sequenceGuid && sequence.ObjectType == ArgumentTypeNum.Condition) {
|
|
558
|
+
//Remap properties (needs in this format to keep reference to this._result, we changing only sequence properties without deattach root) newData is reference to this._tmp
|
|
559
|
+
sequence.AtMeetCondition = newData.AtMeetCondition;
|
|
560
|
+
sequence.ConditionTimeout = newData.ConditionTimeout;
|
|
561
|
+
sequence.ConditionType = newData.ConditionType;
|
|
562
|
+
sequence.ExecuteOnce = newData.ExecuteOnce;
|
|
563
|
+
sequence.HandledType = newData.HandledType;
|
|
564
|
+
sequence.IsDisabled = newData.IsDisabled;
|
|
565
|
+
sequence.LeftArgument = newData.LeftArgument;
|
|
566
|
+
sequence.LeftArgumentType = newData.LeftArgumentType;
|
|
567
|
+
sequence.ObjectType = newData.ObjectType;
|
|
568
|
+
sequence.Tasks = newData.Tasks;
|
|
569
|
+
//Keep settings that are not edited in this scope
|
|
570
|
+
newData.Guid = sequence.Guid;
|
|
571
|
+
newData.Icon = sequence.Icon;
|
|
572
|
+
newData.Name = sequence.Name;
|
|
573
|
+
}
|
|
574
|
+
else if (sequence.RightArgumentType == ArgumentTypeNum.Condition)
|
|
575
|
+
return findLastArgumentWithGuidAndEditCondition(sequence.RightArgument, newData);
|
|
576
|
+
else
|
|
577
|
+
throw new SequenceNotFoundScenesBuilderException(`Cannot edit sequence with given GUID ${sequenceGuid} - sequence not foud in chain`);
|
|
578
|
+
};
|
|
579
|
+
if (this._result == null)
|
|
580
|
+
throw new SequenceNotFoundScenesBuilderException(`Cannot edit sequence with given GUID ${sequenceGuid} - sequence not initialized (no root element)`);
|
|
581
|
+
findLastArgumentWithGuidAndEditCondition(this._result, this._tmp);
|
|
582
|
+
const sequneceData = this._service.MapSequence(JSON.parse(JSON.stringify(this._tmp)));
|
|
583
|
+
this._tmp = new SequenceRequestData();
|
|
584
|
+
console.log(`new tmp guid: ${this._tmp.Guid}`);
|
|
585
|
+
if (!this._result.AtMeetCondition)
|
|
586
|
+
this._result.AtMeetCondition = true;
|
|
587
|
+
return {
|
|
588
|
+
GetNext: () => this.GetNext(),
|
|
589
|
+
GetPrevious: () => this.GetPrevious(),
|
|
590
|
+
GetByGuid: (sequenceGuid) => this.GetByGuid(sequenceGuid),
|
|
591
|
+
RemoveSequenceByGuid: (sequenceGuid) => this.RemoveSequenceByGuid(sequenceGuid),
|
|
592
|
+
Commit: () => this.Commit(),
|
|
593
|
+
ArgumentAsActionWithEmptyCondition: () => this.ArgumentAsActionWithEmptyCondition(),
|
|
594
|
+
ArgumentAsAstronomicalClockWithOffset: (arg, atMeetCondition, comparasion) => this.ArgumentAsAstronomicalClockWithOffset(arg, atMeetCondition, comparasion),
|
|
595
|
+
ArgumentAsDaysOfWeek: (arg, atMeetCondition, comparison) => this.ArgumentAsDaysOfWeek(arg, atMeetCondition, comparison),
|
|
596
|
+
ArgumentAsDeviceState: (arg, atMeetCondition, atMeetConditionTimeout, comparison = ConditionsTypes.Equal) => this.ArgumentAsDeviceState(arg, atMeetCondition, atMeetConditionTimeout, comparison),
|
|
597
|
+
ArgumentAsTime: (arg, atMeetCondition, comparison = ConditionsTypes.Equal) => this.ArgumentAsTime(arg, atMeetCondition, comparison),
|
|
598
|
+
ArgumentAsTimeSpan: (arg, comparison) => this.ArgumentAsTimeSpan(arg, comparison),
|
|
599
|
+
ArgumentAsSceneExecuted: (arg) => this.ArgumentAsSceneExecuted(arg),
|
|
600
|
+
SequenceData: sequneceData
|
|
601
|
+
};
|
|
602
|
+
}
|
|
603
|
+
RemoveSequenceByGuid(sequenceGuid) {
|
|
604
|
+
let refToHead;
|
|
605
|
+
const fixNavigation = (sequence, sequenceGuid) => {
|
|
606
|
+
//navigation never used, don't need fix
|
|
607
|
+
if (this._currentSeqGuid == "" && this._prevSeqGuid == "")
|
|
608
|
+
return;
|
|
609
|
+
if (this._currentSeqGuid == sequenceGuid) {
|
|
610
|
+
this._currentSeqGuid = sequence.RightArgumentType == ArgumentTypeNum.Condition ? sequence.RightArgument.Guid : "";
|
|
611
|
+
this._prevSeqGuid = refToHead != null ? refToHead.Guid : "";
|
|
612
|
+
}
|
|
613
|
+
else if (this._prevSeqGuid == sequenceGuid) {
|
|
614
|
+
this._prevSeqGuid = refToHead != null ? refToHead.Guid : "";
|
|
615
|
+
}
|
|
616
|
+
};
|
|
617
|
+
const findRightArgumentAndRemoveArg = (sequence, sequenceGuid) => {
|
|
618
|
+
//Argument to remove
|
|
619
|
+
if (sequence.Guid == sequenceGuid) {
|
|
620
|
+
//no ref to head - root argument
|
|
621
|
+
if (refToHead == null)
|
|
622
|
+
this._result = null;
|
|
623
|
+
else {
|
|
624
|
+
refToHead.RightArgument = sequence.RightArgument;
|
|
625
|
+
refToHead.RightArgumentType = sequence.RightArgumentType;
|
|
626
|
+
}
|
|
627
|
+
fixNavigation(sequence, sequenceGuid);
|
|
628
|
+
}
|
|
629
|
+
else {
|
|
630
|
+
refToHead = sequence;
|
|
631
|
+
if (sequence.RightArgumentType == ArgumentTypeNum.Null)
|
|
632
|
+
throw new SequenceNotFoundScenesBuilderException(`Cannot remove sequence, sequence with given guid ${sequenceGuid} not found!`);
|
|
633
|
+
return findRightArgumentAndRemoveArg(sequence.RightArgument, sequenceGuid);
|
|
634
|
+
}
|
|
635
|
+
};
|
|
636
|
+
if (this._result == null)
|
|
637
|
+
throw new SequenceNotFoundScenesBuilderException("Cannot remove sequence, sequence not configured!");
|
|
638
|
+
//Removing root argument
|
|
639
|
+
if (this._result.Guid == sequenceGuid && this._result.RightArgumentType != ArgumentTypeNum.Null) {
|
|
640
|
+
this._result.RightArgument.Name = this._result.Name;
|
|
641
|
+
this._result.RightArgument.Icon = this._result.Icon;
|
|
642
|
+
this._result.RightArgument.Guid = this._result.Guid;
|
|
643
|
+
this._result = this._result.RightArgument;
|
|
644
|
+
this._result.AtMeetCondition = true;
|
|
645
|
+
fixNavigation(this._result, sequenceGuid);
|
|
646
|
+
}
|
|
647
|
+
else {
|
|
648
|
+
//Removing nested arguments
|
|
649
|
+
findRightArgumentAndRemoveArg(this._result, sequenceGuid);
|
|
650
|
+
}
|
|
651
|
+
return {
|
|
652
|
+
GetNext: () => this.GetNext(),
|
|
653
|
+
GetPrevious: () => this.GetPrevious(),
|
|
654
|
+
GetByGuid: (sequenceGuid) => this.GetByGuid(sequenceGuid),
|
|
655
|
+
RemoveSequenceByGuid: (sequenceGuid) => this.RemoveSequenceByGuid(sequenceGuid),
|
|
656
|
+
Commit: () => this.Commit(),
|
|
657
|
+
ArgumentAsActionWithEmptyCondition: () => this.ArgumentAsActionWithEmptyCondition(),
|
|
658
|
+
ArgumentAsAstronomicalClockWithOffset: (arg, atMeetCondition, comparasion) => this.ArgumentAsAstronomicalClockWithOffset(arg, atMeetCondition, comparasion),
|
|
659
|
+
ArgumentAsDaysOfWeek: (arg, atMeetCondition, comparison) => this.ArgumentAsDaysOfWeek(arg, atMeetCondition, comparison),
|
|
660
|
+
ArgumentAsDeviceState: (arg, atMeetCondition, atMeetConditionTimeout, comparison = ConditionsTypes.Equal) => this.ArgumentAsDeviceState(arg, atMeetCondition, atMeetConditionTimeout, comparison),
|
|
661
|
+
ArgumentAsTime: (arg, atMeetCondition, comparison = ConditionsTypes.Equal) => this.ArgumentAsTime(arg, atMeetCondition, comparison),
|
|
662
|
+
ArgumentAsTimeSpan: (arg, comparison) => this.ArgumentAsTimeSpan(arg, comparison),
|
|
663
|
+
ArgumentAsSceneExecuted: (arg) => this.ArgumentAsSceneExecuted(arg),
|
|
664
|
+
SequenceData: null
|
|
665
|
+
};
|
|
666
|
+
}
|
|
667
|
+
/**
|
|
668
|
+
* Functions commits modifications of arguments chain
|
|
669
|
+
* @returns
|
|
670
|
+
*/
|
|
671
|
+
Commit() {
|
|
672
|
+
const findLastRightArgumentAndMoveTasks = (sequence) => {
|
|
673
|
+
//Last arg
|
|
674
|
+
if (sequence.RightArgumentType == ArgumentTypeNum.Null) {
|
|
675
|
+
if (this._rawExistingSequenceTasks != null)
|
|
676
|
+
sequence.Tasks = this._rawExistingSequenceTasks;
|
|
677
|
+
}
|
|
678
|
+
else
|
|
679
|
+
return findLastRightArgumentAndMoveTasks(sequence.RightArgument);
|
|
680
|
+
};
|
|
681
|
+
if (this._result == null)
|
|
682
|
+
throw new SequenceNotFoundScenesBuilderException("Sequence are not initialized! Not found root sequence.");
|
|
683
|
+
//Move tasks to last argument - required while editing (removing or adding argument)
|
|
684
|
+
if (this._editingExistingSequence)
|
|
685
|
+
findLastRightArgumentAndMoveTasks(this._result);
|
|
686
|
+
return {
|
|
687
|
+
DeviceTask: (task) => this.DeviceTask(task),
|
|
688
|
+
DelayTask: (delay) => this.DelayTask(delay),
|
|
689
|
+
NotifyTask: (notification) => this.NotifyTask(notification),
|
|
690
|
+
LockExecutionTask: (lockTask) => this.LockExecutionTask(lockTask),
|
|
691
|
+
RemoveTask: (taskGuid) => this.RemoveTask(taskGuid),
|
|
692
|
+
Build: () => this.Build(),
|
|
693
|
+
BuildToISequence: () => this._service.MapSequence(JSON.parse(JSON.stringify(this._result)))
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
DeviceTask(task) {
|
|
697
|
+
this._tmpTask = this.ParseDeviceTask(task);
|
|
698
|
+
if (this._result == null)
|
|
699
|
+
throw new Error("No context!");
|
|
700
|
+
return {
|
|
701
|
+
AddTask: () => this.AddTask(),
|
|
702
|
+
EditTask: (taskId) => this.EditTask(taskId),
|
|
703
|
+
TaskId: Helpers.GenerateMd5(JSON.stringify(this._tmpTask)),
|
|
704
|
+
};
|
|
705
|
+
}
|
|
706
|
+
ParseDeviceTask(task) {
|
|
707
|
+
const tsk = new DeviceTaskRequestData();
|
|
708
|
+
tsk.Channel = task.Channel;
|
|
709
|
+
tsk.DeviceGuid = task.DeviceGuid;
|
|
710
|
+
tsk.ControlFeature = this.MapTaskTypeToControlFeature(task.TaskType);
|
|
711
|
+
tsk.Data = {};
|
|
712
|
+
tsk.Data.Channel = task.Channel;
|
|
713
|
+
if (task.TaskType == DeviceTaskType.SetBlindPosition || task instanceof SetBlindPosition) {
|
|
714
|
+
tsk.Data.Position = task.Position;
|
|
715
|
+
tsk.Data.Action = task.Action;
|
|
716
|
+
}
|
|
717
|
+
else if (task.TaskType == DeviceTaskType.SetLightColor || task instanceof SetLightColor) {
|
|
718
|
+
tsk.Data.R = task.R;
|
|
719
|
+
tsk.Data.G = task.G;
|
|
720
|
+
tsk.Data.B = task.B;
|
|
721
|
+
}
|
|
722
|
+
else if (task.TaskType == DeviceTaskType.SetLightTemperature || task instanceof SetLightTemperature) {
|
|
723
|
+
tsk.Data.Temperature = task.Temperature;
|
|
724
|
+
}
|
|
725
|
+
else if (task.TaskType == DeviceTaskType.SetLightBrightness || task instanceof SetLightBrightness) {
|
|
726
|
+
tsk.Data.Brightness = task.Brightness;
|
|
727
|
+
}
|
|
728
|
+
else if (task.TaskType == DeviceTaskType.SetTemperature || task instanceof SetTemperature) {
|
|
729
|
+
tsk.Data.Temperature = task.Temperature;
|
|
730
|
+
}
|
|
731
|
+
else if (task.TaskType == DeviceTaskType.TurnOnWithTime || task instanceof TurnOnWithTime) {
|
|
732
|
+
tsk.Data.SwitchOffDelaySeconds = task.SwitchOffDelaySeconds;
|
|
733
|
+
}
|
|
734
|
+
else if (task.TaskType == DeviceTaskType.SetLightBrightnessDynamicly || task instanceof SetLightBrightnessDynamicly) {
|
|
735
|
+
tsk.Data.Brightness = task.Brightness;
|
|
736
|
+
}
|
|
737
|
+
else if (task.TaskType == DeviceTaskType.SetBlindOpenCloseTime || task instanceof SetBlindOpenCloseTime) {
|
|
738
|
+
tsk.Data.CloseTime = task.Data.CloseTime;
|
|
739
|
+
tsk.Data.OpenTime = task.Data.OpenTime;
|
|
740
|
+
}
|
|
741
|
+
else if (task.TaskType == DeviceTaskType.SetBlindMicroventilation || task instanceof SetBlindMicroventilation) {
|
|
742
|
+
tsk.Data.Position = task.Position;
|
|
743
|
+
}
|
|
744
|
+
else if (task.TaskType == DeviceTaskType.SetFacadePosition || task instanceof SetFacadePosition) {
|
|
745
|
+
tsk.Data.FacadeAction = task.FacadeAction;
|
|
746
|
+
tsk.Data.Position = task.Position;
|
|
747
|
+
tsk.Data.Tilt = task.Tilt;
|
|
748
|
+
}
|
|
749
|
+
else if (task.TaskType == DeviceTaskType.LightRGBW || task instanceof LightRGBW) {
|
|
750
|
+
tsk.Data.R = task.Data.R;
|
|
751
|
+
tsk.Data.G = task.Data.G;
|
|
752
|
+
tsk.Data.B = task.Data.B;
|
|
753
|
+
tsk.Data.W = task.Data.W;
|
|
754
|
+
tsk.Data.Brightness = task.Data.Brightness;
|
|
755
|
+
}
|
|
756
|
+
//else
|
|
757
|
+
// throw new Error(`Unsupported device task, task type: ${task.TaskType} task object: ${task}!`);
|
|
758
|
+
return tsk;
|
|
759
|
+
}
|
|
760
|
+
DelayTask(delay) {
|
|
761
|
+
const task = new DelayTaskRequestData();
|
|
762
|
+
task.Delay = delay.Delay.Value;
|
|
763
|
+
this._tmpTask = task;
|
|
764
|
+
if (this._result == null)
|
|
765
|
+
throw new Error("No context!");
|
|
766
|
+
return {
|
|
767
|
+
AddTask: () => this.AddTask(),
|
|
768
|
+
EditTask: (taskGuid) => this.EditTask(taskGuid),
|
|
769
|
+
TaskId: Helpers.GenerateMd5(JSON.stringify(task)),
|
|
770
|
+
};
|
|
771
|
+
}
|
|
772
|
+
NotifyTask(notification) {
|
|
773
|
+
throw new UnsupportedArgumentScenesBuilderException("Funcionality will be available in the future.");
|
|
774
|
+
}
|
|
775
|
+
LockExecutionTask(lockTask) {
|
|
776
|
+
const task = new LockTaskTaskRequestData();
|
|
777
|
+
task.LockType = lockTask.LockType;
|
|
778
|
+
if (task.LockType == LockType.Timeout) {
|
|
779
|
+
if (task.LockEndHour != "00:00:00")
|
|
780
|
+
throw new UnsupportedArgumentScenesBuilderException("Parameter LockEndHour at lock type `Timeout` must be default!");
|
|
781
|
+
}
|
|
782
|
+
task.LockStartHour = lockTask.LockStartHour.Value;
|
|
783
|
+
task.LockEndHour = lockTask.LockEndHour.Value;
|
|
784
|
+
task.ResetLockScenesGuids = lockTask.ResetLockScenesGuids;
|
|
785
|
+
this._tmpTask = task;
|
|
786
|
+
if (this._result == null)
|
|
787
|
+
throw new Error("No context!");
|
|
788
|
+
return {
|
|
789
|
+
AddTask: () => this.AddTask(),
|
|
790
|
+
EditTask: (taskGuid) => this.EditTask(taskGuid),
|
|
791
|
+
TaskId: Helpers.GenerateMd5(JSON.stringify(task)),
|
|
792
|
+
};
|
|
793
|
+
}
|
|
794
|
+
AddTask() {
|
|
795
|
+
const findLastRightArgumentAndAddTask = (sequence) => {
|
|
796
|
+
//Last arg
|
|
797
|
+
if (sequence.RightArgumentType == ArgumentTypeNum.Null) {
|
|
798
|
+
if (this._tmpTask == null)
|
|
799
|
+
throw Error("No task context!");
|
|
800
|
+
if (sequence.Tasks.DevicesTasks === undefined || sequence.Tasks.DevicesTasks === null)
|
|
801
|
+
sequence.Tasks.DevicesTasks = [];
|
|
802
|
+
if (this._tmpTask instanceof DeviceTaskRequestData)
|
|
803
|
+
sequence.Tasks.DevicesTasks.push(structuredClone(this._tmpTask));
|
|
804
|
+
sequence.Tasks.ControllerTasks.push(structuredClone(this._tmpTask));
|
|
805
|
+
this._tmpTask = null;
|
|
806
|
+
Api.Get(LoggerService.ServiceName).Debug(`Task added to sequence: \n${JSON.stringify(this._tmpTask)} \ntasks on a list: \n${JSON.stringify(sequence.Tasks)}`);
|
|
807
|
+
}
|
|
808
|
+
else
|
|
809
|
+
return findLastRightArgumentAndAddTask(sequence.RightArgument);
|
|
810
|
+
};
|
|
811
|
+
if (this._result == null)
|
|
812
|
+
throw new Error("No context!");
|
|
813
|
+
findLastRightArgumentAndAddTask(this._result);
|
|
814
|
+
return {
|
|
815
|
+
DeviceTask: (task) => this.DeviceTask(task),
|
|
816
|
+
DelayTask: (delay) => this.DelayTask(delay),
|
|
817
|
+
NotifyTask: (notification) => this.NotifyTask(notification),
|
|
818
|
+
LockExecutionTask: (lockTask) => this.LockExecutionTask(lockTask),
|
|
819
|
+
RemoveTask: (taskId) => this.RemoveTask(taskId),
|
|
820
|
+
Build: () => this.Build(),
|
|
821
|
+
BuildToISequence: () => this._service.MapSequence(JSON.parse(JSON.stringify(this._result))),
|
|
822
|
+
};
|
|
823
|
+
}
|
|
824
|
+
EditTask(taskId) {
|
|
825
|
+
const findLastRightArgumentAndEditTask = (sequence) => {
|
|
826
|
+
//Last arg
|
|
827
|
+
if (sequence.RightArgumentType == ArgumentTypeNum.Null) {
|
|
828
|
+
if (this._tmpTask == null)
|
|
829
|
+
throw Error("No task context!");
|
|
830
|
+
if (sequence.Tasks.ControllerTasks == null || sequence.Tasks.ControllerTasks.length == 0)
|
|
831
|
+
throw new TaskNotFoundScenesBuilderException("Task not found, cannot edit!");
|
|
832
|
+
if (this._tmpTask instanceof DeviceTaskRequestData && sequence.Tasks.DevicesTasks != null)
|
|
833
|
+
sequence.Tasks.DevicesTasks = sequence.Tasks.DevicesTasks.map(dTask => Helpers.GenerateMd5(JSON.stringify(dTask)) == taskId ? structuredClone(this._tmpTask) : dTask);
|
|
834
|
+
sequence.Tasks.ControllerTasks = sequence.Tasks.ControllerTasks.map(cTask => Helpers.GenerateMd5(JSON.stringify(cTask)) == taskId ? structuredClone(this._tmpTask) : cTask);
|
|
835
|
+
this._tmpTask = null;
|
|
836
|
+
Api.Get(LoggerService.ServiceName).Debug(`Task edited in sequence: \n${JSON.stringify(this._tmpTask)} \ntasks on a list: \n${JSON.stringify(sequence.Tasks)}`);
|
|
837
|
+
}
|
|
838
|
+
else
|
|
839
|
+
return findLastRightArgumentAndEditTask(sequence.RightArgument);
|
|
840
|
+
};
|
|
841
|
+
if (this._result == null)
|
|
842
|
+
throw new Error("No context!");
|
|
843
|
+
findLastRightArgumentAndEditTask(this._result);
|
|
844
|
+
return {
|
|
845
|
+
DeviceTask: (task) => this.DeviceTask(task),
|
|
846
|
+
DelayTask: (delay) => this.DelayTask(delay),
|
|
847
|
+
NotifyTask: (notification) => this.NotifyTask(notification),
|
|
848
|
+
LockExecutionTask: (lockTask) => this.LockExecutionTask(lockTask),
|
|
849
|
+
RemoveTask: (taskGuid) => this.RemoveTask(taskGuid),
|
|
850
|
+
Build: () => this.Build(),
|
|
851
|
+
BuildToISequence: () => this._service.MapSequence(JSON.parse(JSON.stringify(this._result))),
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
RemoveTask(taskId) {
|
|
855
|
+
const findLastRightArgumentAndRemoveTask = (sequence, taskId) => {
|
|
856
|
+
//Last arg
|
|
857
|
+
if (sequence.RightArgumentType == ArgumentTypeNum.Null) {
|
|
858
|
+
const newTasks = sequence.Tasks.ControllerTasks.filter(t => Helpers.GenerateMd5(JSON.stringify(t)) != taskId);
|
|
859
|
+
if (newTasks == null)
|
|
860
|
+
sequence.Tasks.ControllerTasks = [];
|
|
861
|
+
else
|
|
862
|
+
sequence.Tasks.ControllerTasks = newTasks;
|
|
863
|
+
if (sequence.Tasks.DevicesTasks.any()) {
|
|
864
|
+
const newTasks = sequence.Tasks.DevicesTasks.filter(t => Helpers.GenerateMd5(JSON.stringify(t)) != taskId);
|
|
865
|
+
if (newTasks == null)
|
|
866
|
+
sequence.Tasks.DevicesTasks = [];
|
|
867
|
+
else
|
|
868
|
+
sequence.Tasks.DevicesTasks = newTasks;
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
else
|
|
872
|
+
return findLastRightArgumentAndRemoveTask(sequence.RightArgument, taskId);
|
|
873
|
+
};
|
|
874
|
+
if (this._result == null)
|
|
875
|
+
throw Error("Cannot remove task, sequence not configured!");
|
|
876
|
+
findLastRightArgumentAndRemoveTask(this._result, taskId);
|
|
877
|
+
}
|
|
878
|
+
MapTaskTypeToControlFeature(taskType) {
|
|
879
|
+
switch (taskType) {
|
|
880
|
+
case DeviceTaskType.Unknown:
|
|
881
|
+
throw new BadParametersScenesBuilderException("Unsupported task type!");
|
|
882
|
+
case DeviceTaskType.SetBlindPosition:
|
|
883
|
+
return DeviceControlFeature.SetBlindPosition;
|
|
884
|
+
case DeviceTaskType.SetBlindPositionSimple:
|
|
885
|
+
return DeviceControlFeature.SetBlindPosition;
|
|
886
|
+
case DeviceTaskType.SetBlindMicroventilation:
|
|
887
|
+
return DeviceControlFeature.SetBlindMicroventilation;
|
|
888
|
+
case DeviceTaskType.TurnOff:
|
|
889
|
+
return DeviceControlFeature.TurnOff;
|
|
890
|
+
case DeviceTaskType.TurnOn:
|
|
891
|
+
return DeviceControlFeature.TurnOn;
|
|
892
|
+
case DeviceTaskType.TurnOnWithTime:
|
|
893
|
+
return DeviceControlFeature.TurnOnWithTimeout;
|
|
894
|
+
case DeviceTaskType.TogleState:
|
|
895
|
+
return DeviceControlFeature.ToggleState;
|
|
896
|
+
case DeviceTaskType.SetLightBrightnessDynamicly:
|
|
897
|
+
return DeviceControlFeature.SetLightBrightnessDynamicly;
|
|
898
|
+
case DeviceTaskType.SetLightBrightness:
|
|
899
|
+
return DeviceControlFeature.SetLightBrightness;
|
|
900
|
+
case DeviceTaskType.SetLightColor:
|
|
901
|
+
return DeviceControlFeature.SetLightColor;
|
|
902
|
+
case DeviceTaskType.SetLightTemperature:
|
|
903
|
+
return DeviceControlFeature.SetLightTemperature;
|
|
904
|
+
case DeviceTaskType.PairDevice:
|
|
905
|
+
throw new BadParametersScenesBuilderException("Unsupported task type!");
|
|
906
|
+
case DeviceTaskType.UnpairDevice:
|
|
907
|
+
throw new BadParametersScenesBuilderException("Unsupported task type!");
|
|
908
|
+
case DeviceTaskType.IdentifyDevice:
|
|
909
|
+
return DeviceControlFeature.IdentifyDevice;
|
|
910
|
+
case DeviceTaskType.GetChannelsState:
|
|
911
|
+
return DeviceControlFeature.GetState;
|
|
912
|
+
case DeviceTaskType.GetPowerMeasurements:
|
|
913
|
+
throw new BadParametersScenesBuilderException("Unsupported task type!");
|
|
914
|
+
case DeviceTaskType.GetAvailableData:
|
|
915
|
+
throw new BadParametersScenesBuilderException("Unsupported task type!");
|
|
916
|
+
case DeviceTaskType.MultipleDataRequest:
|
|
917
|
+
throw new BadParametersScenesBuilderException("Unsupported task type!");
|
|
918
|
+
case DeviceTaskType.SetBlindOpenCloseTime:
|
|
919
|
+
return DeviceControlFeature.SetBlindOpenCloseTime;
|
|
920
|
+
case DeviceTaskType.SetTemperature:
|
|
921
|
+
return DeviceControlFeature.SetTemperature;
|
|
922
|
+
case DeviceTaskType.ChangeGatePositionPulse:
|
|
923
|
+
return DeviceControlFeature.GatePulse;
|
|
924
|
+
case DeviceTaskType.ChangeGatewayPositionPulse:
|
|
925
|
+
return DeviceControlFeature.GatewayPulse;
|
|
926
|
+
case DeviceTaskType.SetFacadePosition:
|
|
927
|
+
return DeviceControlFeature.SetFacadePositionAndTilt;
|
|
928
|
+
case DeviceTaskType.GetFacadeType:
|
|
929
|
+
return DeviceControlFeature.SetFacadePositionAndTilt;
|
|
930
|
+
case DeviceTaskType.LightRGBW:
|
|
931
|
+
return DeviceControlFeature.LightRGBW;
|
|
932
|
+
default:
|
|
933
|
+
throw new BadParametersScenesBuilderException("Unsupported task type!");
|
|
934
|
+
}
|
|
935
|
+
}
|
|
936
|
+
/**
|
|
937
|
+
* Function builds SequenceRequestData object, this obj. can be send via API to controller to modify or add sequence
|
|
938
|
+
* SequenceRequestData should be pass to EditSequenceAsync(sequence: SequenceRequestData) or CreateSequenceAsync(sequence: SequenceRequestData) methods in ScenesService;
|
|
939
|
+
* @returns
|
|
940
|
+
*/
|
|
941
|
+
Build() {
|
|
942
|
+
const findLastRightArgumentAndRemoveTaskGuid = (sequence) => {
|
|
943
|
+
//Last arg
|
|
944
|
+
if (sequence.RightArgumentType == ArgumentTypeNum.Null) {
|
|
945
|
+
sequence.Tasks.ControllerTasks = sequence.Tasks.ControllerTasks.map(t => {
|
|
946
|
+
if (Object.hasOwn(t, "_taskGuid"))
|
|
947
|
+
delete t["_taskGuid"];
|
|
948
|
+
return t;
|
|
949
|
+
});
|
|
950
|
+
}
|
|
951
|
+
else
|
|
952
|
+
return findLastRightArgumentAndRemoveTaskGuid(sequence.RightArgument);
|
|
953
|
+
};
|
|
954
|
+
if (this._result != null) {
|
|
955
|
+
//Removing taskGuid for internal purposes
|
|
956
|
+
findLastRightArgumentAndRemoveTaskGuid(this._result);
|
|
957
|
+
return this._result;
|
|
958
|
+
}
|
|
959
|
+
else
|
|
960
|
+
throw Error("Cannot build sequence, sequence not configured!");
|
|
961
|
+
}
|
|
962
|
+
FindArgumentWithGuid(sequence, sequenceGuid) {
|
|
963
|
+
if (sequence.Guid == sequenceGuid) {
|
|
964
|
+
return sequence;
|
|
965
|
+
}
|
|
966
|
+
else if (sequence.RightArgumentType == ArgumentTypeNum.Condition)
|
|
967
|
+
return this.FindArgumentWithGuid(sequence.RightArgument, sequenceGuid);
|
|
968
|
+
else
|
|
969
|
+
return null;
|
|
970
|
+
}
|
|
971
|
+
}
|
|
972
|
+
export class SequenceRequestData {
|
|
973
|
+
constructor() {
|
|
974
|
+
this.Tasks = new TasksRequestData();
|
|
975
|
+
this.Guid = "";
|
|
976
|
+
this.ObjectType = 1;
|
|
977
|
+
this.Name = "";
|
|
978
|
+
this.Icon = "";
|
|
979
|
+
this.AtMeetCondition = false;
|
|
980
|
+
this.ExecuteOnce = false;
|
|
981
|
+
this.IsDisabled = false;
|
|
982
|
+
this.HandledType = HandledType.Unknown;
|
|
983
|
+
this.ConditionType = ConditionsTypes.Unknown;
|
|
984
|
+
this.ConditionTimeout = 0;
|
|
985
|
+
this.LeftArgumentType = ArgumentTypeNum.Null;
|
|
986
|
+
this.RightArgumentType = ArgumentTypeNum.Null;
|
|
987
|
+
this.LeftArgument = new LeftArgumentRequestData({}, ArgumentTypeNum.Null);
|
|
988
|
+
this.RightArgument = new EmptySequenceRequestData();
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
class EmptySequenceRequestData {
|
|
992
|
+
constructor() {
|
|
993
|
+
this.HandledType = 0;
|
|
994
|
+
this.Argument = null;
|
|
995
|
+
}
|
|
996
|
+
}
|
|
997
|
+
class LeftArgumentRequestData {
|
|
998
|
+
constructor(argument, handledType) {
|
|
999
|
+
this.Argument = argument;
|
|
1000
|
+
this.HandledType = handledType;
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
class LeftArgumentDeviceStateRequestData {
|
|
1004
|
+
constructor() {
|
|
1005
|
+
this.DeviceStateType = DeviceStateType.Unknown;
|
|
1006
|
+
this.Channel = 0;
|
|
1007
|
+
this.DeviceGuid = "";
|
|
1008
|
+
this.ComparisonMethod = DeviceStateComparisonMethod.Default;
|
|
1009
|
+
this.ComparisonParams = null;
|
|
1010
|
+
this.CheckedDeviceState = {};
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
class TasksRequestData {
|
|
1014
|
+
constructor() {
|
|
1015
|
+
this.ControllerTasks = [];
|
|
1016
|
+
this.DevicesTasks = [];
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
class ControllerTaskRequestData {
|
|
1020
|
+
constructor() {
|
|
1021
|
+
this.RunParallel = false;
|
|
1022
|
+
this.TaskType = SceneTaskTypeNum.Unknown;
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
class DeviceTaskRequestData extends ControllerTaskRequestData {
|
|
1026
|
+
constructor() {
|
|
1027
|
+
super(...arguments);
|
|
1028
|
+
this.TaskType = SceneTaskTypeNum.DeviceTask;
|
|
1029
|
+
this.DeviceGuid = "";
|
|
1030
|
+
this.Channel = 0;
|
|
1031
|
+
this.ControlFeature = DeviceControlFeature.TurnOn;
|
|
1032
|
+
}
|
|
1033
|
+
}
|
|
1034
|
+
class DelayTaskRequestData extends ControllerTaskRequestData {
|
|
1035
|
+
constructor() {
|
|
1036
|
+
super(...arguments);
|
|
1037
|
+
this.TaskType = SceneTaskTypeNum.DelayTask;
|
|
1038
|
+
this.Delay = "00:00:00";
|
|
1039
|
+
}
|
|
1040
|
+
}
|
|
1041
|
+
class LockTaskTaskRequestData extends ControllerTaskRequestData {
|
|
1042
|
+
constructor() {
|
|
1043
|
+
super(...arguments);
|
|
1044
|
+
this.TaskType = SceneTaskTypeNum.LockExecution;
|
|
1045
|
+
this.LockType = LockType.Timeout;
|
|
1046
|
+
this.LockStartHour = "00:00:00";
|
|
1047
|
+
this.LockEndHour = "00:00:00";
|
|
1048
|
+
this.ResetLockScenesGuids = [];
|
|
1049
|
+
}
|
|
1050
|
+
}
|
|
1051
|
+
var ArgumentTypeNum;
|
|
1052
|
+
(function (ArgumentTypeNum) {
|
|
1053
|
+
ArgumentTypeNum[ArgumentTypeNum["Null"] = 0] = "Null";
|
|
1054
|
+
ArgumentTypeNum[ArgumentTypeNum["Condition"] = 1] = "Condition";
|
|
1055
|
+
ArgumentTypeNum[ArgumentTypeNum["ConditionGroup"] = 2] = "ConditionGroup";
|
|
1056
|
+
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsInt"] = 3] = "ArgumentAsInt";
|
|
1057
|
+
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsTimeSpan"] = 4] = "ArgumentAsTimeSpan";
|
|
1058
|
+
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsBoolean"] = 5] = "ArgumentAsBoolean";
|
|
1059
|
+
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsTimeout"] = 6] = "ArgumentAsTimeout";
|
|
1060
|
+
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsDayOfWeek"] = 7] = "ArgumentAsDayOfWeek";
|
|
1061
|
+
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsDaysOfWeek"] = 8] = "ArgumentAsDaysOfWeek";
|
|
1062
|
+
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsAstronomicalClock"] = 9] = "ArgumentAsAstronomicalClock";
|
|
1063
|
+
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsTime"] = 10] = "ArgumentAsTime";
|
|
1064
|
+
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsDeviceState"] = 11] = "ArgumentAsDeviceState";
|
|
1065
|
+
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsNumber"] = 12] = "ArgumentAsNumber";
|
|
1066
|
+
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsAstronomicalClockWithOffset"] = 13] = "ArgumentAsAstronomicalClockWithOffset";
|
|
1067
|
+
ArgumentTypeNum[ArgumentTypeNum["ArgumentAsConditionInfo"] = 14] = "ArgumentAsConditionInfo";
|
|
1068
|
+
})(ArgumentTypeNum || (ArgumentTypeNum = {}));
|
|
1069
|
+
//Errors
|
|
1070
|
+
export class BadParametersScenesBuilderException extends Error {
|
|
1071
|
+
constructor(message) {
|
|
1072
|
+
super(message);
|
|
1073
|
+
this.message = message;
|
|
1074
|
+
this.name = "BadParametersScenesBuilderException";
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
export class SequenceNotFoundScenesBuilderException extends Error {
|
|
1078
|
+
constructor(message) {
|
|
1079
|
+
super(message);
|
|
1080
|
+
this.message = message;
|
|
1081
|
+
this.name = "SequenceNotFoundScenesBuilderException";
|
|
1082
|
+
}
|
|
1083
|
+
}
|
|
1084
|
+
export class TaskNotFoundScenesBuilderException extends Error {
|
|
1085
|
+
constructor(message) {
|
|
1086
|
+
super(message);
|
|
1087
|
+
this.message = message;
|
|
1088
|
+
this.name = "TaskNotFoundScenesBuilderException";
|
|
1089
|
+
}
|
|
1090
|
+
}
|
|
1091
|
+
export class UnsupportedArgumentScenesBuilderException extends Error {
|
|
1092
|
+
constructor(message) {
|
|
1093
|
+
super(message);
|
|
1094
|
+
this.message = message;
|
|
1095
|
+
this.name = "UnsupportedArgumentScenesBuilderException";
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
1098
|
//# sourceMappingURL=ScenesBuilder.js.map
|