ruby-macrodroid 0.9.7 → 0.9.12
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 +56 -35
- data/lib/ruby-macrodroid/actions.rb +150 -53
- data/lib/ruby-macrodroid/actionsnlp.rb +244 -0
- data/lib/ruby-macrodroid/base.rb +7 -5
- data/lib/ruby-macrodroid/constraintsnlp.rb +75 -0
- data/lib/ruby-macrodroid/macro.rb +26 -462
- data/lib/ruby-macrodroid/triggers.rb +5 -0
- data/lib/ruby-macrodroid/triggersnlp.rb +150 -0
- metadata +5 -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: f551fa79f564fe3e791b75d0bd3b5dabafd8c90b47980c5c77ab344d8b5612db
|
4
|
+
data.tar.gz: 2f5b9fe15f59cf9abfd628c7050d40229104ac1137780be6d7a9723214dbff73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fecd36b6b6da15005cfde4259886dfde7f37538d3217026958174b53a8eab4bf4af3f8903f3504f6291fdb5bce2435292d65f41904a47640486a97e1dc72be9c
|
7
|
+
data.tar.gz: 59b920327286062d098054a4225c36c0b4ab054ae98bac8c8100f5beb55cc45ee87c8f8d51cc10506a12b172fcaed6024ba4d4384233b5215062b2d127fd5e38
|
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
|
@@ -585,4 +603,7 @@ require 'ruby-macrodroid/base'
|
|
585
603
|
require 'ruby-macrodroid/triggers'
|
586
604
|
require 'ruby-macrodroid/actions'
|
587
605
|
require 'ruby-macrodroid/constraints'
|
606
|
+
require 'ruby-macrodroid/triggersnlp'
|
607
|
+
require 'ruby-macrodroid/actionsnlp'
|
608
|
+
require 'ruby-macrodroid/constraintsnlp'
|
588
609
|
require 'ruby-macrodroid/macro'
|
@@ -150,7 +150,7 @@ class OpenWebPageAction < ApplicationAction
|
|
150
150
|
|
151
151
|
def initialize(obj={}, macro=nil)
|
152
152
|
|
153
|
-
$debug =
|
153
|
+
$debug = false
|
154
154
|
puts ('obj: ' + obj.inspect).debug if $debug
|
155
155
|
|
156
156
|
h = if obj.is_a? Hash then
|
@@ -190,9 +190,9 @@ class OpenWebPageAction < ApplicationAction
|
|
190
190
|
#h[:url_to_open] = h[:url] if h[:url] and h[:url].length > 1
|
191
191
|
|
192
192
|
options = {
|
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},
|
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},
|
196
196
|
url_to_open: '',
|
197
197
|
http_get: true,
|
198
198
|
disable_url_encode: false,
|
@@ -284,11 +284,64 @@ end
|
|
284
284
|
#
|
285
285
|
class TakePictureAction < CameraAction
|
286
286
|
|
287
|
-
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
|
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
|
+
|
288
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
|
+
|
289
342
|
options = {
|
290
|
-
new_path:
|
291
|
-
path:
|
343
|
+
new_path: macro.picture_path,
|
344
|
+
path: macro.picture_path,
|
292
345
|
show_icon: true,
|
293
346
|
use_front_camera: true,
|
294
347
|
flash_option: 0
|
@@ -304,7 +357,22 @@ class TakePictureAction < CameraAction
|
|
304
357
|
end
|
305
358
|
|
306
359
|
def to_s(colour: false, indent: 0)
|
307
|
-
|
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
|
+
|
308
376
|
end
|
309
377
|
|
310
378
|
end
|
@@ -401,10 +469,14 @@ end
|
|
401
469
|
|
402
470
|
# Conditions/Loops
|
403
471
|
#
|
404
|
-
class IfConditionAction < Action
|
405
472
|
|
473
|
+
class IfAction < Action
|
474
|
+
using ColouredText
|
475
|
+
|
406
476
|
def initialize(obj=nil)
|
407
|
-
|
477
|
+
|
478
|
+
$debug = false
|
479
|
+
|
408
480
|
options = {
|
409
481
|
a: true,
|
410
482
|
constraint_list: []
|
@@ -424,10 +496,10 @@ class IfConditionAction < Action
|
|
424
496
|
super()
|
425
497
|
puts 'e.xml: ' + e.xml if $debug
|
426
498
|
puts 'e.text: ' + e.text.to_s.strip if $debug
|
427
|
-
raw_txt = e.text.to_s.strip[
|
499
|
+
raw_txt = e.text.to_s.strip[/^#{@label}[^$]+/i] || e.text('item/description')
|
428
500
|
puts 'raw_txt: ' + raw_txt.inspect if $debug
|
429
501
|
|
430
|
-
clause = raw_txt[
|
502
|
+
clause = raw_txt[/^#{@label}(.*)/i,1]
|
431
503
|
puts 'clause: ' + clause.inspect if $debug
|
432
504
|
conditions = clause.split(/\s+\b(?:AND|OR)\b\s+/i)
|
433
505
|
puts 'conditions: ' + conditions.inspect if $debug
|
@@ -446,6 +518,7 @@ class IfConditionAction < Action
|
|
446
518
|
|
447
519
|
# find any nested actions
|
448
520
|
item = e.element('item')
|
521
|
+
#puts ('item: ' + item.xml.inspect).debug if $debug
|
449
522
|
|
450
523
|
if item then
|
451
524
|
|
@@ -466,19 +539,13 @@ class IfConditionAction < Action
|
|
466
539
|
|
467
540
|
end
|
468
541
|
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
|
473
|
-
@label = 'If '
|
474
|
-
|
475
542
|
end
|
476
|
-
|
543
|
+
|
477
544
|
def to_s(colour: false, indent: 0)
|
478
545
|
|
479
546
|
h = @h.clone
|
480
547
|
#h.delete :macro
|
481
|
-
@s =
|
548
|
+
@s = @label
|
482
549
|
operator = @h[:is_or_condition] ? 'OR' : 'AND'
|
483
550
|
constraints = @constraints.map \
|
484
551
|
{|x| ' ' * indent + x.to_summary(colour: colour)}.join(" %s " % operator)
|
@@ -489,7 +556,18 @@ class IfConditionAction < Action
|
|
489
556
|
out << s + constraints
|
490
557
|
out.join("\n")
|
491
558
|
|
492
|
-
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
|
493
571
|
|
494
572
|
end
|
495
573
|
|
@@ -537,41 +615,15 @@ class ElseAction < Action
|
|
537
615
|
|
538
616
|
end
|
539
617
|
|
540
|
-
class ElseIfConditionAction <
|
618
|
+
class ElseIfConditionAction < IfAction
|
541
619
|
|
542
|
-
def initialize(
|
543
|
-
|
544
|
-
options = {
|
545
|
-
constraint_list: ''
|
546
|
-
}
|
547
|
-
|
548
|
-
super(options.merge h)
|
549
|
-
@label = 'Else If '
|
620
|
+
def initialize(obj=nil)
|
550
621
|
|
551
|
-
|
552
|
-
|
553
|
-
def to_s(colour: false, indent: 0)
|
554
|
-
|
555
|
-
h = @h.clone
|
556
|
-
h.delete :macro
|
557
|
-
@s = 'Else If '
|
558
|
-
operator = @h[:is_or_condition] ? 'OR' : 'AND'
|
559
|
-
constraints = @constraints.map \
|
560
|
-
{|x| ' ' * indent + x.to_summary(colour: colour)}.join(" %s " % operator)
|
622
|
+
@label = 'Else If '
|
623
|
+
super(obj)
|
561
624
|
|
562
|
-
out = []
|
563
|
-
out << "; %s" % @h[:comment] if @h[:comment]
|
564
|
-
s = @s.lines.map {|x| (' ' * indent) + x}.join
|
565
|
-
out << s + constraints
|
566
|
-
out.join("\n")
|
567
|
-
|
568
|
-
end
|
569
|
-
|
570
|
-
def to_summary(colour: false)
|
571
|
-
'foo'
|
572
625
|
end
|
573
|
-
|
574
|
-
|
626
|
+
|
575
627
|
end
|
576
628
|
|
577
629
|
|
@@ -1654,6 +1706,51 @@ class ConfirmNextAction < Action
|
|
1654
1706
|
|
1655
1707
|
end
|
1656
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, h2 = 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
|
+
h3 = if found then
|
1726
|
+
{macro_name: found.title, GUID: found.guid}
|
1727
|
+
else
|
1728
|
+
{macro_name: name}
|
1729
|
+
end
|
1730
|
+
|
1731
|
+
h3.merge h2
|
1732
|
+
|
1733
|
+
end
|
1734
|
+
|
1735
|
+
# state: 0 = enable, 1 = disable, 2 = toggle
|
1736
|
+
|
1737
|
+
options = {macro_name: "Change brightness", state: 1, GUID: nil}
|
1738
|
+
super(options.merge h)
|
1739
|
+
|
1740
|
+
end
|
1741
|
+
|
1742
|
+
def to_s(colour: false, indent: 0)
|
1743
|
+
|
1744
|
+
state = %w(Enable Disable Toggle)[@h[:state]]
|
1745
|
+
@s = state + ' macro'# + @h.inspect
|
1746
|
+
@s += "\n" + @h[:macro_name]
|
1747
|
+
super()
|
1748
|
+
|
1749
|
+
end
|
1750
|
+
|
1751
|
+
alias to_summary to_s
|
1752
|
+
end
|
1753
|
+
|
1657
1754
|
# MacroDroid Specific
|
1658
1755
|
#
|
1659
1756
|
class ExportMacrosAction < Action
|
@@ -1820,7 +1917,7 @@ class PauseAction < Action
|
|
1820
1917
|
options = {
|
1821
1918
|
delay_in_milli_seconds: 0, delay_in_seconds: 1, use_alarm: false
|
1822
1919
|
}
|
1823
|
-
super(h)
|
1920
|
+
super(options.merge h)
|
1824
1921
|
|
1825
1922
|
end
|
1826
1923
|
|