ruby-macrodroid 0.8.12 → 0.9.0

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: 35ba502f49880d0b2036510866095ff532a03311c4b503099305b943ed5dd77f
4
- data.tar.gz: c604614f382e0bdf812ca7426fc74cd5339e16b821e272b3d31c85663a5f34fe
3
+ metadata.gz: 6f4d8a484f60935d656a2ac7973ca917709201955fe55897ce27d2430cb8ec93
4
+ data.tar.gz: d886539a6623877a521969d869d8d4b5690191795ffa6710dc0df5149b123707
5
5
  SHA512:
6
- metadata.gz: c36b8205504f1e76b467fe13e3e752213a0bff61e1312f507ce30ecc79904070e3004e5f82efb3e3dae9e0c22edfe5e5c7f19c421d87119ede851ab103f5d64e
7
- data.tar.gz: ab08df04436246ea37ade91f8a3509749923c1e017fb33163b591cc72f78410f3a4dcf78715669217897032362ed0a17935d4eb8858133d766a2bb712465232e
6
+ metadata.gz: 5d6251c0656a7ff30a252bc3ef38dcdd27da42ef278f34e07d4d03d07a2d11a7bab346e39330d76d17d69dd5f8d2d6091f89a81e691b1c47d7513013781e0524
7
+ data.tar.gz: bd12b85b6ef51759358f4c7e44e5671a1f69119d156ba25806eeb287e67da4f6cd50aca09940e6b4e5c0e3b9b96475be4dde49ce7f8a01694634e764e45fe343
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -141,10 +141,10 @@ end
141
141
  class ActionsNlp
142
142
  include AppRoutes
143
143
 
144
- def initialize()
144
+ def initialize(macro=nil)
145
145
 
146
146
  super()
147
- params = {}
147
+ params = {macro: macro}
148
148
  actions(params)
149
149
 
150
150
  end
@@ -230,8 +230,20 @@ class ActionsNlp
230
230
 
231
231
  # e.g. webhook entered_kitchen
232
232
  #
233
- get /webhook|HTTP GET/i do
234
- [OpenWebPageAction, {}]
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]
235
247
  end
236
248
 
237
249
  #a: Keep Device Awake Screen On Until Disabled
@@ -367,14 +379,14 @@ class MacroDroid
367
379
  using Params
368
380
 
369
381
  attr_reader :macros, :geofences, :yaml
370
- attr_accessor :deviceid
382
+ attr_accessor :deviceid, :remote_url
371
383
 
372
384
  # note: The deviceid can only be found from an existing Webhook trigger,
373
385
  # generated from MacroDroid itself.
374
386
 
375
- def initialize(obj=nil, deviceid: nil, debug: false)
387
+ def initialize(obj=nil, deviceid: nil, remote_url: nil, debug: false)
376
388
 
377
- @deviceid, @debug = deviceid, debug
389
+ @deviceid, @remote_url, @debug = deviceid, remote_url, debug
378
390
 
379
391
  @geofences = {}
380
392
 
@@ -590,7 +602,7 @@ class MacroDroid
590
602
  # puts '@geofences: ' + @geofences.inspect if @debug
591
603
 
592
604
  m = Macro.new(geofences: @geofences.map(&:last), deviceid: @deviceid,
593
- debug: @debug )
605
+ remote_url: @remote_url, debug: @debug )
594
606
  m.import_h(macro)
595
607
  m
596
608
 
@@ -612,7 +624,7 @@ class MacroDroid
612
624
  @macros = doc.root.xpath('item').map do |node|
613
625
  puts ('geofences: ' + geofences.inspect).highlight if @debug
614
626
  Macro.new(geofences: geofences.map(&:last), deviceid: @deviceid,
615
- debug: @debug).import_xml(node)
627
+ remote_url: @remote_url, debug: @debug).import_xml(node)
616
628
 
617
629
  end
618
630
 
@@ -835,65 +847,6 @@ class DroidSim
835
847
 
836
848
  end
837
849
 
