ruby-macrodroid 0.9.0 → 0.9.1

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: 6f4d8a484f60935d656a2ac7973ca917709201955fe55897ce27d2430cb8ec93
4
- data.tar.gz: d886539a6623877a521969d869d8d4b5690191795ffa6710dc0df5149b123707
3
+ metadata.gz: 37e8014bb2ccd71ffd2da90197a1dd1a89c7e8e6bbbfc7ed88e9cfbff07925a1
4
+ data.tar.gz: f2d4910bb6893249e33eb7c4326ea733188ecef67ec94f808cd25ef6c97760d0
5
5
  SHA512:
6
- metadata.gz: 5d6251c0656a7ff30a252bc3ef38dcdd27da42ef278f34e07d4d03d07a2d11a7bab346e39330d76d17d69dd5f8d2d6091f89a81e691b1c47d7513013781e0524
7
- data.tar.gz: bd12b85b6ef51759358f4c7e44e5671a1f69119d156ba25806eeb287e67da4f6cd50aca09940e6b4e5c0e3b9b96475be4dde49ce7f8a01694634e764e45fe343
6
+ metadata.gz: 06015fe764a0450838ad49b6dbebba46afc32ec49673dbf4e1bce9b07e04aaea1850153cf2c0b1d56e740dd2cbcf4653f92878ee99680d7c3f2eaacf1fffb69e
7
+ data.tar.gz: df0c2950bcae690d137b294825c95579f8530fea24cabfe371809efff64343d4e9ffd71b5f2378c7938bc214dfc0e409892947ad03a86ef4438816fafa11000a
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -44,275 +44,6 @@ device
44
44
  airplane_mode is disabled
45
45
  EOF
46
46
 
