ruby-macrodroid 0.9.8 → 0.9.13
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 +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
@@ -61,6 +61,7 @@ class Trigger < MacroObject
|
|
61
61
|
{|x| 'c: ' + x.to_summary(colour: colour, indent: 1)}.join(" %s " % operator)
|
62
62
|
|
63
63
|
@constraints.any? ? @s + "\n" + constraints : @s
|
64
|
+
super()
|
64
65
|
|
65
66
|
end
|
66
67
|
|
@@ -85,7 +86,7 @@ end
|
|
85
86
|
# ["Any Network"]
|
86
87
|
# ["some Wifi SSID"] - 1 or more SSID can be supplied
|
87
88
|
|
88
|
-
class
|
89
|
+
class WifiConnectionTrigger2 < Trigger
|
89
90
|
|
90
91
|
def initialize(h={})
|
91
92
|
|
@@ -216,7 +217,7 @@ class PowerButtonToggleTrigger < Trigger
|
|
216
217
|
end
|
217
218
|
|
218
219
|
def to_s(colour: false)
|
219
|
-
|
220
|
+
"Power Button Toggle (%s)" % @h[:num_toggles] #+ @h.inspect
|
220
221
|
end
|
221
222
|
|
222
223
|
alias to_summary to_s
|
@@ -457,7 +458,7 @@ class WebHookTrigger < Trigger
|
|
457
458
|
|
458
459
|
url = "https://trigger.macrodroid.com/%s/%s" % \
|
459
460
|
[@deviceid, @h[:identifier]]
|
460
|
-
@s = 'WebHook (Url)' + "\n
|
461
|
+
@s = 'WebHook (Url)' + "\n" + url
|
461
462
|
super()
|
462
463
|
|
463
464
|
end
|
@@ -469,8 +470,15 @@ end
|
|
469
470
|
#
|
470
471
|
class WifiConnectionTrigger < Trigger
|
471
472
|
|
472
|
-
def initialize(
|
473
|
+
def initialize(obj=nil)
|
473
474
|
|
475
|
+
h = if obj.is_a? Hash then
|
476
|
+
obj
|
477
|
+
elsif obj.is_a? Array
|
478
|
+
e, macro = obj
|
479
|
+
{ssid_list: [e.text('item/description').to_s], wifi_state: 2}
|
480
|
+
end
|
481
|
+
|
474
482
|
options = {
|
475
483
|
ssid_list: [],
|
476
484
|
wifi_state: 0
|
@@ -482,10 +490,15 @@ class WifiConnectionTrigger < Trigger
|
|
482
490
|
|
483
491
|
def to_s(colour: false)
|
484
492
|
access_point = @h[:ssid_list].first
|
485
|
-
'Connected to network
|
493
|
+
@s = 'Connected to network'
|
494
|
+
@s += "\n" + access_point
|
495
|
+
super()
|
486
496
|
end
|
487
497
|
|
488
|
-
|
498
|
+
def to_summary()
|
499
|
+
access_point = @h[:ssid_list].first
|
500
|
+
'Connected to network' + access_point
|
501
|
+
end
|
489
502
|
end
|
490
503
|
|
491
504
|
# Category: Connectivity
|
@@ -1010,7 +1023,7 @@ class MusicPlayingTrigger < DeviceEventsTrigger
|
|
1010
1023
|
def to_s(colour: false)
|
1011
1024
|
|
1012
1025
|
event = @h[:option] == 0 ? 'Started' : 'Stopped'
|
1013
|
-
@s = 'Music/Sound Playing' + "\n
|
1026
|
+
@s = 'Music/Sound Playing' + "\n%s" % event #+ @h.inspect
|
1014
1027
|
super()
|
1015
1028
|
|
1016
1029
|
end
|
@@ -1026,8 +1039,15 @@ end
|
|
1026
1039
|
#
|
1027
1040
|
class NFCTrigger < DeviceEventsTrigger
|
1028
1041
|
|
1029
|
-
def initialize(
|
1030
|
-
|
1042
|
+
def initialize(obj=nil)
|
1043
|
+
|
1044
|
+
h = if obj.is_a? Hash then
|
1045
|
+
obj
|
1046
|
+
elsif obj.is_a? Array
|
1047
|
+
e, macro = obj
|
1048
|
+
{tag_name: e.text('item/description').to_s}
|
1049
|
+
end
|
1050
|
+
|
1031
1051
|
options = {
|
1032
1052
|
}
|
1033
1053
|
|
@@ -1367,8 +1387,24 @@ end
|
|
1367
1387
|
#
|
1368
1388
|
class ActivityRecognitionTrigger < SensorsTrigger
|
1369
1389
|
|
1370
|
-
def initialize(
|
1371
|
-
|
1390
|
+
def initialize(obj=nil)
|
1391
|
+
|
1392
|
+
#puts 'obj: ' + obj.inspect
|
1393
|
+
|
1394
|
+
h = if obj.is_a? Hash then
|
1395
|
+
|
1396
|
+
obj
|
1397
|
+
|
1398
|
+
elsif obj.is_a? Array
|
1399
|
+
|
1400
|
+
e, macro, h2 = obj
|
1401
|
+
#puts 'h2: ' + h2.inspect
|
1402
|
+
#puts 'e: ' + e.xml
|
1403
|
+
s = e.text('item/description').to_s
|
1404
|
+
#puts 's: ' + s.inspect
|
1405
|
+
{confidence_level: s[/\d+%$/].to_i}.merge h2
|
1406
|
+
end
|
1407
|
+
|
1372
1408
|
options = {
|
1373
1409
|
confidence_level: 50,
|
1374
1410
|
selected_index: 1
|
@@ -1381,8 +1417,13 @@ class ActivityRecognitionTrigger < SensorsTrigger
|
|
1381
1417
|
end
|
1382
1418
|
|
1383
1419
|
def to_s(colour: false)
|
1420
|
+
|
1384
1421
|
activity = @activity[@h[:selected_index]]
|
1385
|
-
'Activity - ' + activity
|
1422
|
+
@s = 'Activity - ' + activity #+ @h.inspect
|
1423
|
+
@s += "\nConfidence >= %s%%" % @h[:confidence_level]
|
1424
|
+
|
1425
|
+
super()
|
1426
|
+
|
1386
1427
|
end
|
1387
1428
|
|
1388
1429
|
def to_summary(colour: false)
|
@@ -1577,7 +1618,7 @@ class ShortcutTrigger < Trigger
|
|
1577
1618
|
end
|
1578
1619
|
|
1579
1620
|
def to_s(colour: false)
|
1580
|
-
'
|
1621
|
+
'Shortcut Launched' #+ @h.inspect
|
1581
1622
|
end
|
1582
1623
|
|
1583
1624
|
alias to_summary to_s
|
@@ -1633,8 +1674,15 @@ end
|
|
1633
1674
|
#
|
1634
1675
|
class MediaButtonPressedTrigger < Trigger
|
1635
1676
|
|
1636
|
-
def initialize(
|
1677
|
+
def initialize(obj=nil)
|
1637
1678
|
|
1679
|
+
h = if obj.is_a? Hash then
|
1680
|
+
obj
|
1681
|
+
elsif obj.is_a? Array
|
1682
|
+
e, macro = obj
|
1683
|
+
{option: e.text('item/description').to_s}
|
1684
|
+
end
|
1685
|
+
|
1638
1686
|
options = {
|
1639
1687
|
option: 'Single Press',
|
1640
1688
|
cancel_press: false
|
@@ -1645,7 +1693,50 @@ class MediaButtonPressedTrigger < Trigger
|
|
1645
1693
|
end
|
1646
1694
|
|
1647
1695
|
def to_s(colour: false)
|
1648
|
-
|
1696
|
+
|
1697
|
+
@s = 'Media Button Pressed ' #+ @h.inspect
|
1698
|
+
@s += "\n" + @h[:option]
|
1699
|
+
super()
|
1700
|
+
|
1701
|
+
end
|
1702
|
+
|
1703
|
+
alias to_summary to_s
|
1704
|
+
end
|
1705
|
+
|
1706
|
+
class MediaButtonV2Trigger < Trigger
|
1707
|
+
|
1708
|
+
def initialize(obj=nil)
|
1709
|
+
|
1710
|
+
@a = %w(Play Play/Pause Pause Stop Previous Next Headset Hook)
|
1711
|
+
|
1712
|
+
h = if obj.is_a? Hash then
|
1713
|
+
obj
|
1714
|
+
elsif obj.is_a? Array
|
1715
|
+
e, macro = obj
|
1716
|
+
s = e.text('item/description').to_s
|
1717
|
+
a = s.split(/, /)
|
1718
|
+
{options_enabled_array: @a.map {|x| a.include? x } }
|
1719
|
+
end
|
1720
|
+
|
1721
|
+
|
1722
|
+
|
1723
|
+
options = {
|
1724
|
+
options_enabled_array: [true, false, false, false, false, false, false]
|
1725
|
+
}
|
1726
|
+
|
1727
|
+
super(options.merge h)
|
1728
|
+
|
1729
|
+
end
|
1730
|
+
|
1731
|
+
def to_s(colour: false)
|
1732
|
+
|
1733
|
+
|
1734
|
+
options = @a.zip(@h[:options_enabled_array]).select(&:last).map(&:first)
|
1735
|
+
|
1736
|
+
@s = 'Media Button V2 ' #+ @h.inspect
|
1737
|
+
@s += "\n" + options.join(', ')
|
1738
|
+
super()
|
1739
|
+
|
1649
1740
|
end
|
1650
1741
|
|
1651
1742
|
alias to_summary to_s
|
@@ -1655,8 +1746,22 @@ end
|
|
1655
1746
|
#
|
1656
1747
|
class SwipeTrigger < Trigger
|
1657
1748
|
|
1658
|
-
def initialize(
|
1659
|
-
|
1749
|
+
def initialize(obj=nil)
|
1750
|
+
|
1751
|
+
h = if obj.is_a? Hash then
|
1752
|
+
obj
|
1753
|
+
elsif obj.is_a? Array
|
1754
|
+
|
1755
|
+
e, macro = obj
|
1756
|
+
s = e.text('item/description').to_s
|
1757
|
+
start, motion = s.split(/ - /,2)
|
1758
|
+
|
1759
|
+
{
|
1760
|
+
swipe_start_area: ['Top Left', 'Top Right'].index(start),
|
1761
|
+
swipe_motion: %w(Across Diagonal Down).index(motion)
|
1762
|
+
}
|
1763
|
+
end
|
1764
|
+
|
1660
1765
|
options = {
|
1661
1766
|
swipe_start_area: 0,
|
1662
1767
|
swipe_motion: 0,
|
@@ -1668,7 +1773,12 @@ class SwipeTrigger < Trigger
|
|
1668
1773
|
end
|
1669
1774
|
|
1670
1775
|
def to_s(colour: false)
|
1671
|
-
|
1776
|
+
|
1777
|
+
direction = [['Top Left', 'Top Right'][@h[:swipe_start_area]],
|
1778
|
+
%w(Across Diagonal Down)[@h[:swipe_motion]]].join(' - ')
|
1779
|
+
@s = 'Swipe Screen'# + @h.inspect
|
1780
|
+
@s += "\n" + direction
|
1781
|
+
super()
|
1672
1782
|
end
|
1673
1783
|
|
1674
1784
|
alias to_summary to_s
|
@@ -0,0 +1,199 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# file: triggersnlp.rb
|
4
|
+
|
5
|
+
|
6
|
+
class TriggersNlp
|
7
|
+
include AppRoutes
|
8
|
+
using ColouredText
|
9
|
+
|
10
|
+
def initialize(macro=nil)
|
11
|
+
|
12
|
+
super()
|
13
|
+
params = {macro: macro}
|
14
|
+
triggers(params)
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
def triggers(params)
|
19
|
+
|
20
|
+
# -- Battery/Power ---------------------------------------------
|
21
|
+
|
22
|
+
get /Power Button Toggle \((\d)\)/i do |num|
|
23
|
+
[PowerButtonToggleTrigger, {num_toggles: num.to_i}]
|
24
|
+
end
|
25
|
+
|
26
|
+
get /^Power Connected: (Wired \([^\)]+\))/i do |s|
|
27
|
+
|
28
|
+
h = {
|
29
|
+
power_connected_options: [true, true, true],
|
30
|
+
has_set_usb_option: true,
|
31
|
+
power_connected: true
|
32
|
+
}
|
33
|
+
|
34
|
+
a = ['Wired (Fast Charge)', 'Wireless', 'Wired (Slow Charge)']
|
35
|
+
|
36
|
+
puts ('s: ' + s.inspect).debug
|
37
|
+
|
38
|
+
options = s.downcase.split(/ \+ /)
|
39
|
+
puts ('options: ' + options.inspect).debug
|
40
|
+
|
41
|
+
h[:power_connected_options] = a.map {|x| options.include? x.downcase }
|
42
|
+
|
43
|
+
[ExternalPowerTrigger, h]
|
44
|
+
end
|
45
|
+
|
46
|
+
get /^Power Connected: Any/i do |s|
|
47
|
+
|
48
|
+
h = {
|
49
|
+
power_connected_options: [true, true, true],
|
50
|
+
has_set_usb_option: true,
|
51
|
+
power_connected: true
|
52
|
+
}
|
53
|
+
|
54
|
+
[ExternalPowerTrigger, h]
|
55
|
+
end
|
56
|
+
|
57
|
+
# -- Connectivity ----------------------------------------------------
|
58
|
+
#
|
59
|
+
|
60
|
+
# Wifi State Change
|
61
|
+
|
62
|
+
get /^Connected to network (.*)$/i do |network|
|
63
|
+
[WifiConnectionTrigger, {ssid_list: [network], wifi_state: 2 }]
|
64
|
+
end
|
65
|
+
|
66
|
+
get /^Connected to network$/i do
|
67
|
+
[WifiConnectionTrigger, {}]
|
68
|
+
end
|
69
|
+
|
70
|
+
# -- Device Events ----------------------------------------------------
|
71
|
+
|
72
|
+
get /^NFC Tag$/i do |state|
|
73
|
+
[NFCTrigger, {}]
|
74
|
+
end
|
75
|
+
|
76
|
+
get /^Screen[ _](On|Off)/i do |state|
|
77
|
+
[ScreenOnOffTrigger, {screen_on: state.downcase == 'on'}]
|
78
|
+
end
|
79
|
+
|
80
|
+
# e.g. at 7:30pm daily
|
81
|
+
get /^(?:at )?(\d+:\d+(?:[ap]m)?) daily/i do |time, days|
|
82
|
+
[TimerTrigger, {time: time,
|
83
|
+
days: %w(Mon Tue Wed Thu Fri Sat Sun).join(', ')}]
|
84
|
+
end
|
85
|
+
|
86
|
+
get /^(?:at )?(\d+:\d+(?:[ap]m)?) (?:on )?(.*)/i do |time, days|
|
87
|
+
[TimerTrigger, {time: time, days: days}]
|
88
|
+
end
|
89
|
+
|
90
|
+
# time.is? 'at 18:30pm on Mon or Tue'
|
91
|
+
get /^time.is\? ['"](?:at )?(\d+:\d+(?:[ap]m)?) (?:on )?(.*)['"]/i do |time, days|
|
92
|
+
[TimerTrigger, {time: time, days: days.gsub(' or ',', ')}]
|
93
|
+
end
|
94
|
+
|
95
|
+
get /^shake[ _]device\??$/i do
|
96
|
+
[ShakeDeviceTrigger, {}]
|
97
|
+
end
|
98
|
+
|
99
|
+
get /^Flip Device (.*)$/i do |motion|
|
100
|
+
facedown = motion =~ /Face Up (?:->|to) Face Down/i
|
101
|
+
[FlipDeviceTrigger, {face_down: facedown }]
|
102
|
+
end
|
103
|
+
|
104
|
+
get /^flip_device_down\?$/i do
|
105
|
+
[FlipDeviceTrigger, {face_down: true }]
|
106
|
+
end
|
107
|
+
|
108
|
+
get /^flip_device_up\?$/i do
|
109
|
+
[FlipDeviceTrigger, {face_down: false }]
|
110
|
+
end
|
111
|
+
|
112
|
+
get /^Failed Login Attempt$/i do
|
113
|
+
[FailedLoginTrigger, {}]
|
114
|
+
end
|
115
|
+
|
116
|
+
get /^failed_login?$/i do
|
117
|
+
[FailedLoginTrigger, {}]
|
118
|
+
end
|
119
|
+
|
120
|
+
get /^Geofence (Entry|Exit) \(([^\)]+)/i do |direction, name|
|
121
|
+
enter_area = direction.downcase.to_sym == :entry
|
122
|
+
[GeofenceTrigger, {name: name, enter_area: enter_area}]
|
123
|
+
end
|
124
|
+
|
125
|
+
get /^location (entered|exited) \(([^\)]+)/i do |direction, name|
|
126
|
+
enter_area = direction.downcase.to_sym == :entered
|
127
|
+
[GeofenceTrigger, {name: name, enter_area: enter_area}]
|
128
|
+
end
|
129
|
+
|
130
|
+
# eg. Proximity Sensor (Near)
|
131
|
+
#
|
132
|
+
get /^Proximity Sensor \(([^\)]+)\)/i do |distance|
|
133
|
+
|
134
|
+
[ProximityTrigger, {distance: distance}]
|
135
|
+
end
|
136
|
+
|
137
|
+
# eg. Proximity near
|
138
|
+
#
|
139
|
+
get /^Proximity (near|far|slow wave|fast wave)/i do |distance|
|
140
|
+
|
141
|
+
[ProximityTrigger, {distance: distance}]
|
142
|
+
end
|
143
|
+
|
144
|
+
get /^WebHook \(Url\)/i do
|
145
|
+
[WebHookTrigger, params]
|
146
|
+
end
|
147
|
+
|
148
|
+
get /^WebHook/i do
|
149
|
+
[WebHookTrigger, params]
|
150
|
+
end
|
151
|
+
|
152
|
+
get /^wh/i do
|
153
|
+
[WebHookTrigger, params]
|
154
|
+
end
|
155
|
+
|
156
|
+
#-- MacroDroid specific ---------------------------------------------------------------
|
157
|
+
|
158
|
+
get /^EmptyTrigger$/i do
|
159
|
+
[EmptyTrigger, params]
|
160
|
+
end
|
161
|
+
|
162
|
+
#-- Sensors ---------------------------------------------------------------
|
163
|
+
|
164
|
+
get /^Activity - (.*)$/i do |s|
|
165
|
+
|
166
|
+
a = ['In Vehicle', 'On Bicycle', 'Running', 'Walking', 'Still']
|
167
|
+
r = a.find {|x| x.downcase == s.downcase}
|
168
|
+
h = r ? {selected_index: a.index(r)} : {}
|
169
|
+
[ActivityRecognitionTrigger , h]
|
170
|
+
end
|
171
|
+
|
172
|
+
# -- User Input ---------------------------------------------------------------
|
173
|
+
|
174
|
+
get /^Media Button Pressed$/i do
|
175
|
+
[MediaButtonPressedTrigger, {}]
|
176
|
+
end
|
177
|
+
|
178
|
+
get /^Media Button V2$/i do
|
179
|
+
[MediaButtonV2Trigger, {}]
|
180
|
+
end
|
181
|
+
|
182
|
+
get /^Shortcut Launched$/i do
|
183
|
+
[ShortcutTrigger, {}]
|
184
|
+
end
|
185
|
+
|
186
|
+
get /^Swipe Screen$/i do
|
187
|
+
[SwipeTrigger, {}]
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
|
192
|
+
alias find_trigger run_route
|
193
|
+
|
194
|
+
def to_s(colour: false)
|
195
|
+
'TriggersNlp ' + @h.inspect
|
196
|
+
end
|
197
|
+
|
198
|
+
alias to_summary to_s
|
199
|
+
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.13
|
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-20 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: glw
|
@@ -185,10 +185,13 @@ extra_rdoc_files: []
|
|
185
185
|
files:
|
186
186
|
- lib/ruby-macrodroid.rb
|
187
187
|
- lib/ruby-macrodroid/actions.rb
|
188
|
+
- lib/ruby-macrodroid/actionsnlp.rb
|
188
189
|
- lib/ruby-macrodroid/base.rb
|
189
190
|
- lib/ruby-macrodroid/constraints.rb
|
191
|
+
- lib/ruby-macrodroid/constraintsnlp.rb
|
190
192
|
- lib/ruby-macrodroid/macro.rb
|
191
193
|
- lib/ruby-macrodroid/triggers.rb
|
194
|
+
- lib/ruby-macrodroid/triggersnlp.rb
|
192
195
|
homepage: https://github.com/jrobertson/ruby-macrodroid
|
193
196
|
licenses:
|
194
197
|
- MIT
|