ruby-macrodroid 0.9.10 → 0.9.15

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: cfb8dbf1cb2f5796722de69e98afcb6d7058ba6faf743740a989589fd3d72fc5
4
- data.tar.gz: 4b6ff72308bae85939e3eadf7776a3b56d2b8084103633dbb7754f496fb7c037
3
+ metadata.gz: 3ee2f540a744e2a309b3e4306a3f75c9ac3f437ebb9907d6f98cc39ea9b873fb
4
+ data.tar.gz: 1f8f909bcd280c7fabe301d8cbb3c8535d56901bb7986224cc0d046cccb3b61b
5
5
  SHA512:
6
- metadata.gz: 722fc170955c3ee925821859e87c3380b5769db34081c8318ee043218e2bb36ae43e104d6c701238ef887405c30c8d05ab3cba32a040e6430392bc60dd6dbce1
7
- data.tar.gz: 2343b75872d051e055d3dd6955dcf03c7c236ef5f77e1b43b5618515b8f0170728878336fe8a2aed5eac51ddce9361c751f3d9170418ee289d2e5522b18ff472
6
+ metadata.gz: 045fb9a42206777def57c23a89ec1aaccb2dac969b44f2b0fc388885e14a7ce8c1a6f093451237dcbfe8e2287cc3395033506853da6dca94706e368704df66ae
7
+ data.tar.gz: fc65220be3fd9e7265b6bfcdf194735c831e02fcb3b6c8e158d6e24cde83cbbbcfbb1547cd4932a0a96ba79f552d9134690dc1e91fdd0405751a6d6c41e382f9
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -603,4 +603,7 @@ require 'ruby-macrodroid/base'
603
603
  require 'ruby-macrodroid/triggers'
604
604
  require 'ruby-macrodroid/actions'
605
605
  require 'ruby-macrodroid/constraints'
606
+ require 'ruby-macrodroid/triggersnlp'
607
+ require 'ruby-macrodroid/actionsnlp'
608
+ require 'ruby-macrodroid/constraintsnlp'
606
609
  require 'ruby-macrodroid/macro'
@@ -32,6 +32,30 @@
32
32
  #
33
33
 
34
34
 
35
+ APPS = {
36
+ 'AutoBoy' => 'com.happyconz.blackbox',
37
+ 'Amazon Alexa' => 'com.amazon.dee.app',
38
+ 'Brave' => 'com.brave.browser',
39
+ 'Camera' => 'com.google.android.camera',
40
+ 'Cast to TV' => 'cast.video.screenmirroring.casttotv',
41
+ 'File Manager' => 'com.alphainventor.filemanager',
42
+ 'Firefox' => 'org.mozilla.firefox',
43
+ 'Google Chrome' => 'com.google.android.chrome',
44
+ 'Chrome' => 'com.google.android.chrome',
45
+ 'Google Home' => 'com.google.android.apps.chromecast.app',
46
+ 'Google Play Music' => 'com.google.android.music',
47
+ 'MacroDroid' => 'com.arlosoft.macrodroid',
48
+ 'QuickEdit Text Editor Pro' => 'com.rhmsoft.edit.pro',
49
+ 'QR & Barcode Reader' => 'com.teacapps.barcodescanner',
50
+ 'Settings' => 'com.google.android.settings',
51
+ 'tinyCam PRO' => 'com.alexvas.dvr.pro',
52
+ 'Tor Browser' => 'org.torproject.torbrowser',
53
+ 'VLC' => 'org.videolan.vlc',
54
+ 'WiFi FTP Server' => 'com.medhaapps.wififtpserver',
55
+ 'YouTube' => 'com.google.android.youtube'
56
+ }
57
+
58
+
35
59
  class Action < MacroObject
36
60
  using ColouredText
37
61
  using Params
@@ -888,8 +912,17 @@ end
888
912
  #
889
913
  class SayTimeAction < DateTimeAction
890
914
 