838
- RD_MACROS =<<EOF
839
- m: Torch
840
- t: webhook
841
- a: Torch toggle
842
- EOF
843
-
844
- module RemoteDroid
845
-
846
- class Service
847
- def initialize(callback)
848
- @callback = callback
849
- end
850
- end
851
-
852
- class Bluetooth
853
- def enable()
854
- end
855
- end
856
-
857
- class Torch < Service
858
-
859
- def toggle()
860
- @callback.call :torch
861
- end
862
-
863
- end
864
-
865
- class Control
866
-
867
- def initialize(deviceid: nil)
868
- @deviceid = deviceid
869
- @torch = Torch.new(self)
870
- end
871
-
872
- def bluetooth()
873
- @bluetooth
874
- end
875
-
876
- def call(command)
877
- url = "https://trigger.macrodroid.com/%s/%s" % [@deviceid, command]
878
- puts 'url: ' + url.inspect
879
- s = open(url).read
880
- end
881
-
882
- def torch()
883
- @torch
884
- end
885
-
886
- def write(s)
887
-
888
- MacroDroid.new(RD_MACROS, deviceid: @deviceid).export s
889
-
890
- end
891
-
892
- alias export write
893
-
894
- end
895
-
896
- end
897
850
 
898
851
  require 'ruby-macrodroid/base'
899
852
  require 'ruby-macrodroid/triggers'
@@ -49,8 +49,8 @@ class Action < MacroObject
49
49
 
50
50
  end
51
51
 
52
- def invoke(s='')
53
- "%s/%s: %s" % [@group, @type, s]
52
+ def invoke(h={})
53
+ "%s/%s: %s" % [@group, @type, h.to_json]
54
54
  end
55
55
 
56
56
 
@@ -136,23 +136,46 @@ class LaunchShortcutAction < ApplicationAction
136
136
 
137
137
  end
138
138
 
139
+ class OpenWebPageActionError < Exception
140
+ end
141
+
139
142
  # Category: Applications
140
143
  #
141
144
  class OpenWebPageAction < ApplicationAction
142
145
 
143
- def initialize(h={})
146
+ def initialize(obj={})
147
+
148
+ h = if obj.is_a? Hash then
149
+ obj
150
+ elsif obj.is_a? Array
151
+ e, macro = obj
152
+ txt = e.text('item/description')
153
+ {url: (txt || e.text)}
154
+ end
144
155
 
145
156
  h[:url_to_open] = h[:url] if h[:url]
146
157
 
147
158
  options = {
148
- variable_to_save_response: {:m_stringValue=>"", :m_name=>"", :m_decimalValue=>0.0, :isLocal=>true, :m_booleanValue=>false, :excludeFromLog=>false, :m_intValue=>0, :m_type=>2},
159
+ variable_to_save_response: {:m_stringValue=>"", :m_name=>"",
160
+ m_decimalValue: 0.0, isLocal: true, m_booleanValue: false,
161
+ excludeFromLog: false, m_intValue: 0, m_type: 2},
149
162
  url_to_open: '',
150
163
  http_get: true,
151
164
  disable_url_encode: false,
152
165
  block_next_action: false
153
166
  }
154
-
155
- super(options.merge filter(options,h))
167
+
168
+ if h[:macro].remote_url.nil? then
169
+ raise OpenWebPageActionError, 'remote_url not found'
170
+ end
171
+
172
+ if (h[:identifier].nil? or h[:identifier].empty?) and
173
+ (h[:url_to_open].nil? or h[:url_to_open].empty?) then
174
+ h[:url_to_open] = h[:macro].remote_url.sub(/\/$/,'') + '/' +
175
+ h[:macro].title.downcase.gsub(/ +/,'-')
176
+ end
177
+
178
+ super(options.merge h)
156
179
 
157
180
  end
158
181
 
@@ -1971,11 +1994,10 @@ class ToastAction < NotificationsAction
1971
1994
 
1972
1995
  h = if obj.is_a? Hash then
1973
1996
  obj
1974
- elsif obj.is_a? Rexle::Element
1975
- txt = obj.text('item/description')
1976
- {msg: (txt || obj.text)}
1977
- else
1978
- {msg: obj}
1997
+ elsif obj.is_a? Array
1998
+ e, macro = obj
1999
+ txt = e.text('item/description')
2000
+ {msg: (txt || e.text)}
1979
2001
  end
1980
2002
 
1981
2003
  if h[:msg] then
@@ -1999,7 +2021,7 @@ class ToastAction < NotificationsAction
1999
2021
  end
2000
2022
 
