ruby-macrodroid 0.9.11 → 0.9.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7c377e6586f261b43617f7daa117872cab4a642476c7923a6b353e2d3adfea8b
4
- data.tar.gz: 73dc4c91553017f35fa6d37afcda647ff1e14fd732f6bb52c89266fde62c66f0
3
+ metadata.gz: e9789db9405136e821003060f52912072c11665303ab25a714c93d5dac058d8f
4
+ data.tar.gz: 7878f4f2c52b3450e2485e5b993cfe275269e88e125da647f89ddf73610c504e
5
5
  SHA512:
6
- metadata.gz: 1fc6439e1bb63fde2828ba2cc3593223b0fdf9ec22c6caf2e926456973663f85cb0f389d641503e41e82c1b660412781485b8ef8b280b55fe7e077ebdaa64cce
7
- data.tar.gz: 2056084f2c420f6f7a3328c92f6ebad1caf150a0a34ea353f1ce2fce5c22c237841ce02dbea3a805eb73baad69a4beb57050570a593a63052559a498fb22c416
6
+ metadata.gz: 6a2f574bc7692cba9cf2cc31228c5c4e6cd4aa78de0bb3a73c5e73c1458fd6cdc0798ac31aebd9e1833738ce700819257a02242c13ed2c5bc91f4e977d171e27
7
+ data.tar.gz: ce58d73abe7f2583bd50a7c6fa0fda42c9aa2a0cf14b9fc370c066dad69fcb8263332f685da3f14aee447180fbfcd9cd5a25a59b81853748114e58e420c6f74c
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
@@ -150,17 +174,17 @@ class OpenWebPageAction < ApplicationAction
150
174
 
151
175
  def initialize(obj={}, macro=nil)
152
176
 
153
- $debug = false
177
+ $debug = true
154
178
  puts ('obj: ' + obj.inspect).debug if $debug
155
179
 
156
180
  h = if obj.is_a? Hash then
157
181
 
158
- obj.merge({macro: macro})
182
+ obj.merge({macro: macro}) #unless obj and obj[:macro]
159
183
 
160
184
  elsif obj.is_a? Array
161
185
 
162
186
  puts ('obj: ' + obj.inspect).debug if $debug
163
- e, macro = obj
187
+ e, macro, h3 = obj
164
188
 
165
189
  a = e.xpath('item/*')
166
190
 
@@ -181,7 +205,7 @@ class OpenWebPageAction < ApplicationAction
181
205
  {url: (txt || e.text)}
182
206
  end
183
207
 
184
- h2.merge(macro: macro)
208
+ h2.merge(macro: macro).merge(h3)
185
209
 
186
210
  end
187
211
 
@@ -219,6 +243,7 @@ class OpenWebPageAction < ApplicationAction
219
243
  h[:macro].title.downcase.gsub(/ +/,'-')
220
244
 
221
245
  end
246
+ puts 'url: ' + url.inspect if $debug
222
247
 
223
248
  if h2 then
224
249
 
@@ -242,7 +267,8 @@ class OpenWebPageAction < ApplicationAction
242
267
  end
243
268
 
244
269
  def to_s(colour: false, indent: 0)
245
- @s = "HTTP GET\nurl: " + @h[:url_to_open]
270
+ s = @h[:http_get] ? '' : 'Open Website / '
271
+ @s = s + "HTTP GET\nurl: " + @h[:url_to_open]
246
272
  super()
247
273
  end
248
274
 
@@ -888,8 +914,17 @@ end
888
914
  #
889
915
  class SayTimeAction < DateTimeAction
890
916
 
891
- def initialize(h={})
892
-
917
+ def initialize(obj=nil)
918
+
919
+ h = if obj.is_a? Hash then
920
+ obj
921
+ elsif obj.is_a? Array
922
+
923
+ e, macro = obj
924
+ {:'12_hour' => e.text('item/description').to_s[/^\d+/] == '12'}
925
+
926
+ end
927
+
893
928
  options = {
894
929
  :'12_hour' => true
895
930
  }
@@ -910,7 +945,9 @@ class SayTimeAction < DateTimeAction
910
945
  end
911
946
 
912
947
  def to_s(colour: false, indent: 0)
