ruby-macrodroid 0.9.3 → 0.9.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 73bd85e05b55cb8139d501f96e7f0692a052d4544dcd518b73e4e1168ffcb0dd
4
- data.tar.gz: 92d7670d08882e34f16085ca22da3a5affc8aa84c3eb89b3f6ec2800c4172501
3
+ metadata.gz: f79a66c628c78bab4c858805ac6486083331723153022cb23030485701b16eea
4
+ data.tar.gz: d2bf06bef9e246852f4ec40a31f267ce2f94b66293318fb82ea864a4d5c15e0e
5
5
  SHA512:
6
- metadata.gz: 7361a05b044e4d759728a91d86952f6273a8bfbfc72ff1ac9965f97cd858dd8ad3902cb4cb72f4e0557a291627a631a75d7f4ef0a04481969b8ac91bcd3eb48e
7
- data.tar.gz: b7ef1815fe2b3e4ff42de13e34c8a663e58a55681aba9e38533c5175ab9a9b197755205175abfe2a013331150bb2f19d4949e41de4f9e3874ea6a4a3981172e2
6
+ metadata.gz: 00ab9a577c80b81d017ebbb35d3e8a746d1d78ddde05473dd87be5c6a5365a3d7ed83e3501cf0402e3b2919be7dff1fe59f1e12c2f309649b69e3fd99e19824d
7
+ data.tar.gz: fa4786c3f3bc343b6e242f5c8abfb6a438edae01df19b623b3d7b27fb610bc4c56f323071ea76890700b6493ede5df714a55f9b2ef619f1c37104832a59d75f8
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -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, debug: false)
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, debug: @debug )
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, debug: @debug).import_xml(node)
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,7 +33,9 @@
33
33
 
34
34
 
35
35
  class Action < MacroObject
36
+ using ColouredText
36
37
  using Params
38
+ include ObjectX
37
39
 
38
40
  attr_reader :constraints
39
41
 
@@ -141,25 +143,39 @@ end
141
143
 
142
144
  # Category: Applications
143
145
  #
146
+
147
+
144
148
  class OpenWebPageAction < ApplicationAction
149
+ using ColouredText
145
150
 
146
151
  def initialize(obj={}, macro=nil)
147
-
148
- # puts 'obj: ' + obj[0].xml.inspect
152
+
153
+ $debug = true
154
+ puts ('obj: ' + obj.inspect).debug if $debug
149
155
 
150
156
  h = if obj.is_a? Hash then
151
157
 
152
- obj
158
+ obj.merge({macro: macro})
153
159
 
154
160
  elsif obj.is_a? Array
155
161
 
156
- puts 'obj: ' + obj.inspect if $debug
162
+ puts ('obj: ' + obj.inspect).debug if $debug
157
163
  e, macro = obj
158
164
 
159
165
  a = e.xpath('item/*')
160
166
 
161
167
  h2 = if a.any? then
162
- a.map {|node| [node.name.to_sym, node.text.to_s]}.to_h
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
+
163
179
  else
164
180
  txt = e.text('item/description')
165
181
  {url: (txt || e.text)}
@@ -169,7 +185,7 @@ class OpenWebPageAction < ApplicationAction
169
185
 
170
186
  end
171
187
 
172
- puts 'h:' + h.inspect if $debug
188
+ puts ('h:' + h.inspect).debug if $debug
173
189
 
174
190
  #h[:url_to_open] = h[:url] if h[:url] and h[:url].length > 1
175
191
 
@@ -268,11 +284,64 @@ end
268
284
  #
269
285
  class TakePictureAction < CameraAction
270
286
 
271
- def initialize(h={})
287
+ def initialize(obj=nil)
272
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
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
+
273
342
  options = {
274
- new_path: '/storage/sdcard1/DCIM/Camera',
275
- path: '/storage/sdcard1/DCIM/Camera',
343
+ new_path: macro.picture_path,
344
+ path: macro.picture_path,
276
345
  show_icon: true,
277
346
  use_front_camera: true,
278
347
  flash_option: 0
@@ -288,7 +357,22 @@ class TakePictureAction < CameraAction
288
357
  end
289
358
 
290
359
  def to_s(colour: false, indent: 0)
291
- 'Take Picture'
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
+
292
376
  end
293
377
 
294
378
  end
@@ -393,6 +477,7 @@ class IfConditionAction < Action
393
477
  a: true,
394
478
  constraint_list: []
395
479
  }
