ruby-macrodroid 0.9.4 → 0.9.9
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 +2 -1
- data/lib/ruby-macrodroid.rb +9 -5
- data/lib/ruby-macrodroid/actions.rb +184 -31
- data/lib/ruby-macrodroid/base.rb +23 -14
- data/lib/ruby-macrodroid/constraints.rb +13 -2
- data/lib/ruby-macrodroid/macro.rb +89 -16
- data/lib/ruby-macrodroid/triggers.rb +6 -1
- metadata +2 -2
- 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: 11509c0f7448ef65211af5a07e3191f4292eecfe6c8aa19d79a520b4aaf04f21
|
4
|
+
data.tar.gz: '08960e2e07bf7c467233be373ae1ae8978302122cba7ab6dfca3c5e28cfe7c46'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0dd2c7ef1a69f05eb9eb235aac3a8805522f68731c2f980fd730eb0b34ee15066d23ead4f74c3dbd762fc3bfb31d852bdfb5f637d362a4a4cbe0b4e5de17c338
|
7
|
+
data.tar.gz: 2483d3e4901eb5a839ab3c716674f0fbf0fe925bb94bfa99a71ec5803aab0472235be98dd5773bbb5fd57ee7c8c1c77d242d5e7fbcf5f5bb4dfd09580a24f96a
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
|
1
|
+
�^O�M�?��Y"8��ߝK{X-Ya{�G�n��̶s2f,v�Q������'33��(5#5�m��\d��B��"y�=��g�0���Xo���<��!8xn�{Md%�`O�nc5������� 0��q�;�,a����$Qi{F����
|
2
|
+
�z1ɝP��v��������9Rrf�?��y03�ȦH����p)��Cq� �lL�s.�����<�:
|
data/lib/ruby-macrodroid.rb
CHANGED
@@ -110,14 +110,16 @@ class MacroDroid
|
|
110
110
|
using Params
|
111
111
|
|
112
112
|
attr_reader :macros, :geofences, :yaml
|
113
|
-
attr_accessor :deviceid, :remote_url
|
113
|
+
attr_accessor :deviceid, :remote_url, :picture_path
|
114
114
|
|
115
115
|
# note: The deviceid can only be found from an existing Webhook trigger,
|
116
116
|
# generated from MacroDroid itself.
|
117
117
|
|
118
|
-
def initialize(obj=nil, deviceid: nil, remote_url: nil,
|
118
|
+
def initialize(obj=nil, deviceid: nil, remote_url: nil,
|
119
|
+
picture_path: '/storage/emulated/0/Pictures', debug: false)
|
119
120
|
|
120
121
|
@deviceid, @remote_url, @debug = deviceid, remote_url, debug
|
122
|
+
@picture_path = picture_path
|
121
123
|
|
122
124
|
@geofences = {}
|
123
125
|
|
@@ -334,7 +336,8 @@ class MacroDroid
|
|
334
336
|
# puts '@geofences: ' + @geofences.inspect if @debug
|
335
337
|
|
336
338
|
m = Macro.new(geofences: @geofences.map(&:last), deviceid: @deviceid,
|
337
|
-
remote_url: @remote_url,
|
339
|
+
remote_url: @remote_url, picture_path: @picture_path,
|
340
|
+
debug: @debug )
|
338
341
|
m.import_h(macro)
|
339
342
|
m
|
340
343
|
|
@@ -356,7 +359,8 @@ class MacroDroid
|
|
356
359
|
@macros = doc.root.xpath('item').map do |node|
|
357
360
|
puts ('geofences: ' + geofences.inspect).highlight if @debug
|
358
361
|
Macro.new(geofences: geofences.map(&:last), deviceid: @deviceid,
|
359
|
-
remote_url: @remote_url,
|
362
|
+
remote_url: @remote_url, picture_path: @picture_path,
|
363
|
+
debug: @debug).import_xml(node)
|
360
364
|
|
361
365
|
end
|
362
366
|
|
@@ -380,7 +384,7 @@ class MacroDroid
|
|
380
384
|
@macros = doc.root.xpath('macro').map do |node|
|
381
385
|
puts 'node: ' + node.inspect if @debug
|
382
386
|
Macro.new(geofences: @geofences.map(&:last), deviceid: @deviceid,
|
383
|
-
debug: @debug).import_xml(node)
|
387
|
+
picture_path: @picture_path, debug: @debug).import_xml(node)
|
384
388
|
|
385
389
|
end
|
386
390
|
end
|
@@ -33,6 +33,7 @@
|
|
33
33
|
|
34
34
|
|
35
35
|
class Action < MacroObject
|
36
|
+
using ColouredText
|
36
37
|
using Params
|
37
38
|
include ObjectX
|
38
39
|
|
@@ -142,25 +143,39 @@ end
|
|
142
143
|
|
143
144
|
# Category: Applications
|
144
145
|
#
|
146
|
+
|
147
|
+
|
145
148
|
class OpenWebPageAction < ApplicationAction
|
149
|
+
using ColouredText
|
146
150
|
|
147
151
|
def initialize(obj={}, macro=nil)
|
148
|
-
|
149
|
-
|
152
|
+
|
153
|
+
$debug = true
|
154
|
+
puts ('obj: ' + obj.inspect).debug if $debug
|
150
155
|
|
151
156
|
h = if obj.is_a? Hash then
|
152
157
|
|
153
|
-
obj
|
158
|
+
obj.merge({macro: macro})
|
154
159
|
|
155
160
|
elsif obj.is_a? Array
|
156
161
|
|
157
|
-
puts 'obj: ' + obj.inspect if $debug
|
162
|
+
puts ('obj: ' + obj.inspect).debug if $debug
|
158
163
|
e, macro = obj
|
159
164
|
|
160
165
|
a = e.xpath('item/*')
|
161
166
|
|
162
167
|
h2 = if a.any? then
|
163
|
-
|
168
|
+
|
169
|
+
a.map do |node|
|
170
|
+
|
171
|
+
if node.name == 'description' and node.text.to_s =~ /: / then
|
172
|
+
node.text.to_s.split(/: +/,2).map(&:strip)
|
173
|
+
else
|
174
|
+
[node.name.to_sym, node.text.to_s.strip]
|
175
|
+
end
|
176
|
+
|
177
|
+
end.to_h
|
178
|
+
|
164
179
|
else
|
165
180
|
txt = e.text('item/description')
|
166
181
|
{url: (txt || e.text)}
|
@@ -170,7 +185,7 @@ class OpenWebPageAction < ApplicationAction
|
|
170
185
|
|
171
186
|
end
|
172
187
|
|
173
|
-
puts 'h:' + h.inspect if $debug
|
188
|
+
puts ('h:' + h.inspect).debug if $debug
|
174
189
|
|
175
190
|
#h[:url_to_open] = h[:url] if h[:url] and h[:url].length > 1
|
176
191
|
|
@@ -269,11 +284,64 @@ end
|
|
269
284
|
#
|
270
285
|
class TakePictureAction < CameraAction
|
271
286
|
|
272
|
-
def initialize(
|
287
|
+
def initialize(obj=nil)
|
288
|
+
|
289
|
+
|
290
|
+
h = if obj.is_a? Hash then
|
291
|
+
|
292
|
+
macro = obj[:macro]
|
293
|
+
obj.delete :macro
|
294
|
+
obj
|
295
|
+
|
296
|
+
|
297
|
+
elsif obj.is_a? Array
|
298
|
+
|
299
|
+
e, macro = obj
|
300
|
+
|
301
|
+
puts 'e: ' + e.xml.inspect
|
302
|
+
|
303
|
+
a = e.xpath('item/*')
|
304
|
+
|
305
|
+
if a.any? then
|
306
|
+
|
307
|
+
h2 = a.map {|node| [node.name.to_sym, node.text.to_s.strip]}.to_h
|
308
|
+
|
309
|
+
desc = ''
|
310
|
+
|
311
|
+
if h2[:description] then
|
273
312
|
|
313
|
+
desc = h2[:description]
|
314
|
+
h2.delete :description
|
315
|
+
puts 'desc: ' + desc.inspect
|
316
|
+
|
317
|
+
if desc.length > 1 then
|
318
|
+
|
319
|
+
flash = case desc
|
320
|
+
when /Flash On/i
|
321
|
+
1
|
322
|
+
when /Flash Auto/i
|
323
|
+
2
|
324
|
+
else
|
325
|
+
0
|
326
|
+
end
|
327
|
+
|
328
|
+
|
329
|
+
end
|
330
|
+
|
331
|
+
end
|
332
|
+
|
333
|
+
{
|
334
|
+
use_front_camera: (desc =~ /Front Facing/ ? true : false),
|
335
|
+
flash_option: flash
|
336
|
+
}.merge(h2)
|
337
|
+
|
338
|
+
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
274
342
|
options = {
|
275
|
-
new_path:
|
276
|
-
path:
|
343
|
+
new_path: macro.picture_path,
|
344
|
+
path: macro.picture_path,
|
277
345
|
show_icon: true,
|
278
346
|
use_front_camera: true,
|
279
347
|
flash_option: 0
|
@@ -289,7 +357,22 @@ class TakePictureAction < CameraAction
|
|
289
357
|
end
|
290
358
|
|
291
359
|
def to_s(colour: false, indent: 0)
|
292
|
-
|
360
|
+
|
361
|
+
flash = case @h[:flash_option]
|
362
|
+
when 0
|
363
|
+
''
|
364
|
+
when 1
|
365
|
+
'Flash On'
|
366
|
+
when 2
|
367
|
+
'Flash Auto'
|
368
|
+
end
|
369
|
+
|
370
|
+
@s = 'Take Picture'# + @h.inspect
|
371
|
+
a = [@h[:use_front_camera] ? 'Front Facing' : 'Rear Facing']
|
372
|
+
a << flash if flash.length > 0
|
373
|
+
@s += "\n" + a.join(', ')
|
374
|
+
super()
|
375
|
+
|
293
376
|
end
|
294
377
|
|
295
378
|
end
|
@@ -394,7 +477,7 @@ class IfConditionAction < Action
|
|
394
477
|
a: true,
|
395
478
|
constraint_list: []
|
396
479
|
}
|
397
|
-
puts 'obj: ' + obj.inspect
|
480
|
+
puts 'obj: ' + obj.inspect if $debug
|
398
481
|
|
399
482
|
if obj.is_a? Hash then
|
400
483
|
|
@@ -407,20 +490,20 @@ class IfConditionAction < Action
|
|
407
490
|
|
408
491
|
e, macro = obj
|
409
492
|
super()
|
410
|
-
puts 'e.xml: ' + e.xml
|
411
|
-
puts 'e.text: ' + e.text.to_s.strip
|
493
|
+
puts 'e.xml: ' + e.xml if $debug
|
494
|
+
puts 'e.text: ' + e.text.to_s.strip if $debug
|
412
495
|
raw_txt = e.text.to_s.strip[/^if [^$]+/i] || e.text('item/description')
|
413
|
-
puts 'raw_txt: ' + raw_txt.inspect
|
496
|
+
puts 'raw_txt: ' + raw_txt.inspect if $debug
|
414
497
|
|
415
498
|
clause = raw_txt[/^If (.*)/i,1]
|
416
|
-
puts 'clause: ' + clause.inspect
|
499
|
+
puts 'clause: ' + clause.inspect if $debug
|
417
500
|
conditions = clause.split(/\s+\b(?:AND|OR)\b\s+/i)
|
418
|
-
puts 'conditions: ' + conditions.inspect
|
501
|
+
puts 'conditions: ' + conditions.inspect if $debug
|
419
502
|
|
420
503
|
cp = ConstraintsNlp.new
|
421
504
|
|
422
505
|
@constraints = conditions.map do |c|
|
423
|
-
puts 'c: ' + c.inspect
|
506
|
+
puts 'c: ' + c.inspect if $debug
|
424
507
|
r = cp.find_constraint c
|
425
508
|
puts 'found constraint ' + r.inspect if $debug
|
426
509
|
|
@@ -436,12 +519,16 @@ class IfConditionAction < Action
|
|
436
519
|
|
437
520
|
ap = ActionsNlp.new
|
438
521
|
obj2 = action_to_object(ap, item, item, macro)
|
439
|
-
puts 'obj2: ' + obj2.inspect
|
522
|
+
puts 'obj2: ' + obj2.inspect if $debug
|
440
523
|
#macro.add obj2
|
441
524
|
|
442
525
|
end
|
443
|
-
|
444
|
-
{
|
526
|
+
|
527
|
+
h = {
|
528
|
+
constraint_list: @constraints.map(&:to_h)
|
529
|
+
}
|
530
|
+
super(h) {}
|
531
|
+
|
445
532
|
else
|
446
533
|
# get the constraints
|
447
534
|
|
@@ -476,16 +563,41 @@ end
|
|
476
563
|
|
477
564
|
class ElseAction < Action
|
478
565
|
|
479
|
-
def initialize(
|
566
|
+
def initialize(obj=[])
|
480
567
|
|
481
568
|
options = {
|
482
|
-
constraint_list:
|
569
|
+
constraint_list: []
|
483
570
|
}
|
571
|
+
|
572
|
+
if obj.is_a? Hash then
|
573
|
+
|
574
|
+
h = obj
|
484
575
|
|
485
|
-
|
576
|
+
super(options.merge h)
|
577
|
+
|
578
|
+
elsif obj.is_a? Array
|
579
|
+
|
580
|
+
e, macro = obj
|
581
|
+
|
582
|
+
# find any nested actions
|
583
|
+
item = e.element('item')
|
584
|
+
|
585
|
+
if item then
|
586
|
+
|
587
|
+
ap = ActionsNlp.new
|
588
|
+
obj2 = action_to_object(ap, item, item, macro)
|
589
|
+
puts 'obj2: ' + obj2.inspect if $debug
|
590
|
+
#macro.add obj2
|
591
|
+
|
592
|
+
end
|
593
|
+
|
594
|
+
super(options)
|
595
|
+
end
|
596
|
+
|
486
597
|
|
487
598
|
|
488
|
-
|
599
|
+
|
600
|
+
end
|
489
601
|
|
490
602
|
def to_s(colour: false, indent: 0)
|
491
603
|
'Else'
|
@@ -665,6 +777,9 @@ class SetHotspotAction < ConnectivityAction
|
|
665
777
|
|
666
778
|
def initialize(h={})
|
667
779
|
|
780
|
+
# to-do: check when *disable hotspot*, is the
|
781
|
+
# *enable wifi* option selected?
|
782
|
+
|
668
783
|
options = {
|
669
784
|
device_name: "", state: 0, turn_wifi_on: true, use_legacy_mechanism: false, mechanism: 0
|
670
785
|
|
@@ -675,8 +790,15 @@ class SetHotspotAction < ConnectivityAction
|
|
675
790
|
end
|
676
791
|
|
677
792
|
def to_s(colour: false, indent: 0)
|
678
|
-
|
679
|
-
|
793
|
+
|
794
|
+
@s = "%s HotSpot" % [@h[:state] == 0 ? 'Enable' : 'Disable']
|
795
|
+
|
796
|
+
if @h[:state] == 1 then
|
797
|
+
@s += "\n" + (@h[:turn_wifi_on] ? 'Enable WiFi' : 'Don\'t Enable Wifi')
|
798
|
+
end
|
799
|
+
|
800
|
+
super()
|
801
|
+
|
680
802
|
end
|
681
803
|
end
|
682
804
|
|
@@ -1627,6 +1749,7 @@ end
|
|
1627
1749
|
# MacroDroid Specific
|
1628
1750
|
#
|
1629
1751
|
class SetVariableAction < Action
|
1752
|
+
using ColouredText
|
1630
1753
|
|
1631
1754
|
def initialize(obj=nil)
|
1632
1755
|
|
@@ -1635,7 +1758,14 @@ class SetVariableAction < Action
|
|
1635
1758
|
elsif obj.is_a? Array
|
1636
1759
|
e, macro = obj
|
1637
1760
|
node = e.element('item/*')
|
1638
|
-
|
1761
|
+
#puts ("node.name: %s node.value: %s" % [node.name, node.value]).debug
|
1762
|
+
r = macro.set_var node.name, node.value.to_s
|
1763
|
+
puts ('r: ' + r.inspect).debug if $debug
|
1764
|
+
r
|
1765
|
+
if r[:type] == 2 then
|
1766
|
+
{ variable: {name: r[:name], type: r[:type]}, new_string_value: r[:string_value]
|
1767
|
+
}
|
1768
|
+
end
|
1639
1769
|
end
|
1640
1770
|
|
1641
1771
|
options = {
|
@@ -1758,7 +1888,7 @@ class PauseAction < Action
|
|
1758
1888
|
options = {
|
1759
1889
|
delay_in_milli_seconds: 0, delay_in_seconds: 1, use_alarm: false
|
1760
1890
|
}
|
1761
|
-
super(h)
|
1891
|
+
super(options.merge h)
|
1762
1892
|
|
1763
1893
|
end
|
1764
1894
|
|
@@ -2355,8 +2485,31 @@ end
|
|
2355
2485
|
# Category: Screen
|
2356
2486
|
#
|
2357
2487
|
class ScreenOnAction < ScreenAction
|
2488
|
+
using ColouredText
|
2358
2489
|
|
2359
|
-
def initialize(
|
2490
|
+
def initialize(obj=nil)
|
2491
|
+
|
2492
|
+
debug = false
|
2493
|
+
|
2494
|
+
h = if obj.is_a? Hash then
|
2495
|
+
|
2496
|
+
obj
|
2497
|
+
|
2498
|
+
elsif obj.is_a? Array
|
2499
|
+
=begin
|
2500
|
+
puts 'obj: ' + obj.inspect if debug
|
2501
|
+
e, macro = obj
|
2502
|
+
puts ('e: ' + e.xml.inspect).debug if debug
|
2503
|
+
a = e.xpath('item/*')
|
2504
|
+
|
2505
|
+
txt = e.text.to_s
|
2506
|
+
puts ('txt: ' + txt.inspect).debug if debug
|
2507
|
+
state = txt[/Screen (On|Off)/i,1]
|
2508
|
+
|
2509
|
+
{screen_off: state.downcase == 'off'}
|
2510
|
+
=end
|
2511
|
+
{}
|
2512
|
+
end
|
2360
2513
|
|
2361
2514
|
options = {
|
2362
2515
|
pie_lock_screen: false,
|
@@ -2433,7 +2586,7 @@ class KeepAwakeAction < ScreenAction
|
|
2433
2586
|
h2 = if txt then
|
2434
2587
|
|
2435
2588
|
raw_duration = (txt || e.text).to_s
|
2436
|
-
puts 'raw_duration: ' + raw_duration.inspect
|
2589
|
+
puts 'raw_duration: ' + raw_duration.inspect if $debug
|
2437
2590
|
duration = raw_duration[/Screen On - ([^$]+)/i]
|
2438
2591
|
{duration: duration}
|
2439
2592
|
|
@@ -2445,7 +2598,7 @@ class KeepAwakeAction < ScreenAction
|
|
2445
2598
|
|
2446
2599
|
end
|
2447
2600
|
|
2448
|
-
puts ('h: ' + h.inspect).debug
|
2601
|
+
puts ('h: ' + h.inspect).debug if $debug
|
2449
2602
|
|
2450
2603
|
if h[:duration] then
|
2451
2604
|
|
data/lib/ruby-macrodroid/base.rb
CHANGED
@@ -9,9 +9,10 @@
|
|
9
9
|
|
10
10
|
module ObjectX
|
11
11
|
|
12
|
+
|
12
13
|
def action_to_object(ap, e, item, macro)
|
13
14
|
|
14
|
-
debug =
|
15
|
+
debug = false
|
15
16
|
|
16
17
|
puts 'inside action_to_object: item.xml: ' + item.xml if debug
|
17
18
|
|
@@ -32,21 +33,29 @@ module ObjectX
|
|
32
33
|
|
33
34
|
r = ap.find_action action
|
34
35
|
puts 'r: ' + r.inspect if debug
|
35
|
-
puts 'description: ' + description.xml.inspect if debug
|
36
|
-
#o = r[0].new([description, self]) if r
|
37
|
-
index = macro.actions.length
|
38
|
-
macro.add Action.new
|
39
|
-
o = object_create(r[0],[description, macro]) if r
|
40
|
-
macro.actions[index] = o
|
41
|
-
puts 'after o' if debug
|
42
|
-
o
|
43
36
|
|
37
|
+
if r[1].any? then
|
38
|
+
|
39
|
+
macro.add r[0].new(r[1])
|
40
|
+
|
41
|
+
else
|
42
|
+
|
43
|
+
puts 'description: ' + description.xml.inspect if debug
|
44
|
+
#o = r[0].new([description, self]) if r
|
45
|
+
index = macro.actions.length
|
46
|
+
macro.add Action.new
|
47
|
+
o = object_create(r[0],[description, macro]) if r
|
48
|
+
macro.actions[index] = o
|
49
|
+
puts 'after o' if debug
|
50
|
+
o
|
51
|
+
|
52
|
+
end
|
44
53
|
end
|
45
54
|
|
46
55
|
else
|
47
56
|
|
48
57
|
action = e.text.strip
|
49
|
-
puts 'action: ' + action.inspect if
|
58
|
+
puts 'action: ' + action.inspect if $debug
|
50
59
|
r = ap.find_action action
|
51
60
|
|
52
61
|
a = e.xpath('item/*')
|
@@ -56,7 +65,7 @@ module ObjectX
|
|
56
65
|
else
|
57
66
|
{}
|
58
67
|
end
|
59
|
-
puts 'h: ' + h.inspect if
|
68
|
+
puts 'h: ' + h.inspect if $debug
|
60
69
|
|
61
70
|
#r = ap.find_action action
|
62
71
|
#r[0].new(h.merge(macro: self)) if r
|
@@ -185,11 +194,11 @@ class MacroObject
|
|
185
194
|
private
|
186
195
|
|
187
196
|
def hashify(h)
|
188
|
-
|
197
|
+
puts 'h: ' + h.inspect
|
189
198
|
h2 = h.inject({}) do |r,x|
|
190
|
-
puts 'x: ' + x.inspect if $debug
|
199
|
+
puts 'x: ' + x.inspect #if $debug
|
191
200
|
key, value = x
|
192
|
-
puts 'key: ' + key.inspect if $debug
|
201
|
+
puts 'key: ' + key.inspect #if $debug
|
193
202
|
new_key = key.to_s.gsub(/\w_\w/){|x| x[0] + x[-1].upcase}
|
194
203
|
new_key = new_key.prepend 'm_' unless @list.include? new_key
|
195
204
|
new_key = 'm_SIGUID' if new_key == 'm_siguid'
|
@@ -798,7 +798,18 @@ class MacroDroidVariableConstraint < Constraint
|
|
798
798
|
h[:variable] = {}
|
799
799
|
h[:variable][:name] = h[:loperand]
|
800
800
|
h[:variable][:type] = 2
|
801
|
-
|
801
|
+
|
802
|
+
if h[:roperand] =~ /true|false/i then
|
803
|
+
|
804
|
+
val = h[:roperand].downcase == 'true'
|
805
|
+
h[:boolean_value] = val
|
806
|
+
h[:variable][:type] = 0
|
807
|
+
h[:variable][:boolean_value] = val
|
808
|
+
h[:string_value] = h[:roperand].capitalize
|
809
|
+
else
|
810
|
+
h[:string_value] = h[:roperand]
|
811
|
+
end
|
812
|
+
|
802
813
|
end
|
803
814
|
|
804
815
|
options = {
|
@@ -908,7 +919,7 @@ class TriggerThatInvokedConstraint < Constraint
|
|
908
919
|
|
909
920
|
def initialize(h={})
|
910
921
|
|
911
|
-
puts ('h: ' + h.inspect).green
|
922
|
+
puts ('h: ' + h.inspect).green if $debug
|
912
923
|
@trigger = h[:macro].triggers.find {|x| x.siguid == h[:si_guid_that_invoked] }
|
913
924
|
|
914
925
|
options = {
|
@@ -25,6 +25,7 @@ VAR_TYPES = {
|
|
25
25
|
|
26
26
|
class TriggersNlp
|
27
27
|
include AppRoutes
|
28
|
+
using ColouredText
|
28
29
|
|
29
30
|
def initialize(macro=nil)
|
30
31
|
|
@@ -34,7 +35,46 @@ class TriggersNlp
|
|
34
35
|
|
35
36
|
end
|
36
37
|
|
37
|
-
def triggers(params)
|
38
|
+
def triggers(params)
|
39
|
+
|
40
|
+
# -- Battery/Power ---------------------------------------------
|
41
|
+
|
42
|
+
get /^Power Connected: (Wired \([^\)]+\))/i do |s|
|
43
|
+
|
44
|
+
h = {
|
45
|
+
power_connected_options: [true, true, true],
|
46
|
+
has_set_usb_option: true,
|
47
|
+
power_connected: true
|
48
|
+
}
|
49
|
+
|
50
|
+
a = ['Wired (Fast Charge)', 'Wireless', 'Wired (Slow Charge)']
|
51
|
+
|
52
|
+
puts ('s: ' + s.inspect).debug
|
53
|
+
|
54
|
+
options = s.downcase.split(/ \+ /)
|
55
|
+
puts ('options: ' + options.inspect).debug
|
56
|
+
|
57
|
+
h[:power_connected_options] = a.map {|x| options.include? x.downcase }
|
58
|
+
|
59
|
+
[ExternalPowerTrigger, h]
|
60
|
+
end
|
61
|
+
|
62
|
+
get /^Power Connected: Any/i do |s|
|
63
|
+
|
64
|
+
h = {
|
65
|
+
power_connected_options: [true, true, true],
|
66
|
+
has_set_usb_option: true,
|
67
|
+
power_connected: true
|
68
|
+
}
|
69
|
+
|
70
|
+
[ExternalPowerTrigger, h]
|
71
|
+
end
|
72
|
+
|
73
|
+
# -- Device Events ----------------------------------------------------
|
74
|
+
|
75
|
+
get /^Screen[ _](On|Off)/i do |state|
|
76
|
+
[ScreenOnOffTrigger, {screen_on: state.downcase == 'on'}]
|
77
|
+
end
|
38
78
|
|
39
79
|
# e.g. at 7:30pm daily
|
40
80
|
get /^(?:at )?(\d+:\d+(?:[ap]m)?) daily/i do |time, days|
|
@@ -135,13 +175,25 @@ class ActionsNlp
|
|
135
175
|
def initialize(macro=nil)
|
136
176
|
|
137
177
|
super()
|
178
|
+
|
138
179
|
params = {macro: macro}
|
139
180
|
actions(params)
|
140
181
|
|
141
182
|
end
|
142
183
|
|
143
184
|
def actions(params)
|
144
|
-
|
185
|
+
|
186
|
+
# -- Connectivity ------------------------------------------------------
|
187
|
+
|
188
|
+
get /^(Enable|Disable) HotSpot/i do |state|
|
189
|
+
enable, state = if state.downcase == 'enable' then
|
190
|
+
[true, 0]
|
191
|
+
else
|
192
|
+
[false, 1]
|
193
|
+
end
|
194
|
+
[SetHotspotAction, {turn_wifi_on: enable, state: state }]
|
195
|
+
end
|
196
|
+
|
145
197
|
# e.g. message popup: hello world!
|
146
198
|
get /^message popup: (.*)/i do |msg|
|
147
199
|
[ToastAction, {msg: msg}]
|
@@ -198,6 +250,10 @@ class ActionsNlp
|
|
198
250
|
[VibrateAction, {pattern: pattern}]
|
199
251
|
end
|
200
252
|
|
253
|
+
get /^Vibrate$/i do |pattern|
|
254
|
+
[VibrateAction, {pattern: 'short buzz'}]
|
255
|
+
end
|
256
|
+
|
201
257
|
# e.g. Display Notification: Hi there: This is the body of the message
|
202
258
|
get /^Display Notification: ([^:]+): [^$]+$/i do |subject, text|
|
203
259
|
[NotificationAction, {subject: subject, text: text}]
|
@@ -252,13 +308,13 @@ class ActionsNlp
|
|
252
308
|
|
253
309
|
#
|
254
310
|
get /^WebHook \(Url\)/i do
|
255
|
-
[OpenWebPageAction,
|
311
|
+
[OpenWebPageAction, {}]
|
256
312
|
end
|
257
313
|
|
258
314
|
# e.g. webhook entered_kitchen
|
259
315
|
#
|
260
316
|
get /^webhook$/i do
|
261
|
-
[OpenWebPageAction, params]
|
317
|
+
[OpenWebPageAction, {}, params[:macro]]
|
262
318
|
end
|
263
319
|
|
264
320
|
# -- Location ---------------------------------------------------------
|
@@ -268,7 +324,7 @@ class ActionsNlp
|
|
268
324
|
end
|
269
325
|
|
270
326
|
get /^Share Location$/i do
|
271
|
-
[ShareLocationAction,
|
327
|
+
[ShareLocationAction, {}]
|
272
328
|
end
|
273
329
|
|
274
330
|
#a: Keep Device Awake Screen On Until Disabled
|
@@ -291,13 +347,13 @@ class ActionsNlp
|
|
291
347
|
[KeepAwakeAction, h]
|
292
348
|
end
|
293
349
|
|
294
|
-
get /Keep Device Awake$/i do
|
295
|
-
[KeepAwakeAction,
|
350
|
+
get /(?:Keep Device|stay) Awake$/i do
|
351
|
+
[KeepAwakeAction, {}]
|
296
352
|
end
|
297
353
|
|
298
354
|
#a: Disable Keep Awake
|
299
355
|
#
|
300
|
-
get /Disable Keep Awake/i do
|
356
|
+
get /Disable Keep Awake|stay awake off/i do
|
301
357
|
[KeepAwakeAction, {enabled: false, screen_option: 0}]
|
302
358
|
end
|
303
359
|
|
@@ -307,6 +363,10 @@ class ActionsNlp
|
|
307
363
|
[IfConditionAction, {}]
|
308
364
|
end
|
309
365
|
|
366
|
+
get /else/i do
|
367
|
+
[ElseAction, {}]
|
368
|
+
end
|
369
|
+
|
310
370
|
get /End If/i do
|
311
371
|
[EndIfAction, {}]
|
312
372
|
end
|
@@ -317,6 +377,16 @@ class ActionsNlp
|
|
317
377
|
[SetVariableAction, {}]
|
318
378
|
end
|
319
379
|
|
380
|
+
get /^wait (\d+) seconds$/i do |seconds|
|
381
|
+
[PauseAction, {delay_in_seconds: seconds.to_i}]
|
382
|
+
end
|
383
|
+
|
384
|
+
# -- Screen ------------------------------------------------
|
385
|
+
#
|
386
|
+
get /^Screen (On|Off)$/i do |state|
|
387
|
+
[ScreenOnAction, {screen_off: state.downcase == 'off'}]
|
388
|
+
end
|
389
|
+
|
320
390
|
end
|
321
391
|
|
322
392
|
alias find_action run_route
|
@@ -406,13 +476,13 @@ class Macro
|
|
406
476
|
|
407
477
|
attr_reader :local_variables, :triggers, :actions, :constraints,
|
408
478
|
:guid, :deviceid
|
409
|
-
attr_accessor :title, :description, :remote_url
|
479
|
+
attr_accessor :title, :description, :remote_url, :picture_path
|
410
480
|
|
411
|
-
def initialize(name=nil, geofences: nil, deviceid: nil, remote_url: nil,
|
412
|
-
debug: false)
|
481
|
+
def initialize(name=nil, geofences: nil, deviceid: nil, remote_url: nil, \
|
482
|
+
picture_path: nil, debug: false)
|
413
483
|
|
414
484
|
@title, @geofences, @deviceid, @debug = name, geofences, deviceid, debug
|
415
|
-
@remote_url = remote_url
|
485
|
+
@remote_url, @picture_path = remote_url, picture_path
|
416
486
|
|
417
487
|
puts 'inside Macro#initialize' if @debug
|
418
488
|
|
@@ -422,8 +492,8 @@ class Macro
|
|
422
492
|
end
|
423
493
|
|
424
494
|
def add(obj)
|
425
|
-
puts 'inside add; ' + obj.inspect
|
426
|
-
puts '@actions: ' + @actions.inspect
|
495
|
+
puts 'inside add; ' + obj.inspect if @debug
|
496
|
+
puts '@actions: ' + @actions.inspect if @debug
|
427
497
|
|
428
498
|
if obj.kind_of? Trigger then
|
429
499
|
|
@@ -698,7 +768,7 @@ class Macro
|
|
698
768
|
action = e.text.strip
|
699
769
|
r = ap.find_action action
|
700
770
|
#r[0].new(r[1]) if r
|
701
|
-
self.add object_create(r[0]
|
771
|
+
self.add object_create(r[0],*r[1..-1]) if r
|
702
772
|
|
703
773
|
end
|
704
774
|
|
@@ -774,7 +844,10 @@ class Macro
|
|
774
844
|
if not @local_variables.has_key? label.to_sym then
|
775
845
|
@local_variables.merge!({label.to_sym => value})
|
776
846
|
end
|
777
|
-
|
847
|
+
|
848
|
+
if @debug then
|
849
|
+
puts ("before varify; label: %s value: %s" % [label, value]).debug
|
850
|
+
end
|
778
851
|
varify(label, value)
|
779
852
|
end
|
780
853
|
|
@@ -244,7 +244,7 @@ class ExternalPowerTrigger < Trigger
|
|
244
244
|
|
245
245
|
return 'Power Disconnected' unless @h[:power_connected]
|
246
246
|
|
247
|
-
status = 'Power
|
247
|
+
status = 'Power Connected'
|
248
248
|
options = if @h[:power_connected_options].all? then
|
249
249
|
'Any'
|
250
250
|
else
|
@@ -1199,6 +1199,11 @@ class ScreenOnOffTrigger < DeviceEventsTrigger
|
|
1199
1199
|
|
1200
1200
|
end
|
1201
1201
|
|
1202
|
+
def match?(detail={}, model=nil)
|
1203
|
+
#@h[:screen_on] == detail[:screen_on]
|
1204
|
+
true
|
1205
|
+
end
|
1206
|
+
|
1202
1207
|
def to_s(colour: false)
|
1203
1208
|
'Screen ' + (@h[:screen_on] ? 'On' : 'Off')
|
1204
1209
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby-macrodroid
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.9
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
NZ2kdBIUDnAM24e0/wXdVxg4HnsZbdymxyzMQ4P5pKYcpI6oisBxI37p/Xy+wAg3
|
36
36
|
SBHno3GEuuD8ZWj24IMJpfbp
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2020-10-
|
38
|
+
date: 2020-10-17 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: glw
|
metadata.gz.sig
CHANGED
Binary file
|