ruby-macrodroid 0.8.11 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/ruby-macrodroid.rb +16 -330
- data/lib/ruby-macrodroid/actions.rb +199 -35
- data/lib/ruby-macrodroid/base.rb +21 -15
- data/lib/ruby-macrodroid/constraints.rb +1338 -0
- data/lib/ruby-macrodroid/macro.rb +528 -47
- data/lib/ruby-macrodroid/triggers.rb +46 -14
- metadata +11 -10
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 73bd85e05b55cb8139d501f96e7f0692a052d4544dcd518b73e4e1168ffcb0dd
|
4
|
+
data.tar.gz: 92d7670d08882e34f16085ca22da3a5affc8aa84c3eb89b3f6ec2800c4172501
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7361a05b044e4d759728a91d86952f6273a8bfbfc72ff1ac9965f97cd858dd8ad3902cb4cb72f4e0557a291627a631a75d7f4ef0a04481969b8ac91bcd3eb48e
|
7
|
+
data.tar.gz: b7ef1815fe2b3e4ff42de13e34c8a663e58a55681aba9e38533c5175ab9a9b197755205175abfe2a013331150bb2f19d4949e41de4f9e3874ea6a4a3981172e2
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/ruby-macrodroid.rb
CHANGED
@@ -38,269 +38,14 @@ require 'rxfhelper'
|
|
38
38
|
require 'chronic_cron'
|
39
39
|
|
40
40
|
|
41
|
+
# PASTE_START
|
42
|
+
|
41
43
|
MODEL =<<EOF
|
42
44
|
device
|
43
45
|
connectivity
|
44
46
|
airplane_mode is disabled
|
45
47
|
EOF
|
46
48
|
|
47
|
-
class TriggersNlp
|
48
|
-
include AppRoutes
|
49
|
-
|
50
|
-
def initialize(macro=nil)
|
51
|
-
|
52
|
-
super()
|
53
|
-
params = {macro: macro}
|
54
|
-
triggers(params)
|
55
|
-
|
56
|
-
end
|
57
|
-
|
58
|
-
def triggers(params)
|
59
|
-
|
60
|
-
# e.g. at 7:30pm daily
|
61
|
-
get /^(?:at )?(\d+:\d+(?:[ap]m)?) daily/i do |time, days|
|
62
|
-
[TimerTrigger, {time: time,
|
63
|
-
days: %w(Mon Tue Wed Thu Fri Sat Sun).join(', ')}]
|
64
|
-
end
|
65
|
-
|
66
|
-
get /^(?:at )?(\d+:\d+(?:[ap]m)?) (?:on )?(.*)/i do |time, days|
|
67
|
-
[TimerTrigger, {time: time, days: days}]
|
68
|
-
end
|
69
|
-
|
70
|
-
# time.is? 'at 18:30pm on Mon or Tue'
|
71
|
-
get /^time.is\? ['"](?:at )?(\d+:\d+(?:[ap]m)?) (?:on )?(.*)['"]/i do |time, days|
|
72
|
-
[TimerTrigger, {time: time, days: days.gsub(' or ',', ')}]
|
73
|
-
end
|
74
|
-
|
75
|
-
get /^shake[ _]device\??$/i do
|
76
|
-
[ShakeDeviceTrigger, {}]
|
77
|
-
end
|
78
|
-
|
79
|
-
get /^Flip Device (.*)$/i do |motion|
|
80
|
-
facedown = motion =~ /Face Up (?:->|to) Face Down/i
|
81
|
-
[FlipDeviceTrigger, {face_down: facedown }]
|
82
|
-
end
|
83
|
-
|
84
|
-
get /^flip_device_down\?$/i do
|
85
|
-
[FlipDeviceTrigger, {face_down: true }]
|
86
|
-
end
|
87
|
-
|
88
|
-
get /^flip_device_up\?$/i do
|
89
|
-
[FlipDeviceTrigger, {face_down: false }]
|
90
|
-
end
|
91
|
-
|
92
|
-
get /^Failed Login Attempt$/i do
|
93
|
-
[FailedLoginTrigger, {}]
|
94
|
-
end
|
95
|
-
|
96
|
-
get /^failed_login?$/i do
|
97
|
-
[FailedLoginTrigger, {}]
|
98
|
-
end
|
99
|
-
|
100
|
-
get /^Geofence (Entry|Exit) \(([^\)]+)/i do |direction, name|
|
101
|
-
enter_area = direction.downcase.to_sym == :entry
|
102
|
-
[GeofenceTrigger, {name: name, enter_area: enter_area}]
|
103
|
-
end
|
104
|
-
|
105
|
-
get /^location (entered|exited) \(([^\)]+)/i do |direction, name|
|
106
|
-
enter_area = direction.downcase.to_sym == :entered
|
107
|
-
[GeofenceTrigger, {name: name, enter_area: enter_area}]
|
108
|
-
end
|
109
|
-
|
110
|
-
# eg. Proximity Sensor (Near)
|
111
|
-
#
|
112
|
-
get /^Proximity Sensor \(([^\)]+)\)/i do |distance|
|
113
|
-
|
114
|
-
[ProximityTrigger, {distance: distance}]
|
115
|
-
end
|
116
|
-
|
117
|
-
get /^WebHook \(Url\)/i do
|
118
|
-
[WebHookTrigger, params]
|
119
|
-
end
|
120
|
-
|
121
|
-
get /^WebHook/i do
|
122
|
-
[WebHookTrigger, params]
|
123
|
-
end
|
124
|
-
|
125
|
-
get /^wh/i do
|
126
|
-
[WebHookTrigger, params]
|
127
|
-
end
|
128
|
-
|
129
|
-
|
130
|
-
end
|
131
|
-
|
132
|
-
alias find_trigger run_route
|
133
|
-
|
134
|
-
def to_s(colour: false)
|
135
|
-
'TriggersNlp ' + @h.inspect
|
136
|
-
end
|
137
|
-
|
138
|
-
alias to_summary to_s
|
139
|
-
end
|
140
|
-
|
141
|
-
class ActionsNlp
|
142
|
-
include AppRoutes
|
143
|
-
|
144
|
-
def initialize()
|
145
|
-
|
146
|
-
super()
|
147
|
-
params = {}
|
148
|
-
actions(params)
|
149
|
-
|
150
|
-
end
|
151
|
-
|
152
|
-
def actions(params)
|
153
|
-
|
154
|
-
# e.g. message popup: hello world!
|
155
|
-
get /^message popup: (.*)/i do |msg|
|
156
|
-
[ToastAction, {msg: msg}]
|
157
|
-
end
|
158
|
-
|
159
|
-
# e.g. Popup Message 'hello world!'
|
160
|
-
get /^Popup[ _]Message ['"]([^'"]+)/i do |msg|
|
161
|
-
[ToastAction, {msg: msg}]
|
162
|
-
end
|
163
|
-
|
164
|
-
# e.g. Popup Message\n hello world!
|
165
|
-
get /^Popup Message\n\s+(.*)/im do |msg|
|
166
|
-
[ToastAction, {msg: msg}]
|
167
|
-
end
|
168
|
-
|
169
|
-
# e.g. Popup Message
|
170
|
-
get /^Popup Message$/i do
|
171
|
-
[ToastAction, {}]
|
172
|
-
end
|
173
|
-
|
174
|
-
# e.g. say current time
|
175
|
-
get /^say current[ _]time/i do
|
176
|
-
[SayTimeAction, {}]
|
177
|
-
end
|
178
|
-
|
179
|
-
get /^Torch :?(.*)/i do |onoffstate|
|
180
|
-
state = %w(on off toggle).index onoffstate.downcase
|
181
|
-
[CameraFlashLightAction, {state: state}]
|
182
|
-
end
|
183
|
-
|
184
|
-
get /^Take Picture/i do
|
185
|
-
[TakePictureAction, {}]
|
186
|
-
end
|
187
|
-
|
188
|
-
get /^take_picture/i do
|
189
|
-
[TakePictureAction, {}]
|
190
|
-
end
|
191
|
-
|
192
|
-
# e.g. Display Notification: Hi there: This is the body of the message
|
193
|
-
get /^Display Notification: ([^:]+): [^$]+$/i do |subject, text|
|
194
|
-
[NotificationAction, {subject: subject, text: text}]
|
195
|
-
end
|
196
|
-
|
197
|
-
|
198
|
-
# e.g. Enable Wifi
|
199
|
-
get /^(Enable|Disable) Wifi$/i do |raw_state|
|
200
|
-
|
201
|
-
state = raw_state.downcase.to_sym == :enable ? 0 : 1
|
202
|
-
[SetWifiAction, {state: state}]
|
203
|
-
|
204
|
-
end
|
205
|
-
|
206
|
-
# e.g. Play: Altair
|
207
|
-
get /^Play: (.*)$/i do |name|
|
208
|
-
|
209
|
-
[PlaySoundAction, {file_path: name}]
|
210
|
-
|
211
|
-
end
|
212
|
-
|
213
|
-
# e.g. Launch Settings
|
214
|
-
get /^Launch (.*)$/i do |application|
|
215
|
-
|
216
|
-
h = {
|
217
|
-
application_name: application,
|
218
|
-
package_to_launch: 'com.android.' + application.downcase
|
219
|
-
}
|
220
|
-
[LaunchActivityAction, h]
|
221
|
-
|
222
|
-
end
|
223
|
-
|
224
|
-
# e.g. HTTP GET http://someurl.com/something
|
225
|
-
get /^HTTP GET ([^$]+)$/i do |url|
|
226
|
-
|
227
|
-
[OpenWebPageAction, url_to_open: url]
|
228
|
-
|
229
|
-
end
|
230
|
-
|
231
|
-
# e.g. webhook entered_kitchen
|
232
|
-
#
|
233
|
-
get /webhook|HTTP GET/i do
|
234
|
-
[OpenWebPageAction, {}]
|
235
|
-
end
|
236
|
-
|
237
|
-
#a: Keep Device Awake Screen On Until Disabled
|
238
|
-
#
|
239
|
-
get /Keep Device Awake Screen On Until Disabled/i do
|
240
|
-
[KeepAwakeAction, {enabled: true, permanent: true, screen_option: 0}]
|
241
|
-
end
|
242
|
-
|
243
|
-
|
244
|
-
#a: Keep Device Awake Screen On 1h 1m 1s
|
245
|
-
#
|
246
|
-
get /Keep Device Awake Screen On ([^$]+)/i do |duration|
|
247
|
-
|
248
|
-
a = duration.split.map(&:to_i)
|
249
|
-
secs = Subunit.new(units={minutes:60, hours:60, seconds: 60}, a).to_i
|
250
|
-
|
251
|
-
h = {
|
252
|
-
permanent: true, screen_option: 0, seconds_to_stay_awake_for: secs
|
253
|
-
}
|
254
|
-
[KeepAwakeAction, h]
|
255
|
-
end
|
256
|
-
|
257
|
-
#a: Disable Keep Awake
|
258
|
-
#
|
259
|
-
get /Disable Keep Awake/i do
|
260
|
-
[KeepAwakeAction, {enabled: false, screen_option: 0}]
|
261
|
-
end
|
262
|
-
|
263
|
-
#e.g a: if Airplane mode enabled
|
264
|
-
#
|
265
|
-
get /if (.*)/i do
|
266
|
-
[IfConditionAction, {}]
|
267
|
-
end
|
268
|
-
|
269
|
-
get /End If/i do
|
270
|
-
[EndIfAction, {}]
|
271
|
-
end
|
272
|
-
|
273
|
-
end
|
274
|
-
|
275
|
-
alias find_action run_route
|
276
|
-
|
277
|
-
|
278
|
-
end
|
279
|
-
|
280
|
-
class ConstraintsNlp
|
281
|
-
include AppRoutes
|
282
|
-
|
283
|
-
def initialize()
|
284
|
-
|
285
|
-
super()
|
286
|
-
params = {}
|
287
|
-
constraints(params)
|
288
|
-
|
289
|
-
end
|
290
|
-
|
291
|
-
def constraints(params)
|
292
|
-
|
293
|
-
get /^airplane mode (.*)/i do |state|
|
294
|
-
[AirplaneModeConstraint, {enabled: (state =~ /^enabled|on$/i) == 0}]
|
295
|
-
end
|
296
|
-
|
297
|
-
end
|
298
|
-
|
299
|
-
alias find_constraint run_route
|
300
|
-
|
301
|
-
end
|
302
|
-
|
303
|
-
|
304
49
|
module Params
|
305
50
|
|
306
51
|
refine Hash do
|
@@ -330,16 +75,16 @@ module Params
|
|
330
75
|
end
|
331
76
|
|
332
77
|
# turns keys from snake_case to CamelCase
|
333
|
-
def
|
78
|
+
def to_camelcase(h=self)
|
334
79
|
|
335
80
|
h.inject({}) do |r,x|
|
336
81
|
|
337
82
|
key, value = x
|
338
83
|
|
339
84
|
val = if value.is_a?(Hash) then
|
340
|
-
|
85
|
+
to_camelcase(value)
|
341
86
|
elsif value.is_a?(Array) and value.first.is_a? Hash
|
342
|
-
value.map {|row|
|
87
|
+
value.map {|row| to_camelcase(row)}
|
343
88
|
else
|
344
89
|
value
|
345
90
|
end
|
@@ -356,8 +101,6 @@ end
|
|
356
101
|
|
357
102
|
|
358
103
|
|
359
|
-
|
360
|
-
|
361
104
|
class MacroDroidError < Exception
|
362
105
|
end
|
363
106
|
|
@@ -367,14 +110,14 @@ class MacroDroid
|
|
367
110
|
using Params
|
368
111
|
|
369
112
|
attr_reader :macros, :geofences, :yaml
|
370
|
-
attr_accessor :deviceid
|
113
|
+
attr_accessor :deviceid, :remote_url
|
371
114
|
|
372
115
|
# note: The deviceid can only be found from an existing Webhook trigger,
|
373
116
|
# generated from MacroDroid itself.
|
374
117
|
|
375
|
-
def initialize(obj=nil, deviceid: nil, debug: false)
|
118
|
+
def initialize(obj=nil, deviceid: nil, remote_url: nil, debug: false)
|
376
119
|
|
377
|
-
@deviceid, @debug = deviceid, debug
|
120
|
+
@deviceid, @remote_url, @debug = deviceid, remote_url, debug
|
378
121
|
|
379
122
|
@geofences = {}
|
380
123
|
|
@@ -403,8 +146,9 @@ class MacroDroid
|
|
403
146
|
puts 'before RowX.new' if @debug
|
404
147
|
|
405
148
|
s2 = s.gsub(/^g:/,'geofence:').gsub(/^m:/,'macro:')\
|
406
|
-
.gsub(/^
|
407
|
-
.gsub(/^
|
149
|
+
.gsub(/^d:/,'description:').gsub(/^v:/,'variable:')\
|
150
|
+
.gsub(/^t:/,'trigger:').gsub(/^a:/,'action:')\
|
151
|
+
.gsub(/^c:/,'constraint:').gsub(/^#.*/,'')
|
408
152
|
|
409
153
|
a = s2.split(/(?=^macro:)/)
|
410
154
|
|
@@ -424,7 +168,7 @@ class MacroDroid
|
|
424
168
|
|
425
169
|
end
|
426
170
|
|
427
|
-
xml = RowX.new(raw_macros).to_xml
|
171
|
+
xml = RowX.new(raw_macros, allow_lonely_keyfield: true).to_xml
|
428
172
|
puts 'xml: ' + xml if @debug
|
429
173
|
import_rowxml(xml)
|
430
174
|
|
@@ -499,7 +243,7 @@ class MacroDroid
|
|
499
243
|
},
|
500
244
|
macro_list: @macros.map(&:to_h)
|
501
245
|
}
|
502
|
-
@h.merge(h).
|
246
|
+
@h.merge(h).to_camelcase
|
503
247
|
|
504
248
|
end
|
505
249
|
|
@@ -590,7 +334,7 @@ class MacroDroid
|
|
590
334
|
# puts '@geofences: ' + @geofences.inspect if @debug
|
591
335
|
|
592
336
|
m = Macro.new(geofences: @geofences.map(&:last), deviceid: @deviceid,
|
593
|
-
debug: @debug )
|
337
|
+
remote_url: @remote_url, debug: @debug )
|
594
338
|
m.import_h(macro)
|
595
339
|
m
|
596
340
|
|
@@ -612,7 +356,7 @@ class MacroDroid
|
|
612
356
|
@macros = doc.root.xpath('item').map do |node|
|
613
357
|
puts ('geofences: ' + geofences.inspect).highlight if @debug
|
614
358
|
Macro.new(geofences: geofences.map(&:last), deviceid: @deviceid,
|
615
|
-
debug: @debug).import_xml(node)
|
359
|
+
remote_url: @remote_url, debug: @debug).import_xml(node)
|
616
360
|
|
617
361
|
end
|
618
362
|
|
@@ -835,65 +579,7 @@ class DroidSim
|
|
835
579
|
|
836
580
|
end
|
837
581
|
|
838
|
-
|
839
|
-
m: Torch
|
840
|
-
t: webhook
|
841
|
-
a: Torch toggle
|
842
|
-
EOF
|
843
|
-
|
844
|
-
module RemoteDroid
|
845
|
-
|
846
|
-
class Service
|
847
|
-
def initialize(callback)
|
848
|
-
@callback = callback
|
849
|
-
end
|
850
|
-
end
|
851
|
-
|
852
|
-
class Bluetooth
|
853
|
-
def enable()
|
854
|
-
end
|
855
|
-
end
|
856
|
-
|
857
|
-
class Torch < Service
|
858
|
-
|
859
|
-
def toggle()
|
860
|
-
@callback.call :torch
|
861
|
-
end
|
862
|
-
|
863
|
-
end
|
864
|
-
|
865
|
-
class Control
|
866
|
-
|
867
|
-
def initialize(deviceid: nil)
|
868
|
-
@deviceid = deviceid
|
869
|
-
@torch = Torch.new(self)
|
870
|
-
end
|
871
|
-
|
872
|
-
def bluetooth()
|
873
|
-
@bluetooth
|
874
|
-
end
|
875
|
-
|
876
|
-
def call(command)
|
877
|
-
url = "https://trigger.macrodroid.com/%s/%s" % [@deviceid, command]
|
878
|
-
puts 'url: ' + url.inspect
|
879
|
-
s = open(url).read
|
880
|
-
end
|
881
|
-
|
882
|
-
def torch()
|
883
|
-
@torch
|
884
|
-
end
|
885
|
-
|
886
|
-
def write(s)
|
887
|
-
|
888
|
-
MacroDroid.new(RD_MACROS, deviceid: @deviceid).export s
|
889
|
-
|
890
|
-
end
|
891
|
-
|
892
|
-
alias export write
|
893
|
-
|
894
|
-
end
|
895
|
-
|
896
|
-
end
|
582
|
+
# PASTE_END
|
897
583
|
|
898
584
|
require 'ruby-macrodroid/base'
|
899
585
|
require 'ruby-macrodroid/triggers'
|
@@ -49,8 +49,8 @@ class Action < MacroObject
|
|
49
49
|
|
50
50
|
end
|
51
51
|
|
52
|
-
def invoke(
|
53
|
-
"%s/%s: %s" % [@group, @type,
|
52
|
+
def invoke(h={})
|
53
|
+
"%s/%s: %s" % [@group, @type, h.to_json]
|
54
54
|
end
|
55
55
|
|
56
56
|
|
@@ -136,26 +136,95 @@ class LaunchShortcutAction < ApplicationAction
|
|
136
136
|
|
137
137
|
end
|
138
138
|
|
139
|
+
class OpenWebPageActionError < Exception
|
140
|
+
end
|
141
|
+
|
139
142
|
# Category: Applications
|
140
143
|
#
|
141
144
|
class OpenWebPageAction < ApplicationAction
|
142
145
|
|
143
|
-
def initialize(
|
146
|
+
def initialize(obj={}, macro=nil)
|
147
|
+
|
148
|
+
# puts 'obj: ' + obj[0].xml.inspect
|
149
|
+
|
150
|
+
h = if obj.is_a? Hash then
|
151
|
+
|
152
|
+
obj
|
153
|
+
|
154
|
+
elsif obj.is_a? Array
|
155
|
+
|
156
|
+
puts 'obj: ' + obj.inspect if $debug
|
157
|
+
e, macro = obj
|
158
|
+
|
159
|
+
a = e.xpath('item/*')
|
160
|
+
|
161
|
+
h2 = if a.any? then
|
162
|
+
a.map {|node| [node.name.to_sym, node.text.to_s]}.to_h
|
163
|
+
else
|
164
|
+
txt = e.text('item/description')
|
165
|
+
{url: (txt || e.text)}
|
166
|
+
end
|
167
|
+
|
168
|
+
h2.merge(macro: macro)
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
puts 'h:' + h.inspect if $debug
|
144
173
|
|
145
|
-
h[:url_to_open] = h[:url] if h[:url]
|
174
|
+
#h[:url_to_open] = h[:url] if h[:url] and h[:url].length > 1
|
146
175
|
|
147
176
|
options = {
|
148
|
-
variable_to_save_response: {:
|
177
|
+
variable_to_save_response: {:string_value=>"", :name=>"coords",
|
178
|
+
decimal_value: 0.0, isLocal: true, m_boolean_value: false,
|
179
|
+
excludeFromLog: false, int_value: 0, type: 2},
|
149
180
|
url_to_open: '',
|
150
181
|
http_get: true,
|
151
182
|
disable_url_encode: false,
|
152
183
|
block_next_action: false
|
153
184
|
}
|
185
|
+
|
186
|
+
return super(options.merge h) if h[:url_to_open]
|
187
|
+
|
188
|
+
if h[:macro].remote_url.nil? and (h[:url].nil? or h[:url].empty?) then
|
189
|
+
raise OpenWebPageActionError, 'remote_url not found'
|
190
|
+
end
|
191
|
+
|
192
|
+
url = if h[:url] and h[:url].length > 1 then
|
193
|
+
|
194
|
+
h[:url]
|
154
195
|
|
155
|
-
|
196
|
+
elsif h2 and h[:macro].remote_url and h[:identifier]
|
197
|
+
|
198
|
+
"%s/%s" % [h[:macro].remote_url.sub(/\/$/,''), h[:identifier]]
|
199
|
+
|
200
|
+
elsif (h[:identifier].nil? or h[:identifier].empty?)
|
201
|
+
|
202
|
+
h[:url_to_open] = h[:macro].remote_url.sub(/\/$/,'') + '/' +
|
203
|
+
h[:macro].title.downcase.gsub(/ +/,'-')
|
204
|
+
|
205
|
+
end
|
206
|
+
|
207
|
+
if h2 then
|
208
|
+
|
209
|
+
h2.delete :identifier
|
210
|
+
h2.delete :url
|
211
|
+
|
212
|
+
if h2.any? then
|
213
|
+
url += '?' + \
|
214
|
+
URI.escape(h2.map {|key,value| "%s=%s" % [key, value]}.join('&'))
|
215
|
+
end
|
216
|
+
|
217
|
+
end
|
218
|
+
|
219
|
+
h[:url_to_open] = url
|
220
|
+
super(options.merge h)
|
156
221
|
|
157
222
|
end
|
158
223
|
|
224
|
+
def invoke()
|
225
|
+
super(url: @h[:url_to_open])
|
226
|
+
end
|
227
|
+
|
159
228
|
def to_s(colour: false, indent: 0)
|
160
229
|
@s = "HTTP GET\nurl: " + @h[:url_to_open]
|
161
230
|
super()
|
@@ -332,9 +401,10 @@ class IfConditionAction < Action
|
|
332
401
|
h2 = options.merge(filter(options,h).merge(macro: macro))
|
333
402
|
super(h2)
|
334
403
|
|
335
|
-
elsif obj.is_a?
|
404
|
+
elsif obj.is_a? Array
|
405
|
+
e, macro = obj
|
336
406
|
super()
|
337
|
-
raw_txt =
|
407
|
+
raw_txt = e.text('item/description') || e.text.to_s
|
338
408
|
puts 'raw_txt: ' + raw_txt.inspect if $debug
|
339
409
|
|
340
410
|
clause = raw_txt[/^if (.*)/i,1]
|
@@ -368,7 +438,7 @@ class IfConditionAction < Action
|
|
368
438
|
def to_s(colour: false, indent: 0)
|
369
439
|
|
370
440
|
h = @h.clone
|
371
|
-
h.delete :macro
|
441
|
+
#h.delete :macro
|
372
442
|
@s = 'If '
|
373
443
|
operator = @h[:is_or_condition] ? 'OR' : 'AND'
|
374
444
|
constraints = @constraints.map \
|
@@ -448,6 +518,8 @@ class EndIfAction < Action
|
|
448
518
|
obj
|
449
519
|
elsif obj.is_a? Rexle::Element
|
450
520
|
{}
|
521
|
+
else
|
522
|
+
{}
|
451
523
|
end
|
452
524
|
|
453
525
|
|
@@ -455,7 +527,7 @@ class EndIfAction < Action
|
|
455
527
|
constraint_list: []
|
456
528
|
}
|
457
529
|
|
458
|
-
super(
|
530
|
+
super()
|
459
531
|
|
460
532
|
end
|
461
533
|
|
@@ -700,9 +772,10 @@ class SayTimeAction < DateTimeAction
|
|
700
772
|
end
|
701
773
|
|
702
774
|
def invoke()
|
703
|
-
time = ($env and $env[:time]) ? $env[:time] : Time.now
|
775
|
+
#time = ($env and $env[:time]) ? $env[:time] : Time.now
|
776
|
+
time = Time.now
|
704
777
|
tformat = @h['12_hour'] ? "%-I:%M%P" : "%H:%M"
|
705
|
-
super(time.strftime(tformat))
|
778
|
+
super(txt: time.strftime(tformat))
|
706
779
|
end
|
707
780
|
|
708
781
|
def to_pc()
|
@@ -791,10 +864,18 @@ end
|
|
791
864
|
#
|
792
865
|
class SpeakTextAction < DeviceAction
|
793
866
|
|
794
|
-
def initialize(
|
795
|
-
|
867
|
+
def initialize(obj=nil)
|
868
|
+
|
869
|
+
h = if obj.is_a? Hash then
|
870
|
+
obj
|
871
|
+
elsif obj.is_a? Array
|
872
|
+
e, macro = obj
|
873
|
+
txt = e.text('item/description')
|
874
|
+
{text: (txt || e.text)}
|
875
|
+
end
|
876
|
+
|
796
877
|
options = {
|
797
|
-
text_to_say: '',
|
878
|
+
text_to_say: h[:text] || '',
|
798
879
|
queue: false,
|
799
880
|
read_numbers_individually: false,
|
800
881
|
specify_audio_stream: false,
|
@@ -808,8 +889,13 @@ class SpeakTextAction < DeviceAction
|
|
808
889
|
|
809
890
|
end
|
810
891
|
|
892
|
+
def invoke()
|
893
|
+
super(text: @h[:text_to_say])
|
894
|
+
end
|
895
|
+
|
811
896
|
def to_s(colour: false, indent: 0)
|
812
|
-
"Speak Text (%s)" % @h[:text_to_say]
|
897
|
+
@s = "Speak Text (%s)" % @h[:text_to_say]
|
898
|
+
super()
|
813
899
|
end
|
814
900
|
|
815
901
|
end
|
@@ -961,6 +1047,9 @@ class CameraFlashLightAction < DeviceSettingsAction
|
|
961
1047
|
super(options.merge h)
|
962
1048
|
|
963
1049
|
end
|
1050
|
+
def invoke()
|
1051
|
+
super(state: @h[:state])
|
1052
|
+
end
|
964
1053
|
|
965
1054
|
def to_pc()
|
966
1055
|
['torch :on', 'torch :off', 'torch :toggle'][@h[:state]]
|
@@ -977,7 +1066,17 @@ end
|
|
977
1066
|
class VibrateAction < DeviceSettingsAction
|
978
1067
|
|
979
1068
|
def initialize(h={})
|
980
|
-
|
1069
|
+
|
1070
|
+
pattern = [
|
1071
|
+
'Blip', 'Short Buzz', 'Long Buzz', 'Rapid', 'Slow', 'Increasing',
|
1072
|
+
'Constant', 'Decreasing', 'Final Fantasy', 'Game Over', 'Star Wars',
|
1073
|
+
'Mini Blip', 'Micro Blip'
|
1074
|
+
]
|
1075
|
+
|
1076
|
+
if h[:pattern] then
|
1077
|
+
h[:vibrate_pattern] = pattern.map(&:downcase).index h[:pattern]
|
1078
|
+
end
|
1079
|
+
|
981
1080
|
options = {
|
982
1081
|
vibrate_pattern: 1
|
983
1082
|
}
|
@@ -1265,7 +1364,7 @@ class ForceLocationUpdateAction < LocationAction
|
|
1265
1364
|
end
|
1266
1365
|
|
1267
1366
|
def to_s(colour: false, indent: 0)
|
1268
|
-
'
|
1367
|
+
'Force Location Update' #+ @h.inspect
|
1269
1368
|
end
|
1270
1369
|
|
1271
1370
|
alias to_summary to_s
|
@@ -1286,26 +1385,34 @@ end
|
|
1286
1385
|
#
|
1287
1386
|
class ShareLocationAction < LocationAction
|
1288
1387
|
|
1289
|
-
def initialize(
|
1388
|
+
def initialize(obj=nil)
|
1290
1389
|
|
1291
|
-
|
1390
|
+
h = if obj.is_a? Hash then
|
1391
|
+
obj
|
1392
|
+
elsif obj.is_a? Array
|
1393
|
+
e, macro = obj
|
1394
|
+
{variable: macro.set_var(e.text('item/description').to_s)}
|
1395
|
+
|
1396
|
+
end
|
1397
|
+
|
1398
|
+
#super()
|
1292
1399
|
|
1293
1400
|
options = {
|
1294
1401
|
email: '',
|
1295
|
-
variable: {:
|
1296
|
-
:
|
1297
|
-
:
|
1402
|
+
variable: {:string_value=>"", :name=>"",
|
1403
|
+
:decimal_value=>0.0, :is_local=>true, :boolean_value=>false,
|
1404
|
+
:exclude_from_log=>false, :int_value=>0, :type=>2},
|
1298
1405
|
sim_id: 0,
|
1299
1406
|
output_channel: 5,
|
1300
1407
|
old_variable_format: true
|
1301
1408
|
}
|
1302
|
-
|
1409
|
+
#options[:variable].merge! h
|
1303
1410
|
super(options.merge h)
|
1304
1411
|
|
1305
1412
|
end
|
1306
1413
|
|
1307
1414
|
def to_s(colour: false, indent: 0)
|
1308
|
-
@s = 'Share Location' + "\
|
1415
|
+
@s = 'Share Location' + "\n" + @h[:variable][:name] # + @h.inspect
|
1309
1416
|
super()
|
1310
1417
|
end
|
1311
1418
|
|
@@ -1500,7 +1607,15 @@ end
|
|
1500
1607
|
#
|
1501
1608
|
class SetVariableAction < Action
|
1502
1609
|
|
1503
|
-
def initialize(
|
1610
|
+
def initialize(obj=nil)
|
1611
|
+
|
1612
|
+
h = if obj.is_a? Hash then
|
1613
|
+
obj
|
1614
|
+
elsif obj.is_a? Array
|
1615
|
+
e, macro = obj
|
1616
|
+
node = e.element('item/*')
|
1617
|
+
macro.set_var node.name, node.value.to_s
|
1618
|
+
end
|
1504
1619
|
|
1505
1620
|
options = {
|
1506
1621
|
:user_prompt=>true,
|
@@ -1508,9 +1623,21 @@ class SetVariableAction < Action
|
|
1508
1623
|
:user_prompt_show_cancel=>true,
|
1509
1624
|
:user_prompt_stop_after_cancel=>true,
|
1510
1625
|
:user_prompt_title=>"Word reverse",
|
1511
|
-
:name => 'word'
|
1626
|
+
:name => 'word',
|
1627
|
+
:false_label=>"False", :int_expression=>false, :int_random=>false,
|
1628
|
+
:int_random_max=>0, :int_random_min=>0, :int_value_decrement=>false,
|
1629
|
+
:int_value_increment=>false, :new_boolean_value=>false,
|
1630
|
+
:new_double_value=>0.0, :new_int_value=>0,
|
1631
|
+
:new_string_value=>"[battery]", :true_label=>"True",
|
1632
|
+
:user_prompt=>false, :user_prompt_show_cancel=>true,
|
1633
|
+
:user_prompt_stop_after_cancel=>true,
|
1634
|
+
:variable=>{
|
1635
|
+
:exclude_from_log=>false, :is_local=>true,
|
1636
|
+
:boolean_value=>false, :decimal_value=>0.0,
|
1637
|
+
:int_value=>0, :name=>"foo", :string_value=>"52", :type=>2
|
1638
|
+
}
|
1512
1639
|
}
|
1513
|
-
super(h)
|
1640
|
+
super(options.merge h)
|
1514
1641
|
|
1515
1642
|
end
|
1516
1643
|
|
@@ -1971,11 +2098,10 @@ class ToastAction < NotificationsAction
|
|
1971
2098
|
|
1972
2099
|
h = if obj.is_a? Hash then
|
1973
2100
|
obj
|
1974
|
-
elsif obj.is_a?
|
1975
|
-
|
1976
|
-
|
1977
|
-
|
1978
|
-
{msg: obj}
|
2101
|
+
elsif obj.is_a? Array
|
2102
|
+
e, macro = obj
|
2103
|
+
txt = e.text('item/description')
|
2104
|
+
{msg: (txt || e.text)}
|
1979
2105
|
end
|
1980
2106
|
|
1981
2107
|
if h[:msg] then
|
@@ -1999,7 +2125,7 @@ class ToastAction < NotificationsAction
|
|
1999
2125
|
end
|
2000
2126
|
|
2001
2127
|
def invoke()
|
2002
|
-
super(@h[:message_text])
|
2128
|
+
super(msg: @h[:message_text])
|
2003
2129
|
end
|
2004
2130
|
|
2005
2131
|
def to_pc()
|
@@ -2265,8 +2391,46 @@ end
|
|
2265
2391
|
# disable keep awake => enabled: false
|
2266
2392
|
#
|
2267
2393
|
class KeepAwakeAction < ScreenAction
|
2394
|
+
using ColouredText
|
2268
2395
|
|
2269
|
-
def initialize(
|
2396
|
+
def initialize(obj=nil)
|
2397
|
+
|
2398
|
+
|
2399
|
+
h = if obj.is_a? Hash then
|
2400
|
+
|
2401
|
+
obj
|
2402
|
+
|
2403
|
+
elsif obj.is_a? Array
|
2404
|
+
|
2405
|
+
puts 'obj: ' + obj.inspect if $debug
|
2406
|
+
e, macro = obj
|
2407
|
+
|
2408
|
+
a = e.xpath('item/*')
|
2409
|
+
|
2410
|
+
txt = e.text('item/description')
|
2411
|
+
|
2412
|
+
h2 = if txt then
|
2413
|
+
|
2414
|
+
raw_duration = (txt || e.text).to_s
|
2415
|
+
puts 'raw_duration: ' + raw_duration.inspect
|
2416
|
+
duration = raw_duration[/Screen On - ([^$]+)/i]
|
2417
|
+
{duration: duration}
|
2418
|
+
|
2419
|
+
elsif a.any? then
|
2420
|
+
a.map {|node| [node.name.to_sym, node.text.to_s]}.to_h
|
2421
|
+
end
|
2422
|
+
|
2423
|
+
h2.merge(macro: macro)
|
2424
|
+
|
2425
|
+
end
|
2426
|
+
|
2427
|
+
puts ('h: ' + h.inspect).debug #if $debug
|
2428
|
+
|
2429
|
+
if h[:duration] then
|
2430
|
+
|
2431
|
+
h[:seconds_to_stay_awake_for] = Subunit.hms_to_seconds(h[:duration])
|
2432
|
+
|
2433
|
+
end
|
2270
2434
|
|
2271
2435
|
options = {
|
2272
2436
|
enabled: true,
|