480
+ puts 'obj: ' + obj.inspect if $debug
396
481
 
397
482
  if obj.is_a? Hash then
398
483
 
@@ -402,18 +487,23 @@ class IfConditionAction < Action
402
487
  super(h2)
403
488
 
404
489
  elsif obj.is_a? Array
490
+
405
491
  e, macro = obj
406
- super()
407
- raw_txt = e.text('item/description') || e.text.to_s
492
+ super()
493
+ puts 'e.xml: ' + e.xml if $debug
494
+ puts 'e.text: ' + e.text.to_s.strip if $debug
495
+ raw_txt = e.text.to_s.strip[/^if [^$]+/i] || e.text('item/description')
408
496
  puts 'raw_txt: ' + raw_txt.inspect if $debug
409
497
 
410
- clause = raw_txt[/^if (.*)/i,1]
498
+ clause = raw_txt[/^If (.*)/i,1]
499
+ puts 'clause: ' + clause.inspect if $debug
411
500
  conditions = clause.split(/\s+\b(?:AND|OR)\b\s+/i)
501
+ puts 'conditions: ' + conditions.inspect if $debug
412
502
 
413
503
  cp = ConstraintsNlp.new
414
504
 
415
505
  @constraints = conditions.map do |c|
416
- puts 'c: ' + c.inspect
506
+ puts 'c: ' + c.inspect if $debug
417
507
  r = cp.find_constraint c
418
508
  puts 'found constraint ' + r.inspect if $debug
419
509
 
@@ -421,7 +511,24 @@ class IfConditionAction < Action
421
511
 
422
512
  end
423
513
  puts '@constraints: ' + @constraints.inspect if $debug
424
- {}
514
+
515
+ # find any nested actions
516
+ item = e.element('item')
517
+
518
+ if item then
519
+
520
+ ap = ActionsNlp.new
521
+ obj2 = action_to_object(ap, item, item, macro)
522
+ puts 'obj2: ' + obj2.inspect if $debug
523
+ #macro.add obj2
524
+
525
+ end
526
+
527
+ h = {
528
+ constraint_list: @constraints.map(&:to_h)
529
+ }
530
+ super(h) {}
531
+
425
532
  else
426
533
  # get the constraints
427
534
 
@@ -450,21 +557,47 @@ class IfConditionAction < Action
450
557
  out << s + constraints
451
558
  out.join("\n")
452
559
 
453
- end
560
+ end
561
+
454
562
  end
455
563
 
456
564
  class ElseAction < Action
457
565
 
458
- def initialize(h={})
566
+ def initialize(obj=[])
459
567
 
460
568
  options = {
461
- constraint_list: ''
569
+ constraint_list: []
462
570
  }
571
+
572
+ if obj.is_a? Hash then
573
+
574
+ h = obj
463
575
 
464
- super(options.merge h)
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
+
465
597
 
466
598
 
467
- end
599
+
600
+ end
468
601
 
469
602
  def to_s(colour: false, indent: 0)
470
603
  'Else'
@@ -644,6 +777,9 @@ class SetHotspotAction < ConnectivityAction
644
777
 
645
778
  def initialize(h={})
646
779
 
