ruby-macrodroid 0.9.8 → 0.9.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/ruby-macrodroid.rb +50 -33
- data/lib/ruby-macrodroid/actions.rb +94 -54
- data/lib/ruby-macrodroid/actionsnlp.rb +244 -0
- data/lib/ruby-macrodroid/base.rb +9 -5
- data/lib/ruby-macrodroid/constraintsnlp.rb +75 -0
- data/lib/ruby-macrodroid/macro.rb +25 -468
- data/lib/ruby-macrodroid/triggers.rb +128 -18
- data/lib/ruby-macrodroid/triggersnlp.rb +199 -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: 0c63b70d5cc34184d15c46395e1add89a6c8999163d4fb1e9362aa80a568dba4
|
4
|
+
data.tar.gz: 797fab9bff840db398067dc5b99ac53bb3d3129668573728c31aa0883a28d792
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2bbf5ca42c6fe1be4eeeda1ba597bc4be3f0944e7a871785b629d5344268bd65d3c560fcf65de0e5b0a619c075a31f6f61eea1d8eefbd29d066777f9fb414584
|
7
|
+
data.tar.gz: 139c4462602b86d49d87d9b2e73873354550b67c8bc435bfed41d6fe6434419d4cbdfef375efdc659978e012bbb8bb9d685a08d1d75f63ae0a403a6796295da7
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/ruby-macrodroid.rb
CHANGED
@@ -122,6 +122,7 @@ class MacroDroid
|
|
122
122
|
@picture_path = picture_path
|
123
123
|
|
124
124
|
@geofences = {}
|
125
|
+
@macros = []
|
125
126
|
|
126
127
|
if obj then
|
127
128
|
|
@@ -145,34 +146,7 @@ class MacroDroid
|
|
145
146
|
|
146
147
|
if s =~ /m(?:acro)?:\s/ then
|
147
148
|
|
148
|
-
|
149
|
-
|
150
|
-
s2 = s.gsub(/^g:/,'geofence:').gsub(/^m:/,'macro:')\
|
151
|
-
.gsub(/^d:/,'description:').gsub(/^v:/,'variable:')\
|
152
|
-
.gsub(/^t:/,'trigger:').gsub(/^a:/,'action:')\
|
153
|
-
.gsub(/^c:/,'constraint:').gsub(/^#.*/,'')
|
154
|
-
|
155
|
-
a = s2.split(/(?=^macro:)/)
|
156
|
-
|
157
|
-
raw_geofences = a.shift if a.first =~ /^geofence/
|
158
|
-
raw_macros = a.join
|
159
|
-
#raw_macros, raw_geofences .reverse
|
160
|
-
|
161
|
-
puts 'raw_macros: ' + raw_macros.inspect if @debug
|
162
|
-
|
163
|
-
if raw_geofences then
|
164
|
-
|
165
|
-
geoxml = RowX.new(raw_geofences).to_xml
|
166
|
-
|
167
|
-
geodoc = Rexle.new(geoxml)
|
168
|
-
geofences = geodoc.root.xpath('item/geofence')
|
169
|
-
@geofences = fetch_geofences(geofences) if geofences.any?
|
170
|
-
|
171
|
-
end
|
172
|
-
|
173
|
-
xml = RowX.new(raw_macros, allow_lonely_keyfield: true).to_xml
|
174
|
-
puts 'xml: ' + xml if @debug
|
175
|
-
import_rowxml(xml)
|
149
|
+
import_txt(s)
|
176
150
|
|
177
151
|
elsif s =~ /^# /
|
178
152
|
xml = pc_to_xml(s)
|
@@ -229,6 +203,10 @@ class MacroDroid
|
|
229
203
|
def export(filepath)
|
230
204
|
FileX.write filepath, to_json
|
231
205
|
end
|
206
|
+
|
207
|
+
def import(s)
|
208
|
+
import_txt(s)
|
209
|
+
end
|
232
210
|
|
233
211
|
def to_json()
|
234
212
|
|
@@ -337,7 +315,7 @@ class MacroDroid
|
|
337
315
|
|
338
316
|
m = Macro.new(geofences: @geofences.map(&:last), deviceid: @deviceid,
|
339
317
|
remote_url: @remote_url, picture_path: @picture_path,
|
340
|
-
debug: @debug )
|
318
|
+
parent: self, debug: @debug )
|
341
319
|
m.import_h(macro)
|
342
320
|
m
|
343
321
|
|
@@ -356,15 +334,50 @@ class MacroDroid
|
|
356
334
|
puts 'import_rowxml: @geofences: ' + @geofences.inspect if @debug
|
357
335
|
geofences = @geofences
|
358
336
|
|
359
|
-
|
337
|
+
a = doc.root.xpath('item').map do |node|
|
360
338
|
puts ('geofences: ' + geofences.inspect).highlight if @debug
|
361
339
|
Macro.new(geofences: geofences.map(&:last), deviceid: @deviceid,
|
362
340
|
remote_url: @remote_url, picture_path: @picture_path,
|
363
|
-
debug: @debug).import_xml(node)
|
341
|
+
parent: self, debug: @debug).import_xml(node)
|
364
342
|
|
365
343
|
end
|
344
|
+
|
345
|
+
@macros.concat a
|
366
346
|
|
367
|
-
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
|
368
381
|
|
369
382
|
def import_xml(raws)
|
370
383
|
|
@@ -384,7 +397,8 @@ class MacroDroid
|
|
384
397
|
@macros = doc.root.xpath('macro').map do |node|
|
385
398
|
puts 'node: ' + node.inspect if @debug
|
386
399
|
Macro.new(geofences: @geofences.map(&:last), deviceid: @deviceid,
|
387
|
-
picture_path: @picture_path, debug: @debug)
|
400
|
+
picture_path: @picture_path, parent: self, debug: @debug)\
|
401
|
+
.import_xml(node)
|
388
402
|
|
389
403
|
end
|
390
404
|
end
|
@@ -589,4 +603,7 @@ require 'ruby-macrodroid/base'
|
|
589
603
|
require 'ruby-macrodroid/triggers'
|
590
604
|
require 'ruby-macrodroid/actions'
|
591
605
|
require 'ruby-macrodroid/constraints'
|
606
|
+
require 'ruby-macrodroid/triggersnlp'
|
607
|
+
require 'ruby-macrodroid/actionsnlp'
|
608
|
+
require 'ruby-macrodroid/constraintsnlp'
|
592
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,
|
@@ -298,7 +298,7 @@ class TakePictureAction < CameraAction
|
|
298
298
|
|
299
299
|
e, macro = obj
|
300
300
|
|
301
|
-
puts 'e: ' + e.xml.inspect
|
301
|
+
#puts 'e: ' + e.xml.inspect
|
302
302
|
|
303
303
|
a = e.xpath('item/*')
|
304
304
|
|
@@ -312,7 +312,7 @@ class TakePictureAction < CameraAction
|
|
312
312
|
|
313
313
|
desc = h2[:description]
|
314
314
|
h2.delete :description
|
315
|
-
puts 'desc: ' + desc.inspect
|
315
|
+
#puts 'desc: ' + desc.inspect
|
316
316
|
|
317
317
|
if desc.length > 1 then
|
318
318
|
|
@@ -469,10 +469,14 @@ end
|
|
469
469
|
|
470
470
|
# Conditions/Loops
|
471
471
|
#
|
472
|
-
class IfConditionAction < Action
|
473
472
|
|
473
|
+
class IfAction < Action
|
474
|
+
using ColouredText
|
475
|
+
|
474
476
|
def initialize(obj=nil)
|
475
|
-
|
477
|
+
|
478
|
+
$debug = false
|
479
|
+
|
476
480
|
options = {
|
477
481
|
a: true,
|
478
482
|
constraint_list: []
|
@@ -492,10 +496,10 @@ class IfConditionAction < Action
|
|
492
496
|
super()
|
493
497
|
puts 'e.xml: ' + e.xml if $debug
|
494
498
|
puts 'e.text: ' + e.text.to_s.strip if $debug
|
495
|
-
raw_txt = e.text.to_s.strip[
|
499
|
+
raw_txt = e.text.to_s.strip[/^#{@label}[^$]+/i] || e.text('item/description')
|
496
500
|
puts 'raw_txt: ' + raw_txt.inspect if $debug
|
497
501
|
|
498
|
-
clause = raw_txt[
|
502
|
+
clause = raw_txt[/^#{@label}(.*)/i,1]
|
499
503
|
puts 'clause: ' + clause.inspect if $debug
|
500
504
|
conditions = clause.split(/\s+\b(?:AND|OR)\b\s+/i)
|
501
505
|
puts 'conditions: ' + conditions.inspect if $debug
|
@@ -514,6 +518,7 @@ class IfConditionAction < Action
|
|
514
518
|
|
515
519
|
# find any nested actions
|
516
520
|
item = e.element('item')
|
521
|
+
#puts ('item: ' + item.xml.inspect).debug if $debug
|
517
522
|
|
518
523
|
if item then
|
519
524
|
|
@@ -534,19 +539,13 @@ class IfConditionAction < Action
|
|
534
539
|
|
535
540
|
end
|
536
541
|
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
@label = 'If '
|
542
|
-
|
543
542
|
end
|
544
|
-
|
543
|
+
|
545
544
|
def to_s(colour: false, indent: 0)
|
546
545
|
|
547
546
|
h = @h.clone
|
548
547
|
#h.delete :macro
|
549
|
-
@s =
|
548
|
+
@s = @label
|
550
549
|
operator = @h[:is_or_condition] ? 'OR' : 'AND'
|
551
550
|
constraints = @constraints.map \
|
552
551
|
{|x| ' ' * indent + x.to_summary(colour: colour)}.join(" %s " % operator)
|
@@ -557,7 +556,18 @@ class IfConditionAction < Action
|
|
557
556
|
out << s + constraints
|
558
557
|
out.join("\n")
|
559
558
|
|
560
|
-
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
|
561
571
|
|
562
572
|
end
|
563
573
|
|
@@ -605,41 +615,15 @@ class ElseAction < Action
|
|
605
615
|
|
606
616
|
end
|
607
617
|
|
608
|
-
class ElseIfConditionAction <
|
618
|
+
class ElseIfConditionAction < IfAction
|
609
619
|
|
610
|
-
def initialize(
|
611
|
-
|
612
|
-
options = {
|
613
|
-
constraint_list: ''
|
614
|
-
}
|
615
|
-
|
616
|
-
super(options.merge h)
|
617
|
-
@label = 'Else If '
|
620
|
+
def initialize(obj=nil)
|
618
621
|
|
619
|
-
|
620
|
-
|
621
|
-
def to_s(colour: false, indent: 0)
|
622
|
-
|
623
|
-
h = @h.clone
|
624
|
-
h.delete :macro
|
625
|
-
@s = 'Else If '
|
626
|
-
operator = @h[:is_or_condition] ? 'OR' : 'AND'
|
627
|
-
constraints = @constraints.map \
|
628
|
-
{|x| ' ' * indent + x.to_summary(colour: colour)}.join(" %s " % operator)
|
629
|
-
|
630
|
-
out = []
|
631
|
-
out << "; %s" % @h[:comment] if @h[:comment]
|
632
|
-
s = @s.lines.map {|x| (' ' * indent) + x}.join
|
633
|
-
out << s + constraints
|
634
|
-
out.join("\n")
|
622
|
+
@label = 'Else If '
|
623
|
+
super(obj)
|
635
624
|
|
636
|
-
end
|
637
|
-
|
638
|
-
def to_summary(colour: false)
|
639
|
-
'foo'
|
640
625
|
end
|
641
|
-
|
642
|
-
|
626
|
+
|
643
627
|
end
|
644
628
|
|
645
629
|
|
@@ -904,8 +888,17 @@ end
|
|
904
888
|
#
|
905
889
|
class SayTimeAction < DateTimeAction
|
906
890
|
|
907
|
-
def initialize(
|
908
|
-
|
891
|
+
def initialize(obj=nil)
|
892
|
+
|
893
|
+
h = if obj.is_a? Hash then
|
894
|
+
obj
|
895
|
+
elsif obj.is_a? Array
|
896
|
+
|
897
|
+
e, macro = obj
|
898
|
+
{:'12_hour' => e.text('item/description').to_s[/^\d+/] == '12'}
|
899
|
+
|
900
|
+
end
|
901
|
+
|
909
902
|
options = {
|
910
903
|
:'12_hour' => true
|
911
904
|
}
|
@@ -926,7 +919,9 @@ class SayTimeAction < DateTimeAction
|
|
926
919
|
end
|
927
920
|
|
928
921
|
def to_s(colour: false, indent: 0)
|
929
|
-
'Say Current Time'
|
922
|
+
@s = 'Say Current Time'
|
923
|
+
@s += "\n%s hour clock" % (@h[:'12_hour'] ? '12' : '24')
|
924
|
+
super()
|
930
925
|
end
|
931
926
|
|
932
927
|
end
|
@@ -1722,6 +1717,51 @@ class ConfirmNextAction < Action
|
|
1722
1717
|
|
1723
1718
|
end
|
1724
1719
|
|
1720
|
+
class DisableMacroAction < Action
|
1721
|
+
|
1722
|
+
def initialize(obj=nil)
|
1723
|
+
|
1724
|
+
h = if obj.is_a? Hash then
|
1725
|
+
|
1726
|
+
obj
|
1727
|
+
|
1728
|
+
elsif obj.is_a? Array
|
1729
|
+
|
1730
|
+
e, macro, h2 = obj
|
1731
|
+
|
1732
|
+
# find the macro guid for the given name
|
1733
|
+
name = e.text('item/description').to_s
|
1734
|
+
found = macro.parent.macros.find {|macro| macro.title =~ /#{name}/ }
|
1735
|
+
|
1736
|
+
h3 = if found then
|
1737
|
+
{macro_name: found.title, GUID: found.guid}
|
1738
|
+
else
|
1739
|
+
{macro_name: name}
|
1740
|
+
end
|
1741
|
+
|
1742
|
+
h3.merge h2
|
1743
|
+
|
1744
|
+
end
|
1745
|
+
|
1746
|
+
# state: 0 = enable, 1 = disable, 2 = toggle
|
1747
|
+
|
1748
|
+
options = {macro_name: "Change brightness", state: 1, GUID: nil}
|
1749
|
+
super(options.merge h)
|
1750
|
+
|
1751
|
+
end
|
1752
|
+
|
1753
|
+
def to_s(colour: false, indent: 0)
|
1754
|
+
|
1755
|
+
state = %w(Enable Disable Toggle)[@h[:state]]
|
1756
|
+
@s = state + ' macro'# + @h.inspect
|
1757
|
+
@s += "\n" + @h[:macro_name]
|
1758
|
+
super()
|
1759
|
+
|
1760
|
+
end
|
1761
|
+
|
1762
|
+
alias to_summary to_s
|
1763
|
+
end
|
1764
|
+
|
1725
1765
|
# MacroDroid Specific
|
1726
1766
|
#
|
1727
1767
|
class ExportMacrosAction < Action
|
@@ -1888,7 +1928,7 @@ class PauseAction < Action
|
|
1888
1928
|
options = {
|
1889
1929
|
delay_in_milli_seconds: 0, delay_in_seconds: 1, use_alarm: false
|
1890
1930
|
}
|
1891
|
-
super(h)
|
1931
|
+
super(options.merge h)
|
1892
1932
|
|
1893
1933
|
end
|
1894
1934
|
|
@@ -0,0 +1,244 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: actionsnlp.rb
|
4
|
+
|
5
|
+
|
6
|
+
class ActionsNlp
|
7
|
+
include AppRoutes
|
8
|
+
|
9
|
+
def initialize(macro=nil)
|
10
|
+
|
11
|
+
super()
|
12
|
+
|
13
|
+
params = {macro: macro}
|
14
|
+
actions(params)
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def actions(params)
|
19
|
+
|
20
|
+
# -- Conditions/Loops ---------------------------------------------
|
21
|
+
#
|
22
|
+
|
23
|
+
get /else if (.*)/i do
|
24
|
+
[ElseIfConditionAction, {}]
|
25
|
+
end
|
26
|
+
|
27
|
+
#e.g a: if Airplane mode enabled
|
28
|
+
#
|
29
|
+
get /if (.*)/i do
|
30
|
+
[IfConditionAction, {}]
|
31
|
+
end
|
32
|
+
|
33
|
+
get /else/i do
|
34
|
+
[ElseAction, {}]
|
35
|
+
end
|
36
|
+
|
37
|
+
get /End If/i do
|
38
|
+
[EndIfAction, {}]
|
39
|
+
end
|
40
|
+
|
41
|
+
|
42
|
+
# -- Connectivity ------------------------------------------------------
|
43
|
+
|
44
|
+
get /^(Enable|Disable) HotSpot/i do |state|
|
45
|
+
enable, state = if state.downcase == 'enable' then
|
46
|
+
[true, 0]
|
47
|
+
else
|
48
|
+
[false, 1]
|
49
|
+
end
|
50
|
+
[SetHotspotAction, {turn_wifi_on: enable, state: state }]
|
51
|
+
end
|
52
|
+
|
53
|
+
# e.g. message popup: hello world!
|
54
|
+
get /^(?:message popup|popup message): (.*)/i do |msg|
|
55
|
+
[ToastAction, {msg: msg}]
|
56
|
+
end
|
57
|
+
|
58
|
+
# e.g. Popup Message 'hello world!'
|
59
|
+
get /^Popup[ _]Message ['"]([^'"]+)/i do |msg|
|
60
|
+
[ToastAction, {msg: msg}]
|
61
|
+
end
|
62
|
+
|
63
|
+
# e.g. Popup Message\n hello world!
|
64
|
+
get /^Popup Message\n\s+(.*)/im do |msg|
|
65
|
+
[ToastAction, {msg: msg}]
|
66
|
+
end
|
67
|
+
|
68
|
+
# e.g. Popup Message
|
69
|
+
get /^Popup Message$/i do
|
70
|
+
[ToastAction, {}]
|
71
|
+
end
|
72
|
+
|
73
|
+
# e.g. say current time
|
74
|
+
get /^say current[ _]time/i do
|
75
|
+
[SayTimeAction, {}]
|
76
|
+
end
|
77
|
+
|
78
|
+
get /^Torch :?(.*)/i do |onoffstate|
|
79
|
+
state = %w(on off toggle).index onoffstate.downcase
|
80
|
+
[CameraFlashLightAction, {state: state}]
|
81
|
+
end
|
82
|
+
|
83
|
+
get /^Take Picture/i do
|
84
|
+
[TakePictureAction, {}]
|
85
|
+
end
|
86
|
+
|
87
|
+
get /^take_picture/i do
|
88
|
+
[TakePictureAction, {}]
|
89
|
+
end
|
90
|
+
|
91
|
+
# -- DEVICE ACTIONS ------------------------------------------------------
|
92
|
+
|
93
|
+
get /^Speak text \(([^\)]+)\)/i do |text|
|
94
|
+
[SpeakTextAction, {text: text}]
|
95
|
+
end
|
96
|
+
|
97
|
+
get /^Speak text ['"]([^'"]+)/i do |text|
|
98
|
+
[SpeakTextAction, {text: text}]
|
99
|
+
end
|
100
|
+
|
101
|
+
get /^Speak text$/i do |text|
|
102
|
+
[SpeakTextAction, {}]
|
103
|
+
end
|
104
|
+
|
105
|
+
get /^Vibrate \(([^\)]+)/i do |pattern|
|
106
|
+
[VibrateAction, {pattern: pattern}]
|
107
|
+
end
|
108
|
+
|
109
|
+
get /^Vibrate$/i do |pattern|
|
110
|
+
[VibrateAction, {pattern: 'short buzz'}]
|
111
|
+
end
|
112
|
+
|
113
|
+
# e.g. Display Notification: Hi there: This is the body of the message
|
114
|
+
get /^Display Notification: ([^:]+): [^$]+$/i do |subject, text|
|
115
|
+
[NotificationAction, {subject: subject, text: text}]
|
116
|
+
end
|
117
|
+
|
118
|
+
|
119
|
+
# e.g. Enable Wifi
|
120
|
+
get /^(Enable|Disable) Wifi$/i do |raw_state|
|
121
|
+
|
122
|
+
state = raw_state.downcase.to_sym == :enable ? 0 : 1
|
123
|
+
[SetWifiAction, {state: state}]
|
124
|
+
|
125
|
+
end
|
126
|
+
|
127
|
+
# e.g. Play: Altair
|
128
|
+
get /^Play: (.*)$/i do |name|
|
129
|
+
|
130
|
+
[PlaySoundAction, {file_path: name}]
|
131
|
+
|
132
|
+
end
|
133
|
+
|
134
|
+
# e.g. Launch Settings
|
135
|
+
get /^Launch (.*)$/i do |application|
|
136
|
+
|
137
|
+
h = {
|
138
|
+
application_name: application,
|
139
|
+
package_to_launch: 'com.android.' + application.downcase
|
140
|
+
}
|
141
|
+
[LaunchActivityAction, h]
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
# e.g. HTTP GET http://someurl.com/something
|
146
|
+
get /^HTTP GET ([^$]+)$/i do |url|
|
147
|
+
|
148
|
+
[OpenWebPageAction, url_to_open: url]
|
149
|
+
|
150
|
+
end
|
151
|
+
|
152
|
+
get /^HTTP GET$/i do
|
153
|
+
|
154
|
+
[OpenWebPageAction, {}]
|
155
|
+
|
156
|
+
end
|
157
|
+
|
158
|
+
# e.g. webhook entered_kitchen
|
159
|
+
#
|
160
|
+
get /(?:webhook|HTTP GET) ([^$]+)$/i do |s|
|
161
|
+
key = s =~ /^http/ ? :url_to_open : :identifier
|
162
|
+
[OpenWebPageAction, {key => s}]
|
163
|
+
end
|
164
|
+
|
165
|
+
#
|
166
|
+
get /^WebHook \(Url\)/i do
|
167
|
+
[OpenWebPageAction, {}]
|
168
|
+
end
|
169
|
+
|
170
|
+
# e.g. webhook entered_kitchen
|
171
|
+
#
|
172
|
+
get /^webhook$/i do
|
173
|
+
[OpenWebPageAction, {}, params[:macro]]
|
174
|
+
end
|
175
|
+
|
176
|
+
# -- Location ---------------------------------------------------------
|
177
|
+
|
178
|
+
get /^Force Location Update$/i do
|
179
|
+
[ForceLocationUpdateAction, params]
|
180
|
+
end
|
181
|
+
|
182
|
+
get /^Share Location$/i do
|
183
|
+
[ShareLocationAction, {}]
|
184
|
+
end
|
185
|
+
|
186
|
+
#a: Keep Device Awake Screen On Until Disabled
|
187
|
+
#
|
188
|
+
get /Keep Device Awake Screen On Until Disabled/i do
|
189
|
+
[KeepAwakeAction, {enabled: true, permanent: true, screen_option: 0}]
|
190
|
+
end
|
191
|
+
|
192
|
+
|
193
|
+
#a: Keep Device Awake Screen On 1h 1m 1s
|
194
|
+
#
|
195
|
+
get /Keep Device Awake Screen On ([^$]+)/i do |duration|
|
196
|
+
|
197
|
+
a = duration.split.map(&:to_i)
|
198
|
+
secs = Subunit.new(units={minutes:60, hours:60, seconds: 60}, a).to_i
|
199
|
+
|
200
|
+
h = {
|
201
|
+
permanent: true, screen_option: 0, seconds_to_stay_awake_for: secs
|
202
|
+
}
|
203
|
+
[KeepAwakeAction, h]
|
204
|
+
end
|
205
|
+
|
206
|
+
get /(?:Keep Device|stay) Awake$/i do
|
207
|
+
[KeepAwakeAction, {}]
|
208
|
+
end
|
209
|
+
|
210
|
+
#a: Disable Keep Awake
|
211
|
+
#
|
212
|
+
get /Disable Keep Awake|stay awake off/i do
|
213
|
+
[KeepAwakeAction, {enabled: false, screen_option: 0}]
|
214
|
+
end
|
215
|
+
|
216
|
+
|
217
|
+
# -- MacroDroid Specific ------------------------------------------------
|
218
|
+
#
|
219
|
+
|
220
|
+
get /^((?:En|Dis)able) Macro$/i do |rawstate|
|
221
|
+
state = %w(enable disable toggle).index(rawstate.downcase)
|
222
|
+
[DisableMacroAction, {state: state}]
|
223
|
+
end
|
224
|
+
|
225
|
+
get /^Set Variable$/i do
|
226
|
+
[SetVariableAction, {}]
|
227
|
+
end
|
228
|
+
|
229
|
+
get /^wait (\d+) seconds$/i do |seconds|
|
230
|
+
[PauseAction, {delay_in_seconds: seconds.to_i}]
|
231
|
+
end
|
232
|
+
|
233
|
+
# -- Screen ------------------------------------------------
|
234
|
+
#
|
235
|
+
get /^Screen (On|Off)$/i do |state|
|
236
|
+
[ScreenOnAction, {screen_off: state.downcase == 'off'}]
|
237
|
+
end
|
238
|
+
|
239
|
+
end
|
240
|
+
|
241
|
+
alias find_action run_route
|
242
|
+
|
243
|
+
|
244
|
+
end
|