913
- 'Say Current Time'
948
+ @s = 'Say Current Time'
949
+ @s += "\n%s hour clock" % (@h[:'12_hour'] ? '12' : '24')
950
+ super()
914
951
  end
915
952
 
916
953
  end
@@ -950,8 +987,15 @@ end
950
987
  #
951
988
  class ClipboardAction < DeviceAction
952
989
 
953
- def initialize(h={})
990
+ def initialize(obj=nil)
954
991
 
992
+ h = if obj.is_a? Hash then
993
+ obj
994
+ elsif obj.is_a? Array
995
+ e, macro = obj
996
+ {clipboard_text: e.text('item/description').to_s}
997
+ end
998
+
955
999
  options = {
956
1000
  clipboard_text: ''
957
1001
  }
@@ -1031,14 +1075,57 @@ end
1031
1075
  #
1032
1076
  class UIInteractionAction < DeviceAction
1033
1077
 
1034
- def initialize(h={})
1078
+ def initialize(obj=nil)
1035
1079
 
1080
+ if obj.is_a? Hash then
1081
+ h = obj
1082
+ elsif obj.is_a? Array
1083
+
1084
+ e, macro = obj
1085
+ s = e.text('item/description').to_s
1086
+
1087
+ r = s.match(/^(Click|Long Click) \[([^\]]+)/)
1088
+
1089
+ # [Current focus] # Current focus
1090
+ # [0,0] # x,y location
1091
+ # [274,186] # Identify in app
1092
+ # [fooo] # Text content
1093
+
1094
+ h = {
1095
+ ui_interaction_configuration: {}, :xy_point=>{:x=>0, :y=>0},
1096
+ :type=>"Click"
1097
+ }
1098
+ h2 = {}
1099
+
1100
+ if r then
1101
+
1102
+ h[:action] = 0
1103
+
1104
+ click, detail = r.captures
1105
+ h2[:long_click] = false if click.downcase.to_sym == :click
1106
+
1107
+ if detail == 'Current focus' then
1108
+ h2[:click_option] = 1
1109
+ elsif detail =~ /\d+,\d+/
1110
+ # to-do
1111
+ else
1112
+ # text content
1113
+ h2[:click_option] = 1
1114
+ h2[:text_content] = detail
1115
+ end
1116
+
1117
+ h[:ui_interaction_configuration] = h2
1118
+ end
1119
+
1120
+ end
1121
+
1036
1122
  options = {
1037
1123
  ui_interaction_configuration: {:type=>"Copy"},
1038
1124
  action: 2
1039
1125
  }
1040
1126
 
1041
- super(options.merge h)
1127
+
1128
+ super(options.merge h)
1042
1129
 
1043
1130
  end
1044
1131
 
@@ -1078,7 +1165,7 @@ class UIInteractionAction < DeviceAction
1078
1165
  "Gesture [%s]" % detail
1079
1166
  end
1080
1167
 
1081
- 'UI Interaction' + "\n " + s #+ ' ' + @h.inspect
1168
+ 'UI Interaction' + "\n " + s + ' ' + @h.inspect
1082
1169
  end
1083
1170
 
1084
1171
  alias to_summary to_s
@@ -1656,9 +1743,18 @@ class ClearLogAction < LoggingAction
1656
1743
  end
1657
1744
 
1658
1745
 
1746
+ class MacroDroidAction < Action
1747
+
1748
+ def initialize(h={})
1749
+ super(h)
1750
+ @group = 'macrodroid'
1751
+ end
1752
+
1753
+ end
1754
+
1659
1755
  # MacroDroid Specific
1660
1756
  #
1661
- class CancelActiveMacroAction < Action
1757
+ class CancelActiveMacroAction < MacroDroidAction
1662
1758
 
1663
1759
  def initialize(h={})
1664
1760
 
@@ -1682,7 +1778,7 @@ end
1682
1778
 
1683
1779
  # MacroDroid Specific
1684
1780
  #
1685
- class ConfirmNextAction < Action
1781
+ class ConfirmNextAction < MacroDroidAction
1686
1782
 
1687
1783
  def initialize(h={})
1688
1784
 
@@ -1706,7 +1802,7 @@ class ConfirmNextAction < Action
1706
1802
 