2001
2023
  def invoke()
2002
- super(@h[:message_text])
2024
+ super(msg: @h[:message_text])
2003
2025
  end
2004
2026
 
2005
2027
  def to_pc()
@@ -24,11 +24,13 @@ class Macro
24
24
 
25
25
  attr_reader :local_variables, :triggers, :actions, :constraints,
26
26
  :guid, :deviceid
27
- attr_accessor :title, :description
27
+ attr_accessor :title, :description, :remote_url
28
28
 
29
- def initialize(name=nil, geofences: nil, deviceid: nil, debug: false)
29
+ def initialize(name=nil, geofences: nil, deviceid: nil, remote_url: nil,
30
+ debug: false)
30
31
 
31
32
  @title, @geofences, @deviceid, @debug = name, geofences, deviceid, debug
33
+ @remote_url = remote_url
32
34
 
33
35
  puts 'inside Macro#initialize' if @debug
34
36
 
@@ -195,30 +197,89 @@ class Macro
195
197
  @title = node.text('macro') || node.attributes[:name]
196
198
 
197
199
  @local_variables = node.xpath('variable').map do |e|
198
- e.text.split(/: +/,2)
200
+
201
+ label, v = e.text.to_s.split(/: */,2)
202
+
203
+ value = if v.to_f.to_s == v
204
+ v.to_f
205
+ elsif v.downcase == 'true'
206
+ true
207
+ elsif v.downcase == 'false'
208
+ false
209
+ elsif v.to_i.to_s == v
210
+ v.to_i
211
+ else
212
+ v
213
+ end
214
+
215
+ [label, value]
199
216
  end
200
217
 
201
218
  #@description = node.attributes[:description]
202
219
 
203
220
  tp = TriggersNlp.new(self)
204
221
 
205
- @triggers = node.xpath('trigger').map do |e|
222
+ @triggers = node.xpath('trigger').flat_map do |e|
206
223
 
207
224
  r = tp.find_trigger e.text
208
225
 
209
226
  puts 'found trigger ' + r.inspect if @debug
210
227
 
211
- if r then
212
- if r[0] == GeofenceTrigger then
213
- GeofenceTrigger.new(r[1], geofences: @geofences)
228
+ item = e.element('item')
229
+ if item then
230
+
231
+ if item.element('description') then
232
+
233
+ item.xpath('description').map do |description|
234
+
235
+ inner_lines = description.text.to_s.strip.lines
236
+ puts 'inner_lines: ' + inner_lines.inspect if @debug
237
+
238
+ trigger = if e.text.to_s.strip.empty? then
239
+ inner_lines.shift.strip
240
+ else
241
+ e.text.strip
242
+ end
243
+
244
+ puts 'trigger: ' + trigger.inspect if @debug
245
+
246
+ r = tp.find_trigger trigger
247
+ puts 'r: ' + r.inspect if @debug
248
+ o = r[0].new([description, self]) if r
249
+ puts 'after o' if @debug
250
+ o
251
+
252
+ end
253
+
214
254
  else
215
- r[0].new(r[1])
255
+
256
+ trigger = e.text.strip
257
+ r = tp.find_trigger trigger
258
+
259
+ a = e.xpath('item/*')
260
+
261
+ h = if a.any? then
262
+ a.map {|node| [node.name.to_sym, node.text.to_s]}.to_h
263
+ else
264
+ {}
265
+ end
266
+
267
+ r = tp.find_trigger trigger
268
+ r[0].new(h) if r
269
+
216
270
  end
271
+
272
+ else
273
+
274
+ trigger = e.text.strip
275
+ r = tp.find_trigger trigger
276
+ r[0].new(r[1]) if r
277
+
217
278
  end
218
279
 
219
280
  end
220
281
 
221
- ap = ActionsNlp.new
282
+ ap = ActionsNlp.new self
222
283
 
223
284
  @actions = node.xpath('action').flat_map do |e|
224
285
 
@@ -245,8 +306,8 @@ class Macro
245
306
 
246
307
  r = ap.find_action action
247
308
  puts 'r: ' + r.inspect if @debug
248
- o = r[0].new(description) if r
249
- puts 'after o'
309
+ o = r[0].new([description, self]) if r
310
+ puts 'after o' if @debug
250
311
  o
251
312
 
252
313
  end