780
+ # to-do: check when *disable hotspot*, is the
781
+ # *enable wifi* option selected?
782
+
647
783
  options = {
648
784
  device_name: "", state: 0, turn_wifi_on: true, use_legacy_mechanism: false, mechanism: 0
649
785
 
@@ -654,8 +790,15 @@ class SetHotspotAction < ConnectivityAction
654
790
  end
655
791
 
656
792
  def to_s(colour: false, indent: 0)
657
- action = @h[:turn_wifi_on] ? 'Enable' : 'Disable'
658
- action + ' HotSpot'
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
+
659
802
  end
660
803
  end
661
804
 
@@ -1606,6 +1749,7 @@ end
1606
1749
  # MacroDroid Specific
1607
1750
  #
1608
1751
  class SetVariableAction < Action
1752
+ using ColouredText
1609
1753
 
1610
1754
  def initialize(obj=nil)
1611
1755
 
@@ -1614,7 +1758,14 @@ class SetVariableAction < Action
1614
1758
  elsif obj.is_a? Array
1615
1759
  e, macro = obj
1616
1760
  node = e.element('item/*')
1617
- macro.set_var node.name, node.value.to_s
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
1618
1769
  end
1619
1770
 
1620
1771
  options = {
@@ -2334,8 +2485,31 @@ end
2334
2485
  # Category: Screen
2335
2486
  #
2336
2487
  class ScreenOnAction < ScreenAction
2488
+ using ColouredText
2337
2489
 
2338
- def initialize(h={})
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
2339
2513
 
2340
2514
  options = {
2341
2515
  pie_lock_screen: false,
@@ -2412,7 +2586,7 @@ class KeepAwakeAction < ScreenAction
2412
2586
  h2 = if txt then
2413
2587
 
2414
2588
  raw_duration = (txt || e.text).to_s
2415
- puts 'raw_duration: ' + raw_duration.inspect
2589
+ puts 'raw_duration: ' + raw_duration.inspect if $debug
2416
2590
  duration = raw_duration[/Screen On - ([^$]+)/i]
2417
2591
  {duration: duration}
2418
2592
 
@@ -2424,7 +2598,7 @@ class KeepAwakeAction < ScreenAction
2424
2598
 
2425
2599
  end
2426
2600
 
2427
- puts ('h: ' + h.inspect).debug #if $debug
2601
+ puts ('h: ' + h.inspect).debug if $debug
2428
2602
 
2429
2603
  if h[:duration] then
2430
2604
 
@@ -7,7 +7,104 @@
7
7
  # MacroObject
8
8
  #
9
9
 
10
+ module ObjectX
11
+
12
+
13
+ def action_to_object(ap, e, item, macro)
14
+
15
+ debug = false
16
+
17
+ puts 'inside action_to_object: item.xml: ' + item.xml if debug
18
+
19
+ if item.element('description') then
20
+
21
+ item.xpath('description').map do |description|
22
+
23
+ inner_lines = description.text.to_s.strip.lines
24
+ puts 'inner_lines: ' + inner_lines.inspect if debug
25
+
26
+ action = if e.text.to_s.strip.empty? then
27
+ inner_lines.shift.strip
28
+ else
29
+ e.text.strip
30
+ end
31
+
32
+ puts 'action: ' + action.inspect if debug
33
+
34
+ r = ap.find_action action
35
+ puts 'r: ' + r.inspect if debug
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
53
+ end
54
+
55
+ else
56
+
57
+ action = e.text.strip
58
+ puts 'action: ' + action.inspect if $debug
59
+ r = ap.find_action action
60
+
61
+ a = e.xpath('item/*')
62
+
63
+ h = if a.any? then
64
+ a.map {|node| [node.name.to_sym, node.text.to_s]}.to_h
65
+ else
66
+ {}
67
+ end
68
+ puts 'h: ' + h.inspect if $debug
69
+
70
+ #r = ap.find_action action
71
+ #r[0].new(h.merge(macro: self)) if r
72
+ o = object_create(r[0], h.merge(macro: macro)) if r
73
+ macro.add o
74
+ o
75
+
76
+ end
77
+
78
+
79
+ end
10
80
 
81
+ def object_create(klass, *args)
82
+
83
+ begin
84
+ klass.new(*args)
85
+ rescue
86
+ raise MacroError, klass.to_s + ': ' + ($!).to_s
87
+ end
88
+ end
89
+
90
+ def varify(label, value='')
91
+
92
+ type = VAR_TYPES[value.class.to_s.to_sym]
93
+
94
+ h = {
95
+ boolean_value: false,
96
+ decimal_value: 0.0,
97
+ int_value: 0,
98
+ name: label,
99
+ string_value: '',
100
+ type: type[0]
101
+ }
102
+ h[type[1]] = value
103
+ h
104
+
105
+ end
106
+
107
+ end
11
108
 
12
109
  class MacroObject
13
110
  using ColouredText
@@ -97,11 +194,11 @@ class MacroObject
97
194
  private
98
195
 
99
196
  def hashify(h)
100
-
197
+ puts 'h: ' + h.inspect
101
198
  h2 = h.inject({}) do |r,x|
102
- puts 'x: ' + x.inspect if $debug
199
+ puts 'x: ' + x.inspect #if $debug
103
200
  key, value = x
104
- puts 'key: ' + key.inspect if $debug
201
+ puts 'key: ' + key.inspect #if $debug
105
202
  new_key = key.to_s.gsub(/\w_\w/){|x| x[0] + x[-1].upcase}
106
203
  new_key = new_key.prepend 'm_' unless @list.include? new_key
107
204
  new_key = 'm_SIGUID' if new_key == 'm_siguid'
@@ -794,6 +794,24 @@ class MacroDroidVariableConstraint < Constraint
794
794
 
795
795
  def initialize(h={})
796
796
 
797
+ if h[:loperand] then
798
+ h[:variable] = {}
799
+ h[:variable][:name] = h[:loperand]
800
+ h[:variable][:type] = 2
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
+
813
+ end
814
+
797
815
  options = {
798
816
 
799
817
  :enable_regex=>false,
@@ -825,11 +843,24 @@ class MacroDroidVariableConstraint < Constraint
825
843
 
826
844
  def to_s(colour: false, indent: 0)
827
845
 
828
- a = [:int_greater_than, :int_less_than, :int_not_equal,
829
- :string_equal].zip(['>','<','!=', '='])
830
- operator = a.find {|label,_| @h[label]}.last
846
+ a = [:int_greater_than, :int_less_than, :int_not_equal,
847
+ :string_equal].zip(['>','<','!=', '='])
848
+ operator = a.find {|label,_| @h[label]}.last
849
+
850
+ var = @h[:variable]
851
+
852
+ type = case var[:type]
853
+ when 0 # boolean
854
+ :boolean_value
855
+ when 1 # integer
856
+ :int_value
857
+ when 2 # string
858
+ :string_value
859
+ when 3 # decimal
860
+ :decimal_Value
861
+ end
831
862
 
832
- @s = "%s %s %s" % [@h[:variable][:name], operator, @h[:int_value]]
863
+ @s = "%s %s %s" % [@h[:variable][:name], operator, @h[type]]
833
864
  super()
834
865
  end
835
866
 
@@ -888,7 +919,7 @@ class TriggerThatInvokedConstraint < Constraint
888
919
 
889
920
  def initialize(h={})
890
921
 
891
- puts ('h: ' + h.inspect).green
922
+ puts ('h: ' + h.inspect).green if $debug
892
923
  @trigger = h[:macro].triggers.find {|x| x.siguid == h[:si_guid_that_invoked] }
893
924
 
894
925
  options = {
@@ -21,8 +21,11 @@ VAR_TYPES = {
21
21
  Float: [3, :decimal_value]
22
22
  }
23
23
 
24
+
25
+
24
26
  class TriggersNlp
25
27
  include AppRoutes
28
+ using ColouredText
26
29
 
27
30
  def initialize(macro=nil)
28
31
 
@@ -32,7 +35,46 @@ class TriggersNlp
32
35
 
33
36
  end
34
37
 
35
- 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
36
78
 
37
79
  # e.g. at 7:30pm daily
38
80
  get /^(?:at )?(\d+:\d+(?:[ap]m)?) daily/i do |time, days|
@@ -133,13 +175,25 @@ class ActionsNlp
133
175
  def initialize(macro=nil)
134
176
 
135
177
  super()
178
+
136
179
  params = {macro: macro}
137
180
  actions(params)
138
181
 
139
182
  end
140
183
 
141
184
  def actions(params)
142
-
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
+
143
197
  # e.g. message popup: hello world!
144
198
  get /^message popup: (.*)/i do |msg|
145
199
  [ToastAction, {msg: msg}]
@@ -196,6 +250,10 @@ class ActionsNlp
196
250
  [VibrateAction, {pattern: pattern}]
197
251
  end
198
252
 
253
+ get /^Vibrate$/i do |pattern|
254
+ [VibrateAction, {pattern: 'short buzz'}]
255
+ end
256
+
199
257
  # e.g. Display Notification: Hi there: This is the body of the message
200
258
  get /^Display Notification: ([^:]+): [^$]+$/i do |subject, text|
201
259
  [NotificationAction, {subject: subject, text: text}]
@@ -250,13 +308,13 @@ class ActionsNlp
250
308
 
251
309
  #
252
310
  get /^WebHook \(Url\)/i do
253
- [OpenWebPageAction, params]
311
+ [OpenWebPageAction, {}]
254
312
  end
255
313
 
256
314
  # e.g. webhook entered_kitchen
257
315
  #
258
316
  get /^webhook$/i do
259
- [OpenWebPageAction, params]
317
+ [OpenWebPageAction, {}, params[:macro]]
260
318
  end
261
319
 
262
320
  # -- Location ---------------------------------------------------------
@@ -266,7 +324,7 @@ class ActionsNlp
266
324
  end
267
325
 
268
326
  get /^Share Location$/i do
269
- [ShareLocationAction, params]
327
+ [ShareLocationAction, {}]
270
328
  end
271
329
 
272
330
  #a: Keep Device Awake Screen On Until Disabled
@@ -290,7 +348,7 @@ class ActionsNlp
290
348
  end
291
349
 
292
350
  get /Keep Device Awake$/i do
293
- [KeepAwakeAction, params]
351
+ [KeepAwakeAction, {}]
294
352
  end
295
353
 
296
354
  #a: Disable Keep Awake
@@ -305,6 +363,10 @@ class ActionsNlp
305
363
  [IfConditionAction, {}]
306
364
  end
307
365
 
366
+ get /else/i do
367
+ [ElseAction, {}]
368
+ end
369
+
308
370
  get /End If/i do
309
371
  [EndIfAction, {}]
310
372
  end
@@ -314,6 +376,12 @@ class ActionsNlp
314
376
  get /^Set Variable$/i do
315
377
  [SetVariableAction, {}]
316
378
  end
379
+
380
+ # -- Screen ------------------------------------------------
381
+ #
382
+ get /^Screen (On|Off)$/i do |state|
383
+ [ScreenOnAction, {screen_off: state.downcase == 'off'}]
384
+ end
317
385
 
318
386
  end
319
387
 
@@ -347,6 +415,20 @@ class ConstraintsNlp
347
415
 
348
416
  #
349
417
 
418
+ # -- MacroDroid specific -----------------------------------------------------------------------
419
+
420
+ get /^(\w+) (=) (\[?\w+\]?)/i do |loperand, operator, roperand|
421
+
422
+ h = {
423
+ loperand: loperand,
424
+ operator: operator,
425
+ roperand: roperand
426
+ }
427
+
428
+ [MacroDroidVariableConstraint, h]
429
+
430
+ end
431
+
350
432
  # -- Sensors -----------------------------------
351
433
  #
352
434
  get /^Light Sensor (Less|Greater) than (50.0)lx/i do |operator, val|
@@ -386,16 +468,17 @@ end
386
468
  class Macro
387
469
  using ColouredText
388
470
  using Params
471
+ include ObjectX
389
472
 
390
473
  attr_reader :local_variables, :triggers, :actions, :constraints,
391
474
  :guid, :deviceid
392
- attr_accessor :title, :description, :remote_url
475
+ attr_accessor :title, :description, :remote_url, :picture_path
393
476
 
394
- def initialize(name=nil, geofences: nil, deviceid: nil, remote_url: nil,
395
- debug: false)
477
+ def initialize(name=nil, geofences: nil, deviceid: nil, remote_url: nil, \
478
+ picture_path: nil, debug: false)
396
479
 
397
480
  @title, @geofences, @deviceid, @debug = name, geofences, deviceid, debug
398
- @remote_url = remote_url
481
+ @remote_url, @picture_path = remote_url, picture_path
399
482
 
400
483
  puts 'inside Macro#initialize' if @debug
401
484
 
@@ -405,6 +488,8 @@ class Macro
405
488
  end
406
489
 
407
490
  def add(obj)
491
+ puts 'inside add; ' + obj.inspect if @debug
492
+ puts '@actions: ' + @actions.inspect if @debug
408
493
 
409
494
  if obj.kind_of? Trigger then
410
495
 
@@ -663,68 +748,25 @@ class Macro
663
748
 
664
749
  ap = ActionsNlp.new self
665
750
 
666
- @actions = node.xpath('action').flat_map do |e|
751
+ node.xpath('action').each do |e|
667
752
 
668
753
  puts 'action e: ' + e.xml.inspect if @debug
669
754
  puts 'e.text ' + e.text if @debug
670
755
 
671
756
  item = e.element('item')
757
+
672
758
  if item then
673
759
 
674
- if item.element('description') then
675
-
676
- item.xpath('description').map do |description|
677
-
678
- inner_lines = description.text.to_s.strip.lines
679
- puts 'inner_lines: ' + inner_lines.inspect if @debug
680
-
681
- action = if e.text.to_s.strip.empty? then
682
- inner_lines.shift.strip
683
- else
684
- e.text.strip
685
- end
686
-
687
- puts 'action: ' + action.inspect if @debug
688
-
689
- r = ap.find_action action
690
- puts 'r: ' + r.inspect if @debug
691
- puts 'description: ' + description.xml.inspect if @debug
692
- #o = r[0].new([description, self]) if r
693
- o = object_create(r[0],[description, self]) if r
694
- puts 'after o' if @debug
695
- o
696
-
697
- end
698
-
699
- else
700
-
701
- action = e.text.strip
702
- puts 'action: ' + action.inspect if @debug
703
- r = ap.find_action action
704
-
705
- a = e.xpath('item/*')
706
-
707
- h = if a.any? then
708
- a.map {|node| [node.name.to_sym, node.text.to_s]}.to_h
709
- else
710
- {}
711
- end
712
- puts 'h: ' + h.inspect if @debug
713
-
714
- #r = ap.find_action action
715
- #r[0].new(h.merge(macro: self)) if r
716
- object_create(r[0], h.merge(macro: self)) if r
717
-
718
- end
760
+ action_to_object(ap, e, item, self)
719
761
 
720
762
  else
721
763
 
722
764
  action = e.text.strip
723
765
  r = ap.find_action action
724
766
  #r[0].new(r[1]) if r
725
- object_create(r[0],r[1]) if r
767
+ self.add object_create(r[0],*r[1..-1]) if r
726
768
 
727
- end
769
+ end
728
770
 
729
771
  end
730
772
 
@@ -798,7 +840,10 @@ class Macro
798
840
  if not @local_variables.has_key? label.to_sym then
799
841
  @local_variables.merge!({label.to_sym => value})
800
842
  end
801
-
843
+
844
+ if @debug then
845
+ puts ("before varify; label: %s value: %s" % [label, value]).debug
846
+ end
802
847
  varify(label, value)
803
848
  end
804
849
 
@@ -1012,31 +1057,7 @@ EOF
1012
1057
 
1013
1058
  end
1014
1059
 
1015
- def object_create(klass, *args)
1016
1060
 
1017
- begin
1018
- klass.new(*args)
1019
- rescue
1020
- raise MacroError, klass.to_s + ': ' + ($!).to_s
1021
- end
1022
- end
1023
-
1024
- def varify(label, value='')
1025
-
1026
1061
 
1027
- type = VAR_TYPES[value.class.to_s.to_sym]
1028
-
1029
- h = {
1030
- boolean_value: false,
1031
- decimal_value: 0.0,
1032
- int_value: 0,
1033
- name: label,
1034
- string_value: '',
1035
- type: type[0]
1036
- }
1037
- h[type[1]] = value
1038
- h
1039
-
1040
- end
1041
1062
 
1042
1063
  end
@@ -244,7 +244,7 @@ class ExternalPowerTrigger < Trigger
244
244
 
245
245
  return 'Power Disconnected' unless @h[:power_connected]
246
246
 
247
- status = 'Power Connectd'
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.3
4
+ version: 0.9.8
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-08 00:00:00.000000000 Z
38
+ date: 2020-10-16 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: glw
metadata.gz.sig CHANGED
Binary file