1707
1803
  end
1708
1804
 
1709
- class DisableMacroAction < Action
1805
+ class DisableMacroAction < MacroDroidAction
1710
1806
 
1711
1807
  def initialize(obj=nil)
1712
1808
 
@@ -1753,7 +1849,7 @@ end
1753
1849
 
1754
1850
  # MacroDroid Specific
1755
1851
  #
1756
- class ExportMacrosAction < Action
1852
+ class ExportMacrosAction < MacroDroidAction
1757
1853
 
1758
1854
  def initialize(h={})
1759
1855
 
@@ -1775,9 +1871,61 @@ class ExportMacrosAction < Action
1775
1871
  end
1776
1872
 
1777
1873
 
1874
+
1875
+ class ForceMacroRunAction < MacroDroidAction
1876
+
1877
+ def initialize(obj=nil)
1878
+
1879
+ h = if obj.is_a? Hash then
1880
+
1881
+ obj
1882
+
1883
+ elsif obj.is_a? Array
1884
+
1885
+ e, macro, h2 = obj
1886
+
1887
+ # find the macro guid for the given name
1888
+ name = e.text('item/description').to_s
1889
+ found = macro.parent.macros.find {|macro| macro.title =~ /#{name}/ }
1890
+
1891
+ h3 = if found then
1892
+ {macro_name: found.title, GUID: found.guid}
1893
+ else
1894
+ {macro_name: name}
1895
+ end
1896
+
1897
+ h3.merge h2
1898
+
1899
+ end
1900
+
1901
+ options = {
1902
+ guid: nil, ignore_constraints: true,
1903
+ macro_name: "", use_off_status: false,
1904
+ user_prompt_title: "Run Macro"
1905
+ }
1906
+ super(options.merge h)
1907
+
1908
+ end
1909
+
1910
+ def invoke()
1911
+ super(macro_name: @h[:macro_name])
1912
+ end
1913
+
1914
+ def to_s(colour: false, indent: 0)
1915
+
1916
+ @s = 'Macro Run'# + @h.inspect
1917
+ @s += "\n" + @h[:macro_name]
1918
+ super()
1919
+
1920
+ end
1921
+
1922
+ alias to_summary to_s
1923
+
1924
+ end
1925
+
1778
1926
  # MacroDroid Specific
1779
1927
  #
1780
- class SetVariableAction < Action
1928
+ class SetVariableAction < MacroDroidAction
1781
1929
  using ColouredText
1782
1930
 
1783
1931
  def initialize(obj=nil)
@@ -1867,7 +2015,7 @@ end
1867
2015
 
1868
2016
  # MacroDroid Specific
1869
2017
  #
1870
- class TextManipulationAction < Action
2018
+ class TextManipulationAction < MacroDroidAction
1871
2019
 
1872
2020
  def initialize(h={})
1873
2021
 
@@ -1910,7 +2058,7 @@ end
1910
2058
 
1911
2059
 
1912
2060
 
1913
- class PauseAction < Action
2061
+ class PauseAction < MacroDroidAction
1914
2062
 
1915
2063
  def initialize(h={})
1916
2064
 
@@ -1950,6 +2098,62 @@ end
1950
2098
 
1951
2099
  # Category: Media
1952
2100
  #
2101
+
2102
+
2103
+ # note: to find a package id from an App name, try searching for the name on
2104
+ # the Google Play Store and the id will be returned in the URL once the
2105
+ # correct app has been clicked. e.g.
2106
+ # https://play.google.com/store/apps/details?id=com.google.android.music
2107
+ #
2108
+ class ControlMediaAction < MediaAction
2109
+
2110
+ def initialize(obj=nil)
2111
+
2112
+ h = if obj.is_a? Hash then
2113
+ obj
2114
+ elsif obj.is_a? Array
2115
+
2116
+ e, macro = obj
2117
+ s = e.text('item/description').to_s
2118
+ app = s[/Simulate Media Button \(([^\)]+)/,1]
2119
+
2120
+ if app then
2121
+
2122
+ {
2123
+ application_name: app, package_name: APPS[app],
2124
+ simulate_media_button: true
2125
+ }
2126
+
2127
+ else
2128
+ {}
2129
+ end
2130
+ end
2131
+
2132
+ options = {
2133
+ application_name: "Google Play Music", option: "Play/Pause",
2134
+ package_name: "com.google.android.music",
2135
+ send_media_player_commands: false,
2136
+ simulate_media_button: true,
2137
+ }
2138
+
2139
+ super(options.merge h)
2140
+
2141
+ end
2142
+
2143
+ def to_s(colour: false, indent: 0)
2144
+
2145
+ @s = 'Media ' + @h[:option] #+ @h.inspect
2146
+
2147
+ if @h[:simulate_media_button] then
2148
+ @s += "\nSimulate Media Button (%s)" % @h[:application_name]
2149
+ end
2150
+
2151
+ super()
2152
+ end
2153
+
2154
+ alias to_summary to_s
2155
+ end
2156
+
1953
2157
  class RecordMicrophoneAction < MediaAction
1954
2158
 
1955
2159
  def initialize(h={})
@@ -90,6 +90,7 @@ class ActionsNlp
90
90
 
91
91
  # -- DEVICE ACTIONS ------------------------------------------------------
92
92
 
93
+ #
93
94
  get /^Speak text \(([^\)]+)\)/i do |text|