@@ -378,13 +439,20 @@ EOF
378
439
  puts 'before triggers' if @debug
379
440
 
380
441
  a << @triggers.map do |x|
442
+
443
+ puts 'x: ' + x.inspect if @debug
444
+
381
445
  s =-x.to_s(colour: colour)
446
+ puts 's: ' + s.inspect if @debug
382
447
 
383
448
  s2 = if s.lines.length > 1 then
384
449
  "\n" + s.lines.map {|x| x.prepend (' ' * (indent+1)) }.join
385
450
  else
386
451
  ' ' + s
387
452
  end
453
+
454
+ puts 's2: ' + s2.inspect if @debug
455
+
388
456
  #s.lines > 1 ? "\n" + x : x
389
457
  (colour ? "t".bg_red.gray.bold : 't') + ":" + s2
390
458
  end.join("\n")
@@ -540,10 +608,11 @@ EOF
540
608
 
541
609
 
542
610
  local_variables.map do |key, value|
543
-
544
-
611
+
612
+ puts 'value ' + value.class.to_s.to_sym.inspect
613
+ puts 'VAR_TYPES: ' + VAR_TYPES.inspect
545
614
  type = VAR_TYPES[value.class.to_s.to_sym]
546
-
615
+ puts 'type: ' + type.inspect
547
616
  h = {
548
617
  boolean_value: false,
549
618
  decimal_value: 0.0,
@@ -416,19 +416,33 @@ end
416
416
  #
417
417
  class WebHookTrigger < Trigger
418
418
 
419
- def initialize(h={})
419
+ def initialize(obj={})
420
+
421
+ h = if obj.is_a? Hash then
422
+ obj
423
+ elsif obj.is_a? Array
424
+ e, macro = obj
425
+ txt = e.text('item/description')
426
+ {url: (txt || e.text), macro: macro}
427
+ end
428
+
429
+ if h[:url] then
430
+ h[:identifier] = h[:url][/https:\/\/trigger.macrodroid.com\/(?:\w+\-){4}\w+\/([^$]+)/,1]
431
+ end
432
+
420
433
 
421
434
  options = {
422
435
  identifier: ''
423
436
  }
437
+
424
438
  @deviceid = h[:macro].deviceid
425
439
 
426
440
 
427
441
  if h[:identifier].nil? or h[:identifier].empty? then
428
- h[:identifier] = h[:macro].title.downcase
442
+ h[:identifier] = h[:macro].title.downcase.gsub(/ +/,'-')
429
443
  end
430
444
 
431
- super(options.merge h)
445
+ super(options.merge filter(options,h))
432
446
  @list << 'identifier'
433
447
 
434
448
  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.8.12
4
+ version: 0.9.0
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-09-30 00:00:00.000000000 Z
38
+ date: 2020-10-02 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: glw
@@ -81,22 +81,22 @@ dependencies:
81
81
  name: rowx
82
82
  requirement: !ruby/object:Gem::Requirement
83
83
  requirements:
84
- - - ">="
85
- - !ruby/object:Gem::Version
86
- version: 0.7.0
87
84
  - - "~>"
88
85
  - !ruby/object:Gem::Version
89
86
  version: '0.7'
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: 0.7.3
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
95
- - !ruby/object:Gem::Version
96
- version: 0.7.0
97
94
  - - "~>"
98
95
  - !ruby/object:Gem::Version
99
96
  version: '0.7'
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 0.7.3
100
100
  - !ruby/object:Gem::Dependency
101
101
  name: subunit
102
102
  requirement: !ruby/object:Gem::Requirement
@@ -146,7 +146,7 @@ dependencies:
146
146
  version: '1.1'
147
147
  - - ">="
148
148
  - !ruby/object:Gem::Version
149
- version: 1.1.1
149
+ version: 1.1.3
150
150
  type: :runtime
151
151
  prerelease: false
152
152
  version_requirements: !ruby/object:Gem::Requirement
@@ -156,7 +156,7 @@ dependencies:
156
156
  version: '1.1'
157
157
  - - ">="
158
158
  - !ruby/object:Gem::Version
159
- version: 1.1.1
159
+ version: 1.1.3
160
160
  - !ruby/object:Gem::Dependency
161
161
  name: chronic_cron
162
162
  requirement: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file