forked from openhab/openhab-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathactions.js
262 lines (252 loc) · 10.3 KB
/
actions.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
/* eslint-disable no-irregular-whitespace */
/**
* Actions namespace.
* This namespace provides access to openHAB actions. All available actions can be accessed as direct properties of this
* object (via their simple class name).
*
* @example <caption>Sends a broadcast notification</caption>
* let { actions } = require('openhab');
* actions.NotificationAction.sendBroadcastNotification("Hello World!")
*
* @example <caption>Sends a PushSafer notification</caption>
* let { actions } = require('openhab');
* actions.Pushsafer.pushsafer("<your pushsafer api key>", "<message>", "<message title>", "", "", "", "")
*
* @namespace actions
*/
const osgi = require('./osgi');
const { actions } = require('@runtime/Defaults');
const log = require('./log')('actions');
const Things = Java.type('org.openhab.core.model.script.actions.Things');
const actionServices = osgi.findServices('org.openhab.core.model.script.engine.action.ActionService', null) || [];
actionServices.forEach(function (item) {
try {
// if an action fails to activate, then warn and continue so that other actions are available
exports[item.getActionClass().getSimpleName()] = item.getActionClass().static;
} catch (e) {
log.warn('Failed to activate action {} due to {}', item, e);
}
});
/**
* Audio Actions
*
* The static methods of this class are made available as functions in the scripts. This allows a script to use audio features.
*
* @example
* Audio.decreaseMasterVolume(float percent)
* Audio.getMasterVolume()
* Audio.increaseMasterVolume(float percent)
* Audio.playSound(String filename)
* Audio.playSound(String sink, String filename)
* Audio.playSound(String sink, String filename, PercentType volume)
* Audio.playSound(String filename, PercentType volume)
* Audio.playStream(String url)
* Audio.playStream(String sink, String url)
* Audio.setMasterVolume(float volume)
* Audio.setMasterVolume(PercentType percent)
* @example
* Audio.decreaseMasterVolume(1.0)
*
* @name Audio
* @memberof actions
*/
const Audio = Java.type('org.openhab.core.model.script.actions.Audio');
/**
* BusEvent Actions
*
* The static methods of this class are made available as functions in the scripts. This gives direct write access to the openHAB event bus from within scripts. Items should not be updated directly (setting the state property), but updates should be sent to the bus, so that all interested bundles are notified.
* @example
* BusEvent.postUpdate(String itemName, String stateString)
* BusEvent.postUpdate(Item item, Number state)
* BusEvent.postUpdate(Item item, String stateAsString)
* BusEvent.postUpdate(Item item, State state)
* BusEvent.restoreStates(Map<Item,State> statesMap)
* BusEvent.sendCommand(String itemName, String commandString)
* BusEvent.sendCommand(Item item, Number number)
* BusEvent.sendCommand(Item item, String commandString)
* BusEvent.sendCommand(Item item, Command command)
* BusEvent.storeStates(Item... items)
*
* @name BusEvent
* @memberof actions
*/
const BusEvent = Java.type('org.openhab.core.model.script.actions.BusEvent');
/**
* Ephemeris Actions
*
* The static methods of this class are made available as functions in the scripts. This allows a script to use ephemeris features.
* @example
* Ephemeris.getBankHolidayName()
* Ephemeris.getBankHolidayName(int offset)
* Ephemeris.getBankHolidayName(int offset, String filename)
* Ephemeris.getBankHolidayName(String filename)
* Ephemeris.getBankHolidayName(ZonedDateTime day)
* Ephemeris.getBankHolidayName(ZonedDateTime day, String filename)
* Ephemeris.getDaysUntil(String searchedHoliday)
* Ephemeris.getDaysUntil(String searchedHoliday, String filename)
* Ephemeris.getDaysUntil(ZonedDateTime day, String searchedHoliday)
* Ephemeris.getDaysUntil(ZonedDateTime day, String searchedHoliday, String filename)
* Ephemeris.getHolidayDescription(@Nullable String holiday)
* Ephemeris.getNextBankHoliday()
* Ephemeris.getNextBankHoliday(int offset)
* Ephemeris.getNextBankHoliday(int offset, String filename)
* Ephemeris.getNextBankHoliday(String filename)
* Ephemeris.getNextBankHoliday(ZonedDateTime day)
* Ephemeris.getNextBankHoliday(ZonedDateTime day, String filename)
* Ephemeris.isBankHoliday()
* Ephemeris.isBankHoliday(int offset)
* Ephemeris.isBankHoliday(int offset, String filename)
* Ephemeris.isBankHoliday(String filename)
* Ephemeris.isBankHoliday(ZonedDateTime day)
* Ephemeris.isBankHoliday(ZonedDateTime day, String filename)
* Ephemeris.isInDayset(String daysetName)
* Ephemeris.isInDayset(String daysetName, int offset)
* Ephemeris.isInDayset(String daysetName, ZonedDateTime day)
* Ephemeris.isWeekend()
* Ephemeris.isWeekend(int offset)
* Ephemeris.isWeekend(ZonedDateTime day)
*
* @name Ephemeris
* @memberof actions
*/
const Ephemeris = Java.type('org.openhab.core.model.script.actions.Ephemeris');
/**
* Exec Actions
*
* This class provides static methods that can be used in automation rules for executing commands on command line.
*
* @example
* Exec.executeCommandLine(String... commandLine)
* Exec.executeCommandLine(Duration timeout, String... commandLine)
*
* @name Exec
* @memberof actions
*/
const Exec = Java.type('org.openhab.core.model.script.actions.Exec');
/**
* HTTP Actions
*
* This class provides static methods that can be used in automation rules for sending HTTP requests
*
* @example
* HTTP.sendHttpDeleteRequest(String url)
* HTTP.sendHttpDeleteRequest(String url, int timeout)
* HTTP.sendHttpDeleteRequest(String url, Map<String,String> headers, int timeout)
* HTTP.sendHttpGetRequest(String url)
* HTTP.sendHttpGetRequest(String url, int timeout)
* HTTP.sendHttpGetRequest(String url, Map<String,String> headers, int timeout)
* HTTP.sendHttpPostRequest(String url)
* HTTP.sendHttpPostRequest(String url, int timeout)
* HTTP.sendHttpPostRequest(String url, String contentType, String content)
* HTTP.sendHttpPostRequest(String url, String contentType, String content, int timeout)
* HTTP.sendHttpPostRequest(String url, String contentType, String content, Map<String,String> headers, int timeout)
* HTTP.sendHttpPutRequest(String url)
* HTTP.sendHttpPutRequest(String url, int timeout)
* HTTP.sendHttpPutRequest(String url, String contentType, String content)
* HTTP.sendHttpPutRequest(String url, String contentType, String content, int timeout)
* HTTP.sendHttpPutRequest(String url, String contentType, String content, Map<String,String> headers, int timeout)
*
* @name HTTP
* @memberof actions
*/
const HTTP = Java.type('org.openhab.core.model.script.actions.HTTP');
/**
* Log Actions
*
* The static methods of this class are made available as functions in the scripts. This allows a script to log to the SLF4J-Log.
*
* @example
* Log.logDebug(String loggerName, String format, Object... args)
* Log.logError(String loggerName, String format, Object... args)
* Log.logInfo(String loggerName, String format, Object... args)
* Log.logWarn(String loggerName, String format, Object... args)
*
* @name Log
* @memberof actions
*/
const LogAction = Java.type('org.openhab.core.model.script.actions.Log');
/**
* Ping Actions
*
* This Action checks the vitality of the given host.
*
* @example
* Ping.checkVitality(String host, int port, int timeout)
*
* @name Ping
* @memberof actions
*/
const Ping = Java.type('org.openhab.core.model.script.actions.Ping');
/**
* ScriptExecution Actions
*
* The static methods of this class are made available as functions in the scripts. This allows a script to call another script, which is available as a file.
*
* @example
* ScriptExecution.callScript(String scriptName)
* ScriptExecution.createTimer(ZonedDateTime instant, org.eclipse.xtext.xbase.lib.Procedures.Procedure0 closure)
* ScriptExecution.createTimerWithArgument(ZonedDateTime instant, Object arg1, org.eclipse.xtext.xbase.lib.Procedures.Procedure1<Object> closure)
*
* @name ScriptExecution
* @memberof actions
*/
const ScriptExecution = Java.type('org.openhab.core.model.script.actions.ScriptExecution');
/**
* Semantics Actions
*
* The static methods of this class are made available as functions in the scripts. This allows a script to use Semantics features.
*
* @example
* Semantics.getEquipment(Item item)
* Semantics.getEquipmentType(Item item)
* Semantics.getLocation(Item item)
* Semantics.getLocationType(Item item)
* Semantics.getPointType(Item item)
* Semantics.getPropertyType(Item item)
* Semantics.getSemanticType(Item item)
* Semantics.isEquipment(Item item)
* Semantics.isLocation(Item item)
* Semantics.isPoint(Item item)
*
* @name Semantics
* @memberof actions
*/
const Semantics = Java.type('org.openhab.core.model.script.actions.Semantics');
/**
* Things Actions
*
* This class provides static methods that can be used in automation rules for getting thing's status info.
*
* @example
* Things.getActions(String scope, String thingUid)
* Things.getThingStatusInfo(String thingUid)
*
* @name Things
* @memberof actions
*/
const ThingsAction = Java.type('org.openhab.core.model.script.actions.Things');
/**
* Voice Actions
*
* The static methods of this class are made available as functions in the scripts. This allows a script to use voice features.
*
* @example
* Voice.interpret(Object text)
* Voice.interpret(Object text, String interpreter)
* Voice.interpret(Object text, String interpreter, String sink)
* Voice.say(Object text)
* Voice.say(Object text, String voice)
* Voice.say(Object text, String voice, String sink)
* Voice.say(Object text, String voice, String sink, PercentType volume)
* Voice.say(Object text, String voice, PercentType volume)
* Voice.say(Object text, PercentType volume)
*
* @name Voice
* @memberof actions
*/
const Voice = Java.type('org.openhab.core.model.script.actions.Voice');
[Audio, BusEvent, Ephemeris, Exec, HTTP, LogAction, Ping, ScriptExecution, Semantics, ThingsAction, Voice].forEach(function (item) {
exports[item.class.getSimpleName()] = item.class.static;
});
exports.get = (...args) => actions.get(...args);
exports.thingActions = (bindingId, thingUid) => Things.getActions(bindingId, thingUid);