94
95
  [SpeakTextAction, {text: text}]
95
96
  end
@@ -100,7 +101,11 @@ class ActionsNlp
100
101
 
101
102
  get /^Speak text$/i do |text|
102
103
  [SpeakTextAction, {}]
103
- end
104
+ end
105
+
106
+ get /^UI Interaction$/i do
107
+ [UIInteractionAction, {}]
108
+ end
104
109
 
105
110
  get /^Vibrate \(([^\)]+)/i do |pattern|
106
111
  [VibrateAction, {pattern: pattern}]
@@ -123,6 +128,10 @@ class ActionsNlp
123
128
  [SetWifiAction, {state: state}]
124
129
 
125
130
  end
131
+
132
+ get /^Fill Clipboard$/i do
133
+ [ClipboardAction, {}]
134
+ end
126
135
 
127
136
  # e.g. Play: Altair
128
137
  get /^Play: (.*)$/i do |name|
@@ -134,9 +143,11 @@ class ActionsNlp
134
143
  # e.g. Launch Settings
135
144
  get /^Launch (.*)$/i do |application|
136
145
 
146
+ app = APPS[application] || 'com.android.' + application.downcase.split()\
147
+ .join('.')
137
148
  h = {
138
149
  application_name: application,
139
- package_to_launch: 'com.android.' + application.downcase
150
+ package_to_launch: app
140
151
  }
141
152
  [LaunchActivityAction, h]
142
153
 
@@ -155,6 +166,19 @@ class ActionsNlp
155
166
 
156
167
  end
157
168
 