47
- class TriggersNlp
48
- include AppRoutes
49
-
50
- def initialize(macro=nil)
51
-
52
- super()
53
- params = {macro: macro}
54
- triggers(params)
55
-
56
- end
57
-
58
- def triggers(params)
59
-
60
- # e.g. at 7:30pm daily
61
- get /^(?:at )?(\d+:\d+(?:[ap]m)?) daily/i do |time, days|
62
- [TimerTrigger, {time: time,
63
- days: %w(Mon Tue Wed Thu Fri Sat Sun).join(', ')}]
64
- end
65
-
66
- get /^(?:at )?(\d+:\d+(?:[ap]m)?) (?:on )?(.*)/i do |time, days|
67
- [TimerTrigger, {time: time, days: days}]
68
- end
69
-
70
- # time.is? 'at 18:30pm on Mon or Tue'
71
- get /^time.is\? ['"](?:at )?(\d+:\d+(?:[ap]m)?) (?:on )?(.*)['"]/i do |time, days|
72
- [TimerTrigger, {time: time, days: days.gsub(' or ',', ')}]
73
- end
74
-
75
- get /^shake[ _]device\??$/i do
76
- [ShakeDeviceTrigger, {}]
77
- end
78
-
79
- get /^Flip Device (.*)$/i do |motion|
80
- facedown = motion =~ /Face Up (?:->|to) Face Down/i
81
- [FlipDeviceTrigger, {face_down: facedown }]
82
- end
83
-
84
- get /^flip_device_down\?$/i do
85
- [FlipDeviceTrigger, {face_down: true }]
86
- end
87
-
88
- get /^flip_device_up\?$/i do
89
- [FlipDeviceTrigger, {face_down: false }]
90
- end
91
-
92
- get /^Failed Login Attempt$/i do
93
- [FailedLoginTrigger, {}]
94
- end
95
-
96
- get /^failed_login?$/i do
97
- [FailedLoginTrigger, {}]
98
- end
99
-
100
- get /^Geofence (Entry|Exit) \(([^\)]+)/i do |direction, name|
101
- enter_area = direction.downcase.to_sym == :entry
102
- [GeofenceTrigger, {name: name, enter_area: enter_area}]
103
- end
104
-
105
- get /^location (entered|exited) \(([^\)]+)/i do |direction, name|
106
- enter_area = direction.downcase.to_sym == :entered
107
- [GeofenceTrigger, {name: name, enter_area: enter_area}]
108
- end
109
-
110
- # eg. Proximity Sensor (Near)
111
- #
112
- get /^Proximity Sensor \(([^\)]+)\)/i do |distance|
113
-
114
- [ProximityTrigger, {distance: distance}]
115
- end
116
-
117
- get /^WebHook \(Url\)/i do
118
- [WebHookTrigger, params]
119
- end
120
-
121
- get /^WebHook/i do
122
- [WebHookTrigger, params]
123
- end
124
-
125
- get /^wh/i do
126
- [WebHookTrigger, params]
127
- end
128
-
129
-
130
- end
131
-
132
- alias find_trigger run_route
133
-
134
- def to_s(colour: false)
135
- 'TriggersNlp ' + @h.inspect
136
- end
137
-
138
- alias to_summary to_s
139
- end
140
-
141
- class ActionsNlp
142
- include AppRoutes
143
-
144
- def initialize(macro=nil)
145
-
146
- super()
147
- params = {macro: macro}
148
- actions(params)
149
-
150
- end
151
-
152
- def actions(params)
153
-
154
- # e.g. message popup: hello world!
155
- get /^message popup: (.*)/i do |msg|
156
- [ToastAction, {msg: msg}]
157
- end
158
-
159
- # e.g. Popup Message 'hello world!'
160
- get /^Popup[ _]Message ['"]([^'"]+)/i do |msg|
161
- [ToastAction, {msg: msg}]
162
- end
163
-
164
- # e.g. Popup Message\n hello world!
165
- get /^Popup Message\n\s+(.*)/im do |msg|
166
- [ToastAction, {msg: msg}]
167
- end
168
-
169
- # e.g. Popup Message
170
- get /^Popup Message$/i do
171
- [ToastAction, {}]
172
- end
173
-
174
- # e.g. say current time
175
- get /^say current[ _]time/i do
176
- [SayTimeAction, {}]
177
- end
178
-
179
- get /^Torch :?(.*)/i do |onoffstate|
180
- state = %w(on off toggle).index onoffstate.downcase
181
- [CameraFlashLightAction, {state: state}]
182
- end
183
-
184
- get /^Take Picture/i do
185
- [TakePictureAction, {}]
186
- end
187
-
188
- get /^take_picture/i do
189
- [TakePictureAction, {}]
190
- end
191
-
192
- # e.g. Display Notification: Hi there: This is the body of the message
193
- get /^Display Notification: ([^:]+): [^$]+$/i do |subject, text|
194
- [NotificationAction, {subject: subject, text: text}]
195
- end
196
-
197
-
198
- # e.g. Enable Wifi
199
- get /^(Enable|Disable) Wifi$/i do |raw_state|
200
-
201
- state = raw_state.downcase.to_sym == :enable ? 0 : 1
202
- [SetWifiAction, {state: state}]
203
-
204
- end
205
-
206
- # e.g. Play: Altair
207
- get /^Play: (.*)$/i do |name|
208
-
209
- [PlaySoundAction, {file_path: name}]
210
-
211
- end
212
-
213
- # e.g. Launch Settings
214
- get /^Launch (.*)$/i do |application|
215
-
216
- h = {
217
- application_name: application,
218
- package_to_launch: 'com.android.' + application.downcase
219
- }
220
- [LaunchActivityAction, h]
221
-
222
- end
223
-
224
- # e.g. HTTP GET http://someurl.com/something
225
- get /^HTTP GET ([^$]+)$/i do |url|
226
-
227
- [OpenWebPageAction, url_to_open: url]
228
-
229
- end
230
-
231
- # e.g. webhook entered_kitchen
232
- #
233
- get /(?:webhook|HTTP GET) ([^$]+)$/i do |s|
234
- key = s =~ /^http/ ? :url_to_open : :identifier
235
- [OpenWebPageAction, {key => s}]
236
- end
237
-
238
- #
239
- get /^WebHook \(Url\)/i do
240
- [OpenWebPageAction, params]
241
- end
242
-
243
- # e.g. webhook entered_kitchen
244
- #
245
- get /^webhook$/i do
246
- [OpenWebPageAction, params]
247
- end
248
-
249
- #a: Keep Device Awake Screen On Until Disabled
250
- #
251
- get /Keep Device Awake Screen On Until Disabled/i do
252
- [KeepAwakeAction, {enabled: true, permanent: true, screen_option: 0}]
253
- end
254
-
255
-
256
- #a: Keep Device Awake Screen On 1h 1m 1s
257
- #
258
- get /Keep Device Awake Screen On ([^$]+)/i do |duration|
259
-
260
- a = duration.split.map(&:to_i)
261
- secs = Subunit.new(units={minutes:60, hours:60, seconds: 60}, a).to_i
262
-
263
- h = {
264
- permanent: true, screen_option: 0, seconds_to_stay_awake_for: secs
265
- }
266
- [KeepAwakeAction, h]
267
- end
268
-
269
- #a: Disable Keep Awake
270
- #
271
- get /Disable Keep Awake/i do
272
- [KeepAwakeAction, {enabled: false, screen_option: 0}]
273
- end
274
-
275
- #e.g a: if Airplane mode enabled
276
- #
277
- get /if (.*)/i do
278
- [IfConditionAction, {}]
279
- end
280
-
281
- get /End If/i do
282
- [EndIfAction, {}]
283
- end
284
-
285
- end
286
-
287
- alias find_action run_route
288
-
289
-
290
- end
291
-
292
- class ConstraintsNlp
293
- include AppRoutes
294
-
295
- def initialize()
296
-
297
- super()
298
- params = {}
299
- constraints(params)
300
-
301
- end
302
-
303
- def constraints(params)
304
-
305
- get /^airplane mode (.*)/i do |state|
306
- [AirplaneModeConstraint, {enabled: (state =~ /^enabled|on$/i) == 0}]
307
- end
308
-
309
- end
310
-
311
- alias find_constraint run_route
312
-
313
- end
314
-
315
-
316
47
  module Params
317
48
 
318
49
  refine Hash do
@@ -368,8 +99,6 @@ end
368
99
 
369
100
 
370
101
 
371
-
372
-
373
102
  class MacroDroidError < Exception
374
103
  end
375
104
 
@@ -143,17 +143,32 @@ end
143
143
  #
144
144
  class OpenWebPageAction < ApplicationAction
145
145
 
146
- def initialize(obj={})
146
+ def initialize(obj={}, macro=nil)
147
147
 
148
148
  h = if obj.is_a? Hash then
149
+
149
150
  obj
151
+
150
152
  elsif obj.is_a? Array
153
+ puts 'obj: ' + obj.inspect if @debug
151
154
  e, macro = obj
152
- txt = e.text('item/description')
153
- {url: (txt || e.text)}
154
- end
155
+
156
+ a = e.xpath('item/*')
157
+
158
+ h2 = if a.any? then
159
+ a.map {|node| [node.name.to_sym, node.text.to_s]}.to_h
160
+ else
161
+ txt = e.text('item/description')
162
+ {url: (txt || e.text)}
163
+ end
164
+
165
+ h2.merge(macro: macro)
166
+
167
+ end
168
+
169
+ puts 'h:' + h.inspect if @debug
155
170
 
156
- h[:url_to_open] = h[:url] if h[:url]
171
+ h[:url_to_open] = h[:url] if h[:url] and h[:url].length > 1
157
172
 
158
173
  options = {
159
174
  variable_to_save_response: {:m_stringValue=>"", :m_name=>"",
@@ -165,20 +180,35 @@ class OpenWebPageAction < ApplicationAction
165
180
  block_next_action: false
166
181
  }
167
182
 
168
- if h[:macro].remote_url.nil? then
183
+ if h[:macro].remote_url.nil? and (h[:url_to_open].nil? or
184
+ h[:url_to_open].empty?) then
169
185
  raise OpenWebPageActionError, 'remote_url not found'
170
186
  end
171
187
 
172
188
  if (h[:identifier].nil? or h[:identifier].empty?) and
173
189
  (h[:url_to_open].nil? or h[:url_to_open].empty?) then
190
+
174
191
  h[:url_to_open] = h[:macro].remote_url.sub(/\/$/,'') + '/' +
175
192
  h[:macro].title.downcase.gsub(/ +/,'-')
176
- end
193
+
194
+ elsif h2 and h[:macro].remote_url and h[:identifier]
195
+
196
+ url = "%s/%s" % [h[:macro].remote_url.sub(/\/$/,''), h[:identifier]]
197
+ h2.delete :identifier
198
+ url += '?' + \
199
+ URI.escape(h2.map {|key,value| "%s=%s" % [key, value]}.join('&'))
200
+ h[:url_to_open] = url
201
+
202
+ end
177
203
 
178
204
  super(options.merge h)
179
205
 
180
206
  end
181
207
 
208
+ def invoke()
209
+ super(url: @h[:url_to_open])
210
+ end
211
+
182
212
  def to_s(colour: false, indent: 0)
183
213
  @s = "HTTP GET\nurl: " + @h[:url_to_open]
184
214
  super()
@@ -355,9 +385,10 @@ class IfConditionAction < Action
355
385
  h2 = options.merge(filter(options,h).merge(macro: macro))
356
386
  super(h2)
357
387
 
358
- elsif obj.is_a? Rexle::Element
388
+ elsif obj.is_a? Array
389
+ e, macro = obj
359
390
  super()
360
- raw_txt = obj.text('item/description') || obj.text.to_s
391
+ raw_txt = e.text('item/description') || e.text.to_s
361
392
  puts 'raw_txt: ' + raw_txt.inspect if $debug
362
393
 
363
394
  clause = raw_txt[/^if (.*)/i,1]
@@ -391,7 +422,7 @@ class IfConditionAction < Action
391
422
  def to_s(colour: false, indent: 0)
392
423
 
393
424
  h = @h.clone
394
- h.delete :macro
425
+ #h.delete :macro
395
426
  @s = 'If '
396
427
  operator = @h[:is_or_condition] ? 'OR' : 'AND'
397
428
  constraints = @constraints.map \
@@ -471,6 +502,8 @@ class EndIfAction < Action
471
502
  obj
472
503
  elsif obj.is_a? Rexle::Element
473
504
  {}
505
+ else
506
+ {}
474
507
  end
475
508
 
476
509
 
@@ -478,7 +511,7 @@ class EndIfAction < Action
478
511
  constraint_list: []
479
512
  }
480
513
 
481
- super(options.merge h)
514
+ super()
482
515
 
483
516
  end
484
517
 
@@ -723,9 +756,10 @@ class SayTimeAction < DateTimeAction
723
756
  end
724
757
 
725
758
  def invoke()
726
- time = ($env and $env[:time]) ? $env[:time] : Time.now
759
+ #time = ($env and $env[:time]) ? $env[:time] : Time.now
760
+ time = Time.now
727
761
  tformat = @h['12_hour'] ? "%-I:%M%P" : "%H:%M"
728
- super(time.strftime(tformat))
762
+ super(txt: time.strftime(tformat))
729
763
  end
730
764
 
731
765
  def to_pc()
@@ -814,10 +848,18 @@ end
814
848
  #
815
849
  class SpeakTextAction < DeviceAction
816
850
 
817
- def initialize(h={})
818
-
851
+ def initialize(obj=nil)
852
+
853
+ h = if obj.is_a? Hash then
854
+ obj
855
+ elsif obj.is_a? Array
856
+ e, macro = obj
857
+ txt = e.text('item/description')
858
+ {text: (txt || e.text)}
859
+ end
860
+
819
861
  options = {
820
- text_to_say: '',
862
+ text_to_say: h[:text] || '',
821
863
  queue: false,
822
864
  read_numbers_individually: false,
823
865
  specify_audio_stream: false,
@@ -831,8 +873,13 @@ class SpeakTextAction < DeviceAction
831
873
 
832
874
  end
833
875
 
876
+ def invoke()
877
+ super(text: @h[:text_to_say])
878
+ end
879
+
834
880
  def to_s(colour: false, indent: 0)
835
- "Speak Text (%s)" % @h[:text_to_say]
881
+ @s = "Speak Text (%s)" % @h[:text_to_say]
882
+ super()
836
883
  end
837
884
 
838
885
  end
@@ -984,6 +1031,9 @@ class CameraFlashLightAction < DeviceSettingsAction
984
1031
  super(options.merge h)
985
1032
 
986
1033
  end
1034
+ def invoke()
1035
+ super(state: @h[:state])
1036
+ end
987
1037
 
988
1038
  def to_pc()
989
1039
  ['torch :on', 'torch :off', 'torch :toggle'][@h[:state]]
@@ -1393,8 +1393,21 @@ end
1393
1393
  #
1394
1394
  class ProximityTrigger < SensorsTrigger
1395
1395
 
1396
- def initialize(h={})
1396
+ def initialize(obj=nil)
1397
1397
 
1398
+ h = if obj.is_a? Hash then
1399
+ obj
1400
+ elsif obj.is_a? Array
1401
+ e, macro = obj
1402
+ txt = e.text('item/description')
1403
+ {option: (txt || e.text), macro: macro}
1404
+ end
1405
+
1406
+ options = {
1407
+ near: true,
1408
+ selected_option: 0
1409
+ }
1410
+
1398
1411
  if h[:distance] then
1399
1412
 
1400
1413
  case h[:distance].to_sym
@@ -1403,15 +1416,14 @@ class ProximityTrigger < SensorsTrigger
1403
1416
  end
1404
1417
  end
1405
1418
 
1406
- options = {
1407
- near: true,
1408
- selected_option: 0
1409
- }
1410
-
1411
1419
  super(options.merge h)
1412
1420
 
1413
1421
  end
1414
1422
 
1423
+ def match?(detail={}, model=nil)
1424
+ @h[:selected_option] == detail[:option].to_i
1425
+ end
1426
+
1415
1427
  def to_s(colour: false)
1416
1428
 
1417
1429
  distance = if @h[:near] then
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.0
4
+ version: 0.9.1
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-02 00:00:00.000000000 Z
38
+ date: 2020-10-03 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: glw
metadata.gz.sig CHANGED
Binary file