891
- def initialize(h={})
892
-
915
+ def initialize(obj=nil)
916
+
917
+ h = if obj.is_a? Hash then
918
+ obj
919
+ elsif obj.is_a? Array
920
+
921
+ e, macro = obj
922
+ {:'12_hour' => e.text('item/description').to_s[/^\d+/] == '12'}
923
+
924
+ end
925
+
893
926
  options = {
894
927
  :'12_hour' => true
895
928
  }
@@ -910,7 +943,9 @@ class SayTimeAction < DateTimeAction
910
943
  end
911
944
 
912
945
  def to_s(colour: false, indent: 0)
913
- 'Say Current Time'
946
+ @s = 'Say Current Time'
947
+ @s += "\n%s hour clock" % (@h[:'12_hour'] ? '12' : '24')
948
+ super()
914
949
  end
915
950
 
916
951
  end
@@ -1656,9 +1691,18 @@ class ClearLogAction < LoggingAction
1656
1691
  end
1657
1692
 
1658
1693
 
1694
+ class MacroDroidAction < Action
1695
+
1696
+ def initialize(h={})
1697
+ super(h)
1698
+ @group = 'macrodroid'
1699
+ end
1700
+
1701
+ end
1702
+
1659
1703
  # MacroDroid Specific
1660
1704
  #
1661
- class CancelActiveMacroAction < Action
1705
+ class CancelActiveMacroAction < MacroDroidAction
1662
1706
 
1663
1707
  def initialize(h={})
1664
1708
 
@@ -1682,7 +1726,7 @@ end
1682
1726
 
1683
1727
  # MacroDroid Specific
1684
1728
  #
1685
- class ConfirmNextAction < Action
1729
+ class ConfirmNextAction < MacroDroidAction
1686
1730
 
1687
1731
  def initialize(h={})
1688
1732
 
@@ -1706,7 +1750,7 @@ class ConfirmNextAction < Action
1706
1750
 
1707
1751
  end
1708
1752
 
1709
- class DisableMacroAction < Action
1753
+ class DisableMacroAction < MacroDroidAction
1710
1754
 
1711
1755
  def initialize(obj=nil)
1712
1756
 
@@ -1716,17 +1760,19 @@ class DisableMacroAction < Action
1716
1760
 
1717
1761
  elsif obj.is_a? Array
1718
1762
 
1719
- e, macro = obj
1763
+ e, macro, h2 = obj
1720
1764
 
1721
1765
  # find the macro guid for the given name
1722
1766
  name = e.text('item/description').to_s