169
+
170
+ get /^Open Website \/ HTTP GET$/i do
171
+
172
+ [OpenWebPageAction, {http_get: false}]
173
+
174
+ end
175
+
176
+ get /^(?:open|goto) ((?:https?:\/\/|\[lv=)[^$]+)$/i do |url|
177
+
178
+ [OpenWebPageAction, url_to_open: url, http_get: false]
179
+
180
+ end
181
+
158
182
  # e.g. webhook entered_kitchen
159
183
  #
160
184
  get /(?:webhook|HTTP GET) ([^$]+)$/i do |s|
@@ -221,6 +245,14 @@ class ActionsNlp
221
245
  state = %w(enable disable toggle).index(rawstate.downcase)
222
246
  [DisableMacroAction, {state: state}]
223
247
  end
248
+
249
+ get /^Macro Run$/i do
250
+ [ForceMacroRunAction, {}]
251
+ end
252
+
253
+ get /^Run Macro$/i do
254
+ [ForceMacroRunAction, {}]
255
+ end
224
256
 
225
257
  get /^Set Variable$/i do
226
258
  [SetVariableAction, {}]
@@ -230,6 +262,14 @@ class ActionsNlp
230
262
  [PauseAction, {delay_in_seconds: seconds.to_i}]
231
263
  end
232
264
 
265
+ ## -- Media -----------------------------------------
266
+ #
267
+ # options: Play/Pause, Previous, Next, Play, Pause, Stop
268
+ #
269
+ get /^Media ([^$]+)$/i do |option|
270
+ [ControlMediaAction, {option: option}]
271
+ end
272
+
233
273
  # -- Screen ------------------------------------------------
234
274
  #
235
275
  get /^Screen (On|Off)$/i do |state|
@@ -12,7 +12,7 @@ module ObjectX
12
12
 
13
13
  def action_to_object(ap, e, item, macro)
14
14
 
15
- debug = false
15
+ debug = true
16
16
 
17
17
  puts 'inside action_to_object: item.xml: ' + item.xml if debug
18
18
 
@@ -34,7 +34,8 @@ module ObjectX
34
34
  r = ap.find_action action
35
35
  puts 'r: ' + r.inspect if debug
36
36
 
37
- nested = description.element('item/description')
37
+ nested = description.element('item/*')
38
+ puts 'nested: ' + nested.inspect if debug
38
39
 
39
40
  if r[1].any? and not nested then
40
41
 
@@ -132,7 +133,8 @@ class MacroObject
132
133
  end
133
134
 
134
135
  def to_h()
135
-
136
+
137
+ @h.delete :macro
136
138
  hashify(@h)
137
139
 
138
140
  end
@@ -204,6 +206,7 @@ class MacroObject
204
206
  new_key = key.to_s.gsub(/\w_\w/){|x| x[0] + x[-1].upcase}
205
207
  new_key = new_key.prepend 'm_' unless @list.include? new_key
206
208
  new_key = 'm_SIGUID' if new_key == 'm_siguid'
209
+ new_key = 'm_SSIDList' if new_key == 'm_ssidList'
207
210
  new_val = value.is_a?(Hash) ? hashify(value) : value
208
211
  r.merge(new_key => new_val)
209
212
  end
@@ -268,7 +268,7 @@ class Macro
268
268
  r = tp.find_trigger trigger
269
269
  puts 'r: ' + r.inspect if @debug
270
270
  #o = r[0].new([description, self]) if r
271
- o = object_create(r[0], [description, self]) if r
271
+ o = object_create(r[0], [description, self, r[1]]) if r
272
272
  puts 'after o' if @debug
273
273
  o
274
274
 
@@ -356,7 +356,7 @@ class Macro
356
356
 
357
357
  end
358
358
 
359
- def match?(triggerx, detail={time: $env[:time]}, model=nil )
359
+ def match?(triggerx, detail={}, model=nil )
360
360
 
361
361
  if @triggers.any? {|x| x.type == triggerx and x.match?(detail, model) } then
362
362
 
@@ -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 WifiConnectionTrigger < Trigger
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
- 'PowerButtonToggleTrigger ' + @h.inspect
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 " + url
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(h={})
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 ' + access_point
493
+ @s = 'Connected to network'
494
+ @s += "\n" + access_point
495
+ super()
486
496
  end
487
497
 
488
- alias to_summary to_s
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 %s" % event #+ @h.inspect
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(h={})
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(h={})
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
@@ -1380,9 +1416,18 @@ class ActivityRecognitionTrigger < SensorsTrigger
1380
1416
 
1381
1417
  end
1382
1418
 
1419
+ def match?(detail={})
1420
+ @h[:selected_index] == detail[:selected_index]
1421
+ end
1422
+
1383
1423
  def to_s(colour: false)
1424
+
1384
1425
  activity = @activity[@h[:selected_index]]
1385
- 'Activity - ' + activity
1426
+ @s = 'Activity - ' + activity #+ @h.inspect
1427
+ @s += "\nConfidence >= %s%%" % @h[:confidence_level]
1428
+
1429
+ super()
1430
+
1386
1431
  end
1387
1432
 
1388
1433
  def to_summary(colour: false)
@@ -1499,6 +1544,19 @@ class FlipDeviceTrigger < SensorsTrigger
1499
1544
 
1500
1545
  end
1501
1546
 
1547
+ def match?(detail={})
1548
+
1549
+ fd = detail[:face_down]
1550
+
1551
+ b = if fd.is_a? String then
1552
+ fd.downcase == 'true'
1553
+ else
1554
+ fd
1555
+ end
1556
+
1557
+ @h[:face_down] == b
1558
+ end
1559
+
1502
1560
  def to_pc()
1503
1561
  @h[:face_down] ? 'flip_device_down?' : 'flip_device_up?'
1504
1562
  end
@@ -1577,7 +1635,7 @@ class ShortcutTrigger < Trigger
1577
1635
  end
1578
1636
 
1579
1637
  def to_s(colour: false)
1580
- 'ShortcutTrigger ' + @h.inspect
1638
+ 'Shortcut Launched' #+ @h.inspect
1581
1639
  end
1582
1640
 
1583
1641
  alias to_summary to_s
@@ -1633,8 +1691,15 @@ end
1633
1691
  #
1634
1692
  class MediaButtonPressedTrigger < Trigger
1635
1693
 
1636
- def initialize(h={})
1694
+ def initialize(obj=nil)
1637
1695
 
1696
+ h = if obj.is_a? Hash then
1697
+ obj
1698
+ elsif obj.is_a? Array
1699
+ e, macro = obj
1700
+ {option: e.text('item/description').to_s}
1701
+ end
1702
+
1638
1703
  options = {
1639
1704
  option: 'Single Press',
1640
1705
  cancel_press: false
@@ -1645,7 +1710,50 @@ class MediaButtonPressedTrigger < Trigger
1645
1710
  end
1646
1711
 
1647
1712
  def to_s(colour: false)
1648
- 'MediaButtonPressedTrigger ' + @h.inspect
1713
+
1714
+ @s = 'Media Button Pressed ' #+ @h.inspect
1715
+ @s += "\n" + @h[:option]
1716
+ super()
1717
+
1718
+ end
1719
+
1720
+ alias to_summary to_s
1721
+ end
1722
+
1723
+ class MediaButtonV2Trigger < Trigger
1724
+
1725
+ def initialize(obj=nil)
1726
+
1727
+ @a = %w(Play Play/Pause Pause Stop Previous Next Headset Hook)
1728
+
1729
+ h = if obj.is_a? Hash then
1730
+ obj
1731
+ elsif obj.is_a? Array
1732
+ e, macro = obj
1733
+ s = e.text('item/description').to_s
1734
+ a = s.split(/, /)
1735
+ {options_enabled_array: @a.map {|x| a.include? x } }
1736
+ end
1737
+
1738
+
1739
+
1740
+ options = {
1741
+ options_enabled_array: [true, false, false, false, false, false, false]
1742
+ }
1743
+
1744
+ super(options.merge h)
1745
+
1746
+ end
1747
+
1748
+ def to_s(colour: false)
1749
+
1750
+
1751
+ options = @a.zip(@h[:options_enabled_array]).select(&:last).map(&:first)
1752
+
1753
+ @s = 'Media Button V2 ' #+ @h.inspect
1754
+ @s += "\n" + options.join(', ')
1755
+ super()
1756
+
1649
1757
  end
1650
1758
 
1651
1759
  alias to_summary to_s
@@ -1655,8 +1763,22 @@ end
1655
1763
  #
1656
1764
  class SwipeTrigger < Trigger
1657
1765
 
1658
- def initialize(h={})
1659
-
1766
+ def initialize(obj=nil)
1767
+
1768
+ h = if obj.is_a? Hash then
1769
+ obj
1770
+ elsif obj.is_a? Array
1771
+
1772
+ e, macro = obj
1773
+ s = e.text('item/description').to_s
1774
+ start, motion = s.split(/ - /,2)
1775
+
1776
+ {
1777
+ swipe_start_area: ['Top Left', 'Top Right'].index(start),
1778
+ swipe_motion: %w(Across Diagonal Down).index(motion)
1779
+ }
1780
+ end
1781
+
1660
1782
  options = {
1661
1783
  swipe_start_area: 0,
1662
1784
  swipe_motion: 0,
@@ -1666,9 +1788,29 @@ class SwipeTrigger < Trigger
1666
1788
  super(options.merge h)
1667
1789
 
1668
1790
  end
1791
+
1792
+ def match?(detail={}, model=nil)
1793
+
1794
+ puts 'detail : ' + detail.inspect
1795
+
1796
+ return false if detail.empty?
1797
+
1798
+ detail[:swipe_start_area] = detail[:start]
1799
+ detail[:swipe_motion] = detail[:motion]
1800
+ return unless detail[:swipe_start_area] and detail[:swipe_motion]
1801
+
1802
+ @h[:swipe_start_area] == detail[:swipe_start_area].to_i and \
1803
+ @h[:swipe_motion] == detail[:swipe_motion].to_i
1804
+
1805
+ end
1669
1806
 
1670
1807
  def to_s(colour: false)
1671
- 'SwipeTrigger ' + @h.inspect
1808
+
1809
+ direction = [['Top Left', 'Top Right'][@h[:swipe_start_area]],
1810
+ %w(Across Diagonal Down)[@h[:swipe_motion]]].join(' - ')
1811
+ @s = 'Swipe Screen'# + @h.inspect
1812
+ @s += "\n" + direction
1813
+ super()
1672
1814
  end
1673
1815
 
1674
1816
  alias to_summary to_s
@@ -19,6 +19,10 @@ class TriggersNlp
19
19
 
20
20
  # -- Battery/Power ---------------------------------------------
21
21
 
22
+ get /Power Button Toggle \((\d)\)/i do |num|
23
+ [PowerButtonToggleTrigger, {num_toggles: num.to_i}]
24
+ end
25
+
22
26
  get /^Power Connected: (Wired \([^\)]+\))/i do |s|
23
27
 
24
28
  h = {
@@ -50,7 +54,26 @@ class TriggersNlp
50
54
  [ExternalPowerTrigger, h]
51
55
  end
52
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
+
71
+
53
72
  # -- Device Events ----------------------------------------------------
73
+
74
+ get /^NFC Tag$/i do |state|
75
+ [NFCTrigger, {}]
76
+ end
54
77
 
55
78
  get /^Screen[ _](On|Off)/i do |state|
56
79
  [ScreenOnOffTrigger, {screen_on: state.downcase == 'on'}]
@@ -132,11 +155,59 @@ class TriggersNlp
132
155
  [WebHookTrigger, params]
133
156
  end
134
157
 
135
- # MacroDroid specific ---------------------------------------------------------------
158
+ #-- MacroDroid specific ---------------------------------------------------------------
136
159
 
137
160
  get /^EmptyTrigger$/i do
138
161
  [EmptyTrigger, params]
139
- end
162
+ end
163
+
164
+ #-- Sensors ---------------------------------------------------------------
165
+
166
+ get /^Activity - (.*)$/i do |s|
167
+
168
+ a = ['In Vehicle', 'On Bicycle', 'Running', 'Walking', 'Still']
169
+ r = a.find {|x| x.downcase == s.downcase}
170
+ h = r ? {selected_index: a.index(r)} : {}
171
+ [ActivityRecognitionTrigger , h]
172
+ end
173
+
174
+ # -- User Input ---------------------------------------------------------------
175
+
176
+ get /^Media Button Pressed$/i do
177
+ [MediaButtonPressedTrigger, {}]
178
+ end
179
+
180
+ get /^Media Button V2$/i do
181
+ [MediaButtonV2Trigger, {}]
182
+ end
183
+
184
+ get /^Shortcut Launched$/i do
185
+ [ShortcutTrigger, {}]
186
+ end
187
+
188
+ get /^Swipe Screen$/i do
189
+ [SwipeTrigger, {}]
190
+ end
191
+
192
+ get /^Swipe (top left) (across|diagonal|down)$/i do |start, motion|
193
+
194
+ swipe_motion = case motion.downcase.to_sym
195
+ when :across
196
+ 0
197
+ when :diagonal
198
+ 1
199
+ when :down
200
+ 2
201
+ end
202
+
203
+ h = {
204
+ swipe_start_area: (start.downcase == 'top left' ? 0 : 1),
205
+ swipe_motion: swipe_motion
206
+ }
207
+
208
+ [SwipeTrigger, h]
209
+
210
+ end
140
211
 
141
212
  end
142
213
 
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.11
4
+ version: 0.9.16
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-19 00:00:00.000000000 Z
38
+ date: 2020-10-23 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: glw
metadata.gz.sig CHANGED
Binary file