ruby-macrodroid 0.9.5 → 0.9.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/ruby-macrodroid.rb +53 -35
- data/lib/ruby-macrodroid/actions.rb +227 -66
- data/lib/ruby-macrodroid/base.rb +23 -12
- data/lib/ruby-macrodroid/constraints.rb +12 -1
- data/lib/ruby-macrodroid/macro.rb +112 -29
- 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: cfb8dbf1cb2f5796722de69e98afcb6d7058ba6faf743740a989589fd3d72fc5
|
4
|
+
data.tar.gz: 4b6ff72308bae85939e3eadf7776a3b56d2b8084103633dbb7754f496fb7c037
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 722fc170955c3ee925821859e87c3380b5769db34081c8318ee043218e2bb36ae43e104d6c701238ef887405c30c8d05ab3cba32a040e6430392bc60dd6dbce1
|
7
|
+
data.tar.gz: 2343b75872d051e055d3dd6955dcf03c7c236ef5f77e1b43b5618515b8f0170728878336fe8a2aed5eac51ddce9361c751f3d9170418ee289d2e5522b18ff472
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/ruby-macrodroid.rb
CHANGED
@@ -110,16 +110,19 @@ 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 = {}
|
125
|
+
@macros = []
|
123
126
|
|
124
127
|
if obj then
|
125
128
|
|
@@ -143,34 +146,7 @@ class MacroDroid
|
|
143
146
|
|
144
147
|
if s =~ /m(?:acro)?:\s/ then
|
145
148
|
|
146
|
-
|
147
|
-
|
148
|
-
s2 = s.gsub(/^g:/,'geofence:').gsub(/^m:/,'macro:')\
|
149
|
-
.gsub(/^d:/,'description:').gsub(/^v:/,'variable:')\
|
150
|
-
.gsub(/^t:/,'trigger:').gsub(/^a:/,'action:')\
|
151
|
-
.gsub(/^c:/,'constraint:').gsub(/^#.*/,'')
|
152
|
-
|
153
|
-
a = s2.split(/(?=^macro:)/)
|
154
|
-
|
155
|
-
raw_geofences = a.shift if a.first =~ /^geofence/
|
156
|
-
raw_macros = a.join
|
157
|
-
#raw_macros, raw_geofences .reverse
|
158
|
-
|
159
|
-
puts 'raw_macros: ' + raw_macros.inspect if @debug
|
160
|
-
|
161
|
-
if raw_geofences then
|
162
|
-
|
163
|
-
geoxml = RowX.new(raw_geofences).to_xml
|
164
|
-
|
165
|
-
geodoc = Rexle.new(geoxml)
|
166
|
-
geofences = geodoc.root.xpath('item/geofence')
|
167
|
-
@geofences = fetch_geofences(geofences) if geofences.any?
|
168
|
-
|
169
|
-
end
|
170
|
-
|
171
|
-
xml = RowX.new(raw_macros, allow_lonely_keyfield: true).to_xml
|
172
|
-
puts 'xml: ' + xml if @debug
|
173
|
-
import_rowxml(xml)
|
149
|
+
import_txt(s)
|
174
150
|
|
175
151
|
elsif s =~ /^# /
|
176
152
|
xml = pc_to_xml(s)
|
@@ -227,6 +203,10 @@ class MacroDroid
|
|
227
203
|
def export(filepath)
|
228
204
|
FileX.write filepath, to_json
|
229
205
|
end
|
206
|
+
|
207
|
+
def import(s)
|
208
|
+
import_txt(s)
|
209
|
+
end
|
230
210
|
|
231
211
|
def to_json()
|
232
212
|
|
@@ -334,7 +314,8 @@ class MacroDroid
|
|
334
314
|
# puts '@geofences: ' + @geofences.inspect if @debug
|
335
315
|
|
336
316
|
m = Macro.new(geofences: @geofences.map(&:last), deviceid: @deviceid,
|
337
|
-
remote_url: @remote_url,
|
317
|
+
remote_url: @remote_url, picture_path: @picture_path,
|
318
|
+
parent: self, debug: @debug )
|
338
319
|
m.import_h(macro)
|
339
320
|
m
|
340
321
|
|
@@ -353,14 +334,50 @@ class MacroDroid
|
|
353
334
|
puts 'import_rowxml: @geofences: ' + @geofences.inspect if @debug
|
354
335
|
geofences = @geofences
|
355
336
|
|
356
|
-
|
337
|
+
a = doc.root.xpath('item').map do |node|
|
357
338
|
puts ('geofences: ' + geofences.inspect).highlight if @debug
|
358
339
|
Macro.new(geofences: geofences.map(&:last), deviceid: @deviceid,
|
359
|
-
remote_url: @remote_url,
|
340
|
+
remote_url: @remote_url, picture_path: @picture_path,
|
341
|
+
parent: self, debug: @debug).import_xml(node)
|
360
342
|
|
361
343
|
end
|
344
|
+
|
345
|
+
@macros.concat a
|
362
346
|
|
363
|
-
end
|
347
|
+
end
|
348
|
+
|
349
|
+
def import_txt(s)
|
350
|
+
|
351
|
+
puts 'before RowX.new' if @debug
|
352
|
+
|
353
|
+
s2 = s.gsub(/^g:/,'geofence:').gsub(/^m:/,'macro:')\
|
354
|
+
.gsub(/^d:/,'description:').gsub(/^v:/,'variable:')\
|
355
|
+
.gsub(/^t:/,'trigger:').gsub(/^a:/,'action:')\
|
356
|
+
.gsub(/^c:/,'constraint:').gsub(/^#.*/,'')
|
357
|
+
|
358
|
+
a = s2.split(/(?=^macro:)/)
|
359
|
+
|
360
|
+
raw_geofences = a.shift if a.first =~ /^geofence/
|
361
|
+
raw_macros = a.join
|
362
|
+
#raw_macros, raw_geofences .reverse
|
363
|
+
|
364
|
+
puts 'raw_macros: ' + raw_macros.inspect if @debug
|
365
|
+
|
366
|
+
if raw_geofences then
|
367
|
+
|
368
|
+
geoxml = RowX.new(raw_geofences).to_xml
|
369
|
+
|
370
|
+
geodoc = Rexle.new(geoxml)
|
371
|
+
geofences = geodoc.root.xpath('item/geofence')
|
372
|
+
@geofences = fetch_geofences(geofences) if geofences.any?
|
373
|
+
|
374
|
+
end
|
375
|
+
|
376
|
+
xml = RowX.new(raw_macros, allow_lonely_keyfield: true).to_xml
|
377
|
+
puts 'xml: ' + xml if @debug
|
378
|
+
import_rowxml(xml)
|
379
|
+
|
380
|
+
end
|
364
381
|
|
365
382
|
def import_xml(raws)
|
366
383
|
|
@@ -380,7 +397,8 @@ class MacroDroid
|
|
380
397
|
@macros = doc.root.xpath('macro').map do |node|
|
381
398
|
puts 'node: ' + node.inspect if @debug
|
382
399
|
Macro.new(geofences: @geofences.map(&:last), deviceid: @deviceid,
|
383
|
-
debug: @debug)
|
400
|
+
picture_path: @picture_path, parent: self, debug: @debug)\
|
401
|
+
.import_xml(node)
|
384
402
|
|
385
403
|
end
|
386
404
|
end
|
@@ -143,19 +143,23 @@ end
|
|
143
143
|
|
144
144
|
# Category: Applications
|
145
145
|
#
|
146
|
+
|
147
|
+
|
146
148
|
class OpenWebPageAction < ApplicationAction
|
149
|
+
using ColouredText
|
147
150
|
|
148
151
|
def initialize(obj={}, macro=nil)
|
149
|
-
|
150
|
-
|
152
|
+
|
153
|
+
$debug = false
|
154
|
+
puts ('obj: ' + obj.inspect).debug if $debug
|
151
155
|
|
152
156
|
h = if obj.is_a? Hash then
|
153
157
|
|
154
|
-
obj
|
158
|
+
obj.merge({macro: macro})
|
155
159
|
|
156
160
|
elsif obj.is_a? Array
|
157
161
|
|
158
|
-
puts 'obj: ' + obj.inspect if $debug
|
162
|
+
puts ('obj: ' + obj.inspect).debug if $debug
|
159
163
|
e, macro = obj
|
160
164
|
|
161
165
|
a = e.xpath('item/*')
|
@@ -181,14 +185,14 @@ class OpenWebPageAction < ApplicationAction
|
|
181
185
|
|
182
186
|
end
|
183
187
|
|
184
|
-
puts 'h:' + h.inspect if $debug
|
188
|
+
puts ('h:' + h.inspect).debug if $debug
|
185
189
|
|
186
190
|
#h[:url_to_open] = h[:url] if h[:url] and h[:url].length > 1
|
187
191
|
|
188
192
|
options = {
|
189
|
-
variable_to_save_response: {:string_value=>"", :name=>"coords",
|
190
|
-
decimal_value: 0.0, isLocal: true, m_boolean_value: false,
|
191
|
-
excludeFromLog: false, int_value: 0, type: 2},
|
193
|
+
#variable_to_save_response: {:string_value=>"", :name=>"coords",
|
194
|
+
#decimal_value: 0.0, isLocal: true, m_boolean_value: false,
|
195
|
+
#excludeFromLog: false, int_value: 0, type: 2},
|
192
196
|
url_to_open: '',
|
193
197
|
http_get: true,
|
194
198
|
disable_url_encode: false,
|
@@ -280,11 +284,64 @@ end
|
|
280
284
|
#
|
281
285
|
class TakePictureAction < CameraAction
|
282
286
|
|
283
|
-
def initialize(
|
287
|
+
def initialize(obj=nil)
|
288
|
+
|
289
|
+
|
290
|
+
h = if obj.is_a? Hash then
|
284
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
|
+
|
285
342
|
options = {
|
286
|
-
new_path:
|
287
|
-
path:
|
343
|
+
new_path: macro.picture_path,
|
344
|
+
path: macro.picture_path,
|
288
345
|
show_icon: true,
|
289
346
|
use_front_camera: true,
|
290
347
|
flash_option: 0
|
@@ -300,7 +357,22 @@ class TakePictureAction < CameraAction
|
|
300
357
|
end
|
301
358
|
|
302
359
|
def to_s(colour: false, indent: 0)
|
303
|
-
|
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
|
+
|
304
376
|
end
|
305
377
|
|
306
378
|
end
|
@@ -397,10 +469,14 @@ end
|
|
397
469
|
|
398
470
|
# Conditions/Loops
|
399
471
|
#
|
400
|
-
class IfConditionAction < Action
|
401
472
|
|
473
|
+
class IfAction < Action
|
474
|
+
using ColouredText
|
475
|
+
|
402
476
|
def initialize(obj=nil)
|
403
|
-
|
477
|
+
|
478
|
+
$debug = false
|
479
|
+
|
404
480
|
options = {
|
405
481
|
a: true,
|
406
482
|
constraint_list: []
|
@@ -420,10 +496,10 @@ class IfConditionAction < Action
|
|
420
496
|
super()
|
421
497
|
puts 'e.xml: ' + e.xml if $debug
|
422
498
|
puts 'e.text: ' + e.text.to_s.strip if $debug
|
423
|
-
raw_txt = e.text.to_s.strip[
|
499
|
+
raw_txt = e.text.to_s.strip[/^#{@label}[^$]+/i] || e.text('item/description')
|
424
500
|
puts 'raw_txt: ' + raw_txt.inspect if $debug
|
425
501
|
|
426
|
-
clause = raw_txt[
|
502
|
+
clause = raw_txt[/^#{@label}(.*)/i,1]
|
427
503
|
puts 'clause: ' + clause.inspect if $debug
|
428
504
|
conditions = clause.split(/\s+\b(?:AND|OR)\b\s+/i)
|
429
505
|
puts 'conditions: ' + conditions.inspect if $debug
|
@@ -442,6 +518,7 @@ class IfConditionAction < Action
|
|
442
518
|
|
443
519
|
# find any nested actions
|
444
520
|
item = e.element('item')
|
521
|
+
#puts ('item: ' + item.xml.inspect).debug if $debug
|
445
522
|
|
446
523
|
if item then
|
447
524
|
|
@@ -451,26 +528,24 @@ class IfConditionAction < Action
|
|
451
528
|
#macro.add obj2
|
452
529
|
|
453
530
|
end
|
454
|
-
|
455
|
-
{
|
531
|
+
|
532
|
+
h = {
|
533
|
+
constraint_list: @constraints.map(&:to_h)
|
534
|
+
}
|
535
|
+
super(h) {}
|
536
|
+
|
456
537
|
else
|
457
538
|
# get the constraints
|
458
539
|
|
459
540
|
end
|
460
541
|
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
@label = 'If '
|
466
|
-
|
467
542
|
end
|
468
|
-
|
543
|
+
|
469
544
|
def to_s(colour: false, indent: 0)
|
470
545
|
|
471
546
|
h = @h.clone
|
472
547
|
#h.delete :macro
|
473
|
-
@s =
|
548
|
+
@s = @label
|
474
549
|
operator = @h[:is_or_condition] ? 'OR' : 'AND'
|
475
550
|
constraints = @constraints.map \
|
476
551
|
{|x| ' ' * indent + x.to_summary(colour: colour)}.join(" %s " % operator)
|
@@ -481,22 +556,58 @@ class IfConditionAction < Action
|
|
481
556
|
out << s + constraints
|
482
557
|
out.join("\n")
|
483
558
|
|
484
|
-
end
|
559
|
+
end
|
560
|
+
|
561
|
+
end
|
562
|
+
|
563
|
+
class IfConditionAction < IfAction
|
564
|
+
|
565
|
+
def initialize(obj=nil)
|
566
|
+
|
567
|
+
@label = 'If '
|
568
|
+
super(obj)
|
569
|
+
|
570
|
+
end
|
485
571
|
|
486
572
|
end
|
487
573
|
|
488
574
|
class ElseAction < Action
|
489
575
|
|
490
|
-
def initialize(
|
576
|
+
def initialize(obj=[])
|
491
577
|
|
492
578
|
options = {
|
493
|
-
constraint_list:
|
579
|
+
constraint_list: []
|
494
580
|
}
|
581
|
+
|
582
|
+
if obj.is_a? Hash then
|
583
|
+
|
584
|
+
h = obj
|
495
585
|
|
496
|
-
|
586
|
+
super(options.merge h)
|
587
|
+
|
588
|
+
elsif obj.is_a? Array
|
589
|
+
|
590
|
+
e, macro = obj
|
591
|
+
|
592
|
+
# find any nested actions
|
593
|
+
item = e.element('item')
|
594
|
+
|
595
|
+
if item then
|
596
|
+
|
597
|
+
ap = ActionsNlp.new
|
598
|
+
obj2 = action_to_object(ap, item, item, macro)
|
599
|
+
puts 'obj2: ' + obj2.inspect if $debug
|
600
|
+
#macro.add obj2
|
601
|
+
|
602
|
+
end
|
603
|
+
|
604
|
+
super(options)
|
605
|
+
end
|
606
|
+
|
497
607
|
|
498
608
|
|
499
|
-
|
609
|
+
|
610
|
+
end
|
500
611
|
|
501
612
|
def to_s(colour: false, indent: 0)
|
502
613
|
'Else'
|
@@ -504,41 +615,15 @@ class ElseAction < Action
|
|
504
615
|
|
505
616
|
end
|
506
617
|
|
507
|
-
class ElseIfConditionAction <
|
618
|
+
class ElseIfConditionAction < IfAction
|
508
619
|
|
509
|
-
def initialize(
|
510
|
-
|
511
|
-
options = {
|
512
|
-
constraint_list: ''
|
513
|
-
}
|
514
|
-
|
515
|
-
super(options.merge h)
|
516
|
-
@label = 'Else If '
|
620
|
+
def initialize(obj=nil)
|
517
621
|
|
518
|
-
|
519
|
-
|
520
|
-
def to_s(colour: false, indent: 0)
|
521
|
-
|
522
|
-
h = @h.clone
|
523
|
-
h.delete :macro
|
524
|
-
@s = 'Else If '
|
525
|
-
operator = @h[:is_or_condition] ? 'OR' : 'AND'
|
526
|
-
constraints = @constraints.map \
|
527
|
-
{|x| ' ' * indent + x.to_summary(colour: colour)}.join(" %s " % operator)
|
622
|
+
@label = 'Else If '
|
623
|
+
super(obj)
|
528
624
|
|
529
|
-
out = []
|
530
|
-
out << "; %s" % @h[:comment] if @h[:comment]
|
531
|
-
s = @s.lines.map {|x| (' ' * indent) + x}.join
|
532
|
-
out << s + constraints
|
533
|
-
out.join("\n")
|
534
|
-
|
535
|
-
end
|
536
|
-
|
537
|
-
def to_summary(colour: false)
|
538
|
-
'foo'
|
539
625
|
end
|
540
|
-
|
541
|
-
|
626
|
+
|
542
627
|
end
|
543
628
|
|
544
629
|
|
@@ -676,6 +761,9 @@ class SetHotspotAction < ConnectivityAction
|
|
676
761
|
|
677
762
|
def initialize(h={})
|
678
763
|
|
764
|
+
# to-do: check when *disable hotspot*, is the
|
765
|
+
# *enable wifi* option selected?
|
766
|
+
|
679
767
|
options = {
|
680
768
|
device_name: "", state: 0, turn_wifi_on: true, use_legacy_mechanism: false, mechanism: 0
|
681
769
|
|
@@ -686,8 +774,15 @@ class SetHotspotAction < ConnectivityAction
|
|
686
774
|
end
|
687
775
|
|
688
776
|
def to_s(colour: false, indent: 0)
|
689
|
-
|
690
|
-
|
777
|
+
|
778
|
+
@s = "%s HotSpot" % [@h[:state] == 0 ? 'Enable' : 'Disable']
|
779
|
+
|
780
|
+
if @h[:state] == 1 then
|
781
|
+
@s += "\n" + (@h[:turn_wifi_on] ? 'Enable WiFi' : 'Don\'t Enable Wifi')
|
782
|
+
end
|
783
|
+
|
784
|
+
super()
|
785
|
+
|
691
786
|
end
|
692
787
|
end
|
693
788
|
|
@@ -1611,6 +1706,49 @@ class ConfirmNextAction < Action
|
|
1611
1706
|
|
1612
1707
|
end
|
1613
1708
|
|
1709
|
+
class DisableMacroAction < Action
|
1710
|
+
|
1711
|
+
def initialize(obj=nil)
|
1712
|
+
|
1713
|
+
h = if obj.is_a? Hash then
|
1714
|
+
|
1715
|
+
obj
|
1716
|
+
|
1717
|
+
elsif obj.is_a? Array
|
1718
|
+
|
1719
|
+
e, macro = obj
|
1720
|
+
|
1721
|
+
# find the macro guid for the given name
|
1722
|
+
name = e.text('item/description').to_s
|
1723
|
+
found = macro.parent.macros.find {|macro| macro.title =~ /#{name}/ }
|
1724
|
+
|
1725
|
+
if found then
|
1726
|
+
{macro_name: found.title, GUID: found.guid}
|
1727
|
+
else
|
1728
|
+
{macro_name: name}
|
1729
|
+
end
|
1730
|
+
|
1731
|
+
end
|
1732
|
+
|
1733
|
+
# state: 0 = enable, 1 = disable, 2 = toggle
|
1734
|
+
|
1735
|
+
options = {macro_name: "Change brightness", state: 1, GUID: nil}
|
1736
|
+
super(options.merge h)
|
1737
|
+
|
1738
|
+
end
|
1739
|
+
|
1740
|
+
def to_s(colour: false, indent: 0)
|
1741
|
+
|
1742
|
+
state = %w(Enable Disable Toggle)[@h[:state]]
|
1743
|
+
@s = state + ' macro'# + @h.inspect
|
1744
|
+
@s += "\n" + @h[:macro_name]
|
1745
|
+
super()
|
1746
|
+
|
1747
|
+
end
|
1748
|
+
|
1749
|
+
alias to_summary to_s
|
1750
|
+
end
|
1751
|
+
|
1614
1752
|
# MacroDroid Specific
|
1615
1753
|
#
|
1616
1754
|
class ExportMacrosAction < Action
|
@@ -1777,7 +1915,7 @@ class PauseAction < Action
|
|
1777
1915
|
options = {
|
1778
1916
|
delay_in_milli_seconds: 0, delay_in_seconds: 1, use_alarm: false
|
1779
1917
|
}
|
1780
|
-
super(h)
|
1918
|
+
super(options.merge h)
|
1781
1919
|
|
1782
1920
|
end
|
1783
1921
|
|
@@ -2374,8 +2512,31 @@ end
|
|
2374
2512
|
# Category: Screen
|
2375
2513
|
#
|
2376
2514
|
class ScreenOnAction < ScreenAction
|
2515
|
+
using ColouredText
|
2377
2516
|
|
2378
|
-
def initialize(
|
2517
|
+
def initialize(obj=nil)
|
2518
|
+
|
2519
|
+
debug = false
|
2520
|
+
|
2521
|
+
h = if obj.is_a? Hash then
|
2522
|
+
|
2523
|
+
obj
|
2524
|
+
|
2525
|
+
elsif obj.is_a? Array
|
2526
|
+
=begin
|
2527
|
+
puts 'obj: ' + obj.inspect if debug
|
2528
|
+
e, macro = obj
|
2529
|
+
puts ('e: ' + e.xml.inspect).debug if debug
|
2530
|
+
a = e.xpath('item/*')
|
2531
|
+
|
2532
|
+
txt = e.text.to_s
|
2533
|
+
puts ('txt: ' + txt.inspect).debug if debug
|
2534
|
+
state = txt[/Screen (On|Off)/i,1]
|
2535
|
+
|
2536
|
+
{screen_off: state.downcase == 'off'}
|
2537
|
+
=end
|
2538
|
+
{}
|
2539
|
+
end
|
2379
2540
|
|
2380
2541
|
options = {
|
2381
2542
|
pie_lock_screen: false,
|
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,15 +33,25 @@ 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
|
+
nested = description.element('item/description')
|
38
|
+
|
39
|
+
if r[1].any? and not nested then
|
40
|
+
|
41
|
+
macro.add r[0].new(r[1])
|
42
|
+
|
43
|
+
else
|
44
|
+
|
45
|
+
puts 'description: ' + description.xml.inspect if debug
|
46
|
+
#o = r[0].new([description, self]) if r
|
47
|
+
index = macro.actions.length
|
48
|
+
macro.add Action.new
|
49
|
+
o = object_create(r[0],[description, macro]) if r
|
50
|
+
macro.actions[index] = o
|
51
|
+
puts 'after o' if debug
|
52
|
+
o
|
53
|
+
|
54
|
+
end
|
44
55
|
end
|
45
56
|
|
46
57
|
else
|
@@ -185,11 +196,11 @@ class MacroObject
|
|
185
196
|
private
|
186
197
|
|
187
198
|
def hashify(h)
|
188
|
-
|
199
|
+
#puts 'h: ' + h.inspect
|
189
200
|
h2 = h.inject({}) do |r,x|
|
190
|
-
puts 'x: ' + x.inspect if $debug
|
201
|
+
#puts 'x: ' + x.inspect #if $debug
|
191
202
|
key, value = x
|
192
|
-
puts 'key: ' + key.inspect if $debug
|
203
|
+
#puts 'key: ' + key.inspect #if $debug
|
193
204
|
new_key = key.to_s.gsub(/\w_\w/){|x| x[0] + x[-1].upcase}
|
194
205
|
new_key = new_key.prepend 'm_' unless @list.include? new_key
|
195
206
|
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 = {
|
@@ -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,15 +175,49 @@ 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
|
-
def actions(params)
|
144
|
-
|
184
|
+
def actions(params)
|
185
|
+
|
186
|
+
# -- Conditions/Loops ---------------------------------------------
|
187
|
+
#
|
188
|
+
|
189
|
+
get /else if (.*)/i do
|
190
|
+
[ElseIfConditionAction, {}]
|
191
|
+
end
|
192
|
+
|
193
|
+
#e.g a: if Airplane mode enabled
|
194
|
+
#
|
195
|
+
get /if (.*)/i do
|
196
|
+
[IfConditionAction, {}]
|
197
|
+
end
|
198
|
+
|
199
|
+
get /else/i do
|
200
|
+
[ElseAction, {}]
|
201
|
+
end
|
202
|
+
|
203
|
+
get /End If/i do
|
204
|
+
[EndIfAction, {}]
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
# -- Connectivity ------------------------------------------------------
|
209
|
+
|
210
|
+
get /^(Enable|Disable) HotSpot/i do |state|
|
211
|
+
enable, state = if state.downcase == 'enable' then
|
212
|
+
[true, 0]
|
213
|
+
else
|
214
|
+
[false, 1]
|
215
|
+
end
|
216
|
+
[SetHotspotAction, {turn_wifi_on: enable, state: state }]
|
217
|
+
end
|
218
|
+
|
145
219
|
# e.g. message popup: hello world!
|
146
|
-
get /^message popup: (.*)/i do |msg|
|
220
|
+
get /^(?:message popup|popup message): (.*)/i do |msg|
|
147
221
|
[ToastAction, {msg: msg}]
|
148
222
|
end
|
149
223
|
|
@@ -256,13 +330,13 @@ class ActionsNlp
|
|
256
330
|
|
257
331
|
#
|
258
332
|
get /^WebHook \(Url\)/i do
|
259
|
-
[OpenWebPageAction,
|
333
|
+
[OpenWebPageAction, {}]
|
260
334
|
end
|
261
335
|
|
262
336
|
# e.g. webhook entered_kitchen
|
263
337
|
#
|
264
338
|
get /^webhook$/i do
|
265
|
-
[OpenWebPageAction, params]
|
339
|
+
[OpenWebPageAction, {}, params[:macro]]
|
266
340
|
end
|
267
341
|
|
268
342
|
# -- Location ---------------------------------------------------------
|
@@ -272,7 +346,7 @@ class ActionsNlp
|
|
272
346
|
end
|
273
347
|
|
274
348
|
get /^Share Location$/i do
|
275
|
-
[ShareLocationAction,
|
349
|
+
[ShareLocationAction, {}]
|
276
350
|
end
|
277
351
|
|
278
352
|
#a: Keep Device Awake Screen On Until Disabled
|
@@ -295,32 +369,39 @@ class ActionsNlp
|
|
295
369
|
[KeepAwakeAction, h]
|
296
370
|
end
|
297
371
|
|
298
|
-
get /Keep Device Awake$/i do
|
299
|
-
[KeepAwakeAction,
|
372
|
+
get /(?:Keep Device|stay) Awake$/i do
|
373
|
+
[KeepAwakeAction, {}]
|
300
374
|
end
|
301
375
|
|
302
376
|
#a: Disable Keep Awake
|
303
377
|
#
|
304
|
-
get /Disable Keep Awake/i do
|
378
|
+
get /Disable Keep Awake|stay awake off/i do
|
305
379
|
[KeepAwakeAction, {enabled: false, screen_option: 0}]
|
306
380
|
end
|
307
381
|
|
308
|
-
#e.g a: if Airplane mode enabled
|
309
|
-
#
|
310
|
-
get /if (.*)/i do
|
311
|
-
[IfConditionAction, {}]
|
312
|
-
end
|
313
|
-
|
314
|
-
get /End If/i do
|
315
|
-
[EndIfAction, {}]
|
316
|
-
end
|
317
382
|
|
318
383
|
# -- MacroDroid Specific ------------------------------------------------
|
319
384
|
#
|
385
|
+
|
386
|
+
get /^((?:En|Dis)able) Macro$/i do |rawstate|
|
387
|
+
state = %w(enable disable toggle).index(rawstate.downcase)
|
388
|
+
[DisableMacroAction, {state: state}]
|
389
|
+
end
|
390
|
+
|
320
391
|
get /^Set Variable$/i do
|
321
392
|
[SetVariableAction, {}]
|
322
393
|
end
|
323
394
|
|
395
|
+
get /^wait (\d+) seconds$/i do |seconds|
|
396
|
+
[PauseAction, {delay_in_seconds: seconds.to_i}]
|
397
|
+
end
|
398
|
+
|
399
|
+
# -- Screen ------------------------------------------------
|
400
|
+
#
|
401
|
+
get /^Screen (On|Off)$/i do |state|
|
402
|
+
[ScreenOnAction, {screen_off: state.downcase == 'off'}]
|
403
|
+
end
|
404
|
+
|
324
405
|
end
|
325
406
|
|
326
407
|
alias find_action run_route
|
@@ -355,7 +436,7 @@ class ConstraintsNlp
|
|
355
436
|
|
356
437
|
# -- MacroDroid specific -----------------------------------------------------------------------
|
357
438
|
|
358
|
-
get /^(\w+) (=) (
|
439
|
+
get /^(\w+) (=) (.*)/i do |loperand, operator, roperand|
|
359
440
|
|
360
441
|
h = {
|
361
442
|
loperand: loperand,
|
@@ -409,19 +490,20 @@ class Macro
|
|
409
490
|
include ObjectX
|
410
491
|
|
411
492
|
attr_reader :local_variables, :triggers, :actions, :constraints,
|
412
|
-
:guid, :deviceid
|
413
|
-
attr_accessor :title, :description, :remote_url
|
493
|
+
:guid, :deviceid, :parent
|
494
|
+
attr_accessor :title, :description, :remote_url, :picture_path
|
414
495
|
|
415
|
-
def initialize(name=nil, geofences: nil, deviceid: nil, remote_url: nil,
|
416
|
-
debug: false)
|
496
|
+
def initialize(name=nil, geofences: nil, deviceid: nil, remote_url: nil, \
|
497
|
+
picture_path: nil, parent: nil, debug: false)
|
417
498
|
|
418
499
|
@title, @geofences, @deviceid, @debug = name, geofences, deviceid, debug
|
419
|
-
@remote_url = remote_url
|
500
|
+
@remote_url, @picture_path, @parent = remote_url, picture_path, parent
|
420
501
|
|
421
502
|
puts 'inside Macro#initialize' if @debug
|
422
503
|
|
423
504
|
@local_variables, @triggers, @actions, @constraints = {}, [], [], []
|
424
505
|
@h = {}
|
506
|
+
@guid = generate_guid()
|
425
507
|
|
426
508
|
end
|
427
509
|
|
@@ -463,7 +545,7 @@ class Macro
|
|
463
545
|
m_description: '',
|
464
546
|
m_name: title(),
|
465
547
|
m_excludeLog: false,
|
466
|
-
m_GUID: guid
|
548
|
+
m_GUID: @guid,
|
467
549
|
m_isOrCondition: false,
|
468
550
|
m_enabled: true,
|
469
551
|
m_descriptionOpen: false,
|
@@ -482,6 +564,7 @@ class Macro
|
|
482
564
|
puts 'h:' + h.inspect
|
483
565
|
end
|
484
566
|
|
567
|
+
@guid = h[:guid]
|
485
568
|
@category = h[:category]
|
486
569
|
@title = h[:name]
|
487
570
|
@description = h[:description]
|
@@ -702,7 +785,7 @@ class Macro
|
|
702
785
|
action = e.text.strip
|
703
786
|
r = ap.find_action action
|
704
787
|
#r[0].new(r[1]) if r
|
705
|
-
self.add object_create(r[0]
|
788
|
+
self.add object_create(r[0],*r[1..-1]) if r
|
706
789
|
|
707
790
|
end
|
708
791
|
|
@@ -970,8 +1053,8 @@ EOF
|
|
970
1053
|
|
971
1054
|
private
|
972
1055
|
|
973
|
-
def
|
974
|
-
'-' + rand(1..9).to_s + 18.times.map { rand 9 }.join
|
1056
|
+
def generate_guid()
|
1057
|
+
('-' + rand(1..9).to_s + 18.times.map { rand 9 }.join).to_i
|
975
1058
|
end
|
976
1059
|
|
977
1060
|
def object(h={})
|
@@ -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.10
|
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-18 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: glw
|
metadata.gz.sig
CHANGED
Binary file
|