1723
1767
  found = macro.parent.macros.find {|macro| macro.title =~ /#{name}/ }
1724
1768
 
1725
- if found then
1769
+ h3 = if found then
1726
1770
  {macro_name: found.title, GUID: found.guid}
1727
1771
  else
1728
1772
  {macro_name: name}
1729
1773
  end
1774
+
1775
+ h3.merge h2
1730
1776
 
1731
1777
  end
1732
1778
 
@@ -1751,7 +1797,7 @@ end
1751
1797
 
1752
1798
  # MacroDroid Specific
1753
1799
  #
1754
- class ExportMacrosAction < Action
1800
+ class ExportMacrosAction < MacroDroidAction
1755
1801
 
1756
1802
  def initialize(h={})
1757
1803
 
@@ -1773,9 +1819,61 @@ class ExportMacrosAction < Action
1773
1819
  end
1774
1820
 
1775
1821
 
1822
+
1823
+ class ForceMacroRunAction < MacroDroidAction
1824
+
1825
+ def initialize(obj=nil)
1826
+
1827
+ h = if obj.is_a? Hash then
1828
+
1829
+ obj
1830
+
1831
+ elsif obj.is_a? Array
1832
+
1833
+ e, macro, h2 = obj
1834
+
1835
+ # find the macro guid for the given name
1836
+ name = e.text('item/description').to_s
1837
+ found = macro.parent.macros.find {|macro| macro.title =~ /#{name}/ }
1838
+
1839
+ h3 = if found then
1840
+ {macro_name: found.title, GUID: found.guid}
1841
+ else
1842
+ {macro_name: name}
1843
+ end
1844
+
1845
+ h3.merge h2
1846
+
1847
+ end
1848
+
1849
+ options = {
1850
+ guid: nil, ignore_constraints: true,
1851
+ macro_name: "", use_off_status: false,
1852
+ user_prompt_title: "Run Macro"
1853
+ }
1854
+ super(options.merge h)
1855
+
1856
+ end
1857
+
1858
+ def invoke()
1859
+ super(macro_name: @h[:macro_name])
1860
+ end
1861
+
1862
+ def to_s(colour: false, indent: 0)
1863
+
1864
+ @s = 'Macro Run'# + @h.inspect
1865
+ @s += "\n" + @h[:macro_name]
1866
+ super()
1867
+
1868
+ end
1869
+
1870
+ alias to_summary to_s
1871
+
1872
+ end
1873
+
1776
1874
  # MacroDroid Specific
1777
1875
  #
1778
- class SetVariableAction < Action
1876
+ class SetVariableAction < MacroDroidAction
1779
1877
  using ColouredText
1780
1878
 
1781
1879
  def initialize(obj=nil)
@@ -1865,7 +1963,7 @@ end
1865
1963
 
1866
1964
  # MacroDroid Specific
1867
1965
  #
1868
- class TextManipulationAction < Action
1966
+ class TextManipulationAction < MacroDroidAction
1869
1967
 
1870
1968
  def initialize(h={})
1871
1969
 
@@ -1908,7 +2006,7 @@ end
1908
2006
 
1909
2007
 
1910
2008
 
1911
- class PauseAction < Action
2009
+ class PauseAction < MacroDroidAction
1912
2010
 
1913
2011
  def initialize(h={})
1914
2012
 
@@ -1948,6 +2046,62 @@ end
1948
2046
 
1949
2047
  # Category: Media
1950
2048
  #
2049
+
2050
+
2051
+ # note: to find a package id from an App name, try searching for the name on
2052
+ # the Google Play Store and the id will be returned in the URL once the
2053
+ # correct app has been clicked. e.g.
2054
+ # https://play.google.com/store/apps/details?id=com.google.android.music
2055
+ #
2056
+ class ControlMediaAction < MediaAction
2057
+
2058
+ def initialize(obj=nil)
2059
+
2060
+ h = if obj.is_a? Hash then
2061
+ obj
2062
+ elsif obj.is_a? Array
2063
+
2064
+ e, macro = obj
2065
+ s = e.text('item/description').to_s
2066
+ app = s[/Simulate Media Button \(([^\)]+)/,1]
2067
+
2068
+ if app then
2069
+
2070
+ {
2071
+ application_name: app, package_name: APPS[app],
2072
+ simulate_media_button: true
2073
+ }
2074
+
2075
+ else
2076
+ {}
2077
+ end
2078
+ end
2079
+
2080
+ options = {
2081
+ application_name: "Google Play Music", option: "Play/Pause",
2082
+ package_name: "com.google.android.music",
2083
+ send_media_player_commands: false,
2084
+ simulate_media_button: true,
2085
+ }
2086
+
2087
+ super(options.merge h)
2088
+
2089
+ end
2090
+
2091
+ def to_s(colour: false, indent: 0)
2092
+
2093
+ @s = 'Media ' + @h[:option] #+ @h.inspect
2094
+
2095
+ if @h[:simulate_media_button] then
2096
+ @s += "\nSimulate Media Button (%s)" % @h[:application_name]
2097
+ end
2098
+
2099
+ super()
2100
+ end
2101
+
2102
+ alias to_summary to_s
2103
+ end
2104
+
1951
2105
  class RecordMicrophoneAction < MediaAction
1952
2106
 
1953
2107
  def initialize(h={})
@@ -0,0 +1,262 @@
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
+ app = APPS[application] || 'com.android.' + application.downcase.split()\
138
+ .join('.')
139
+ h = {
140
+ application_name: application,
141
+ package_to_launch: app
142
+ }
143
+ [LaunchActivityAction, h]
144
+
145
+ end
146
+
147
+ # e.g. HTTP GET http://someurl.com/something
148
+ get /^HTTP GET ([^$]+)$/i do |url|
149
+
150
+ [OpenWebPageAction, url_to_open: url]
151
+
152
+ end
153
+
154
+ get /^HTTP GET$/i do
155
+
156
+ [OpenWebPageAction, {}]
157
+
158
+ end
159
+
160
+ # e.g. webhook entered_kitchen
161
+ #
162
+ get /(?:webhook|HTTP GET) ([^$]+)$/i do |s|
163
+ key = s =~ /^http/ ? :url_to_open : :identifier
164
+ [OpenWebPageAction, {key => s}]
165
+ end
166
+
167
+ #
168
+ get /^WebHook \(Url\)/i do
169
+ [OpenWebPageAction, {}]
170
+ end
171
+
172
+ # e.g. webhook entered_kitchen
173
+ #
174
+ get /^webhook$/i do
175
+ [OpenWebPageAction, {}, params[:macro]]
176
+ end
177
+
178
+ # -- Location ---------------------------------------------------------
179
+
180
+ get /^Force Location Update$/i do
181
+ [ForceLocationUpdateAction, params]
182
+ end
183
+
184
+ get /^Share Location$/i do
185
+ [ShareLocationAction, {}]
186
+ end
187
+
188
+ #a: Keep Device Awake Screen On Until Disabled
189
+ #
190
+ get /Keep Device Awake Screen On Until Disabled/i do
191
+ [KeepAwakeAction, {enabled: true, permanent: true, screen_option: 0}]
192
+ end
193
+
194
+
195
+ #a: Keep Device Awake Screen On 1h 1m 1s
196
+ #
197
+ get /Keep Device Awake Screen On ([^$]+)/i do |duration|
198
+
199
+ a = duration.split.map(&:to_i)
200
+ secs = Subunit.new(units={minutes:60, hours:60, seconds: 60}, a).to_i
201
+
202
+ h = {
203
+ permanent: true, screen_option: 0, seconds_to_stay_awake_for: secs
204
+ }
205
+ [KeepAwakeAction, h]
206
+ end
207
+
208
+ get /(?:Keep Device|stay) Awake$/i do
209
+ [KeepAwakeAction, {}]
210
+ end
211
+
212
+ #a: Disable Keep Awake
213
+ #
214
+ get /Disable Keep Awake|stay awake off/i do
215
+ [KeepAwakeAction, {enabled: false, screen_option: 0}]
216
+ end
217
+
218
+
219
+ # -- MacroDroid Specific ------------------------------------------------
220
+ #
221
+
222
+ get /^((?:En|Dis)able) Macro$/i do |rawstate|
223
+ state = %w(enable disable toggle).index(rawstate.downcase)
224
+ [DisableMacroAction, {state: state}]
225
+ end
226
+
227
+ get /^Macro Run$/i do
228
+ [ForceMacroRunAction, {}]
229
+ end
230
+
231
+ get /^Run Macro$/i do
232
+ [ForceMacroRunAction, {}]
233
+ end
234
+
235
+ get /^Set Variable$/i do
236
+ [SetVariableAction, {}]
237
+ end
238
+
239
+ get /^wait (\d+) seconds$/i do |seconds|
240
+ [PauseAction, {delay_in_seconds: seconds.to_i}]
241
+ end
242
+
243
+ ## -- Media -----------------------------------------
244
+ #
245
+ # options: Play/Pause, Previous, Next, Play, Pause, Stop
246
+ #
247
+ get /^Media ([^$]+)$/i do |option|
248
+ [ControlMediaAction, {option: option}]
249
+ end
250
+
251
+ # -- Screen ------------------------------------------------
252
+ #
253
+ get /^Screen (On|Off)$/i do |state|
254
+ [ScreenOnAction, {screen_off: state.downcase == 'off'}]
255
+ end
256
+
257
+ end
258
+
259
+ alias find_action run_route
260
+
261
+
262
+ end