ruby-macrodroid 0.8.10 → 0.8.11
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 +98 -13
- data/lib/ruby-macrodroid/actions.rb +49 -16
- data/lib/ruby-macrodroid/macro.rb +51 -4
- data/lib/ruby-macrodroid/triggers.rb +8 -1
- metadata +2 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 378a54305a1bfcce6433d130a154765550e7c19f547e19897fffe48c4ee5abf2
|
4
|
+
data.tar.gz: dc2374f5fe37dbf9e011a62272874b6e6b80be87c5dcb6479a253d033a0f3b26
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52222f8794ae92cdae799a5309dcb387c8e6e587a9d36fbbc429f636730c57610f4b9e20f9cf65f60989a843aaa1cfa96696954142dc98bb0c162bd737cb49cb
|
7
|
+
data.tar.gz: 9db28bc4773d3e8daff58a75244b1506a2885fd70da22136e10baa4c5f9d008a37e45538320c2ad4831412857aa4fd68a50d13dd6a9f4518744d700cc5521d1b
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/ruby-macrodroid.rb
CHANGED
@@ -47,10 +47,10 @@ EOF
|
|
47
47
|
class TriggersNlp
|
48
48
|
include AppRoutes
|
49
49
|
|
50
|
-
def initialize()
|
50
|
+
def initialize(macro=nil)
|
51
51
|
|
52
52
|
super()
|
53
|
-
params = {}
|
53
|
+
params = {macro: macro}
|
54
54
|
triggers(params)
|
55
55
|
|
56
56
|
end
|
@@ -113,7 +113,18 @@ class TriggersNlp
|
|
113
113
|
|
114
114
|
[ProximityTrigger, {distance: distance}]
|
115
115
|
end
|
116
|
+
|
117
|
+
get /^WebHook \(Url\)/i do
|
118
|
+
[WebHookTrigger, params]
|
119
|
+
end
|
116
120
|
|
121
|
+
get /^WebHook/i do
|
122
|
+
[WebHookTrigger, params]
|
123
|
+
end
|
124
|
+
|
125
|
+
get /^wh/i do
|
126
|
+
[WebHookTrigger, params]
|
127
|
+
end
|
117
128
|
|
118
129
|
|
119
130
|
end
|
@@ -166,7 +177,7 @@ class ActionsNlp
|
|
166
177
|
end
|
167
178
|
|
168
179
|
get /^Torch :?(.*)/i do |onoffstate|
|
169
|
-
state =
|
180
|
+
state = %w(on off toggle).index onoffstate.downcase
|
170
181
|
[CameraFlashLightAction, {state: state}]
|
171
182
|
end
|
172
183
|
|
@@ -249,11 +260,15 @@ class ActionsNlp
|
|
249
260
|
[KeepAwakeAction, {enabled: false, screen_option: 0}]
|
250
261
|
end
|
251
262
|
|
252
|
-
#a:
|
263
|
+
#e.g a: if Airplane mode enabled
|
253
264
|
#
|
254
265
|
get /if (.*)/i do
|
255
266
|
[IfConditionAction, {}]
|
256
|
-
end
|
267
|
+
end
|
268
|
+
|
269
|
+
get /End If/i do
|
270
|
+
[EndIfAction, {}]
|
271
|
+
end
|
257
272
|
|
258
273
|
end
|
259
274
|
|
@@ -276,7 +291,7 @@ class ConstraintsNlp
|
|
276
291
|
def constraints(params)
|
277
292
|
|
278
293
|
get /^airplane mode (.*)/i do |state|
|
279
|
-
[AirplaneModeConstraint, {enabled: (state =~ /^enabled|on$/) == 0}]
|
294
|
+
[AirplaneModeConstraint, {enabled: (state =~ /^enabled|on$/i) == 0}]
|
280
295
|
end
|
281
296
|
|
282
297
|
end
|
@@ -347,6 +362,7 @@ class MacroDroidError < Exception
|
|
347
362
|
end
|
348
363
|
|
349
364
|
class MacroDroid
|
365
|
+
include RXFHelperModule
|
350
366
|
using ColouredText
|
351
367
|
using Params
|
352
368
|
|
@@ -387,10 +403,16 @@ class MacroDroid
|
|
387
403
|
puts 'before RowX.new' if @debug
|
388
404
|
|
389
405
|
s2 = s.gsub(/^g:/,'geofence:').gsub(/^m:/,'macro:')\
|
390
|
-
.gsub(/^
|
391
|
-
.gsub(/^c:/,'constraint:').gsub(/^#.*/,'')
|
406
|
+
.gsub(/^v:/,'variable:').gsub(/^t:/,'trigger:')\
|
407
|
+
.gsub(/^a:/,'action:').gsub(/^c:/,'constraint:').gsub(/^#.*/,'')
|
392
408
|
|
393
|
-
|
409
|
+
a = s2.split(/(?=^macro:)/)
|
410
|
+
|
411
|
+
raw_geofences = a.shift if a.first =~ /^geofence/
|
412
|
+
raw_macros = a.join
|
413
|
+
#raw_macros, raw_geofences .reverse
|
414
|
+
|
415
|
+
puts 'raw_macros: ' + raw_macros.inspect if @debug
|
394
416
|
|
395
417
|
if raw_geofences then
|
396
418
|
|
@@ -457,14 +479,16 @@ class MacroDroid
|
|
457
479
|
|
458
480
|
}
|
459
481
|
end
|
482
|
+
|
483
|
+
def export(filepath)
|
484
|
+
FileX.write filepath, to_json
|
485
|
+
end
|
460
486
|
|
461
|
-
def
|
487
|
+
def to_json()
|
462
488
|
|
463
489
|
to_h.to_json
|
464
490
|
|
465
491
|
end
|
466
|
-
|
467
|
-
alias to_json export_json
|
468
492
|
|
469
493
|
|
470
494
|
def to_h()
|
@@ -610,7 +634,7 @@ class MacroDroid
|
|
610
634
|
end
|
611
635
|
|
612
636
|
@macros = doc.root.xpath('macro').map do |node|
|
613
|
-
|
637
|
+
puts 'node: ' + node.inspect if @debug
|
614
638
|
Macro.new(geofences: @geofences.map(&:last), deviceid: @deviceid,
|
615
639
|
debug: @debug).import_xml(node)
|
616
640
|
|
@@ -811,7 +835,68 @@ class DroidSim
|
|
811
835
|
|
812
836
|
end
|
813
837
|
|
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
|
+
|
814
898
|
require 'ruby-macrodroid/base'
|
815
899
|
require 'ruby-macrodroid/triggers'
|
816
900
|
require 'ruby-macrodroid/actions'
|
817
901
|
require 'ruby-macrodroid/constraints'
|
902
|
+
require 'ruby-macrodroid/macro'
|
@@ -42,11 +42,11 @@ class Action < MacroObject
|
|
42
42
|
macro = h[:macro]
|
43
43
|
h.delete :macro
|
44
44
|
super(h)
|
45
|
-
|
46
|
-
# fetch the constraints
|
45
|
+
|
47
46
|
@constraints = @h[:constraint_list].map do |constraint|
|
48
47
|
object(constraint.to_snake_case.merge(macro: macro))
|
49
|
-
end
|
48
|
+
end
|
49
|
+
|
50
50
|
end
|
51
51
|
|
52
52
|
def invoke(s='')
|
@@ -317,25 +317,49 @@ end
|
|
317
317
|
# Conditions/Loops
|
318
318
|
#
|
319
319
|
class IfConditionAction < Action
|
320
|
-
|
320
|
+
|
321
321
|
def initialize(obj=nil)
|
322
|
+
|
323
|
+
options = {
|
324
|
+
a: true,
|
325
|
+
constraint_list: []
|
326
|
+
}
|
322
327
|
|
323
|
-
|
324
|
-
|
328
|
+
if obj.is_a? Hash then
|
329
|
+
|
330
|
+
h = obj
|
331
|
+
macro = h[:macro]
|
332
|
+
h2 = options.merge(filter(options,h).merge(macro: macro))
|
333
|
+
super(h2)
|
334
|
+
|
335
|
+
elsif obj.is_a? Rexle::Element
|
336
|
+
super()
|
337
|
+
raw_txt = obj.text('item/description') || obj.text.to_s
|
338
|
+
puts 'raw_txt: ' + raw_txt.inspect if $debug
|
339
|
+
|
340
|
+
clause = raw_txt[/^if (.*)/i,1]
|
341
|
+
conditions = clause.split(/\s+\b(?:AND|OR)\b\s+/i)
|
342
|
+
|
343
|
+
cp = ConstraintsNlp.new
|
344
|
+
|
345
|
+
@constraints = conditions.map do |c|
|
346
|
+
puts 'c: ' + c.inspect
|
347
|
+
r = cp.find_constraint c
|
348
|
+
puts 'found constraint ' + r.inspect if $debug
|
349
|
+
|
350
|
+
r[0].new(r[1]) if r
|
351
|
+
|
352
|
+
end
|
353
|
+
puts '@constraints: ' + @constraints.inspect if $debug
|
354
|
+
{}
|
325
355
|
else
|
326
356
|
# get the constraints
|
327
357
|
|
328
358
|
end
|
329
359
|
|
330
|
-
|
331
|
-
a: true,
|
332
|
-
constraint_list: ''
|
333
|
-
}
|
360
|
+
|
334
361
|
|
335
|
-
macro = h[:macro]
|
336
|
-
h2 = options.merge(filter(options,h).merge(macro: macro))
|
337
362
|
|
338
|
-
super(h2)
|
339
363
|
|
340
364
|
@label = 'If '
|
341
365
|
|
@@ -418,10 +442,17 @@ end
|
|
418
442
|
|
419
443
|
class EndIfAction < Action
|
420
444
|
|
421
|
-
def initialize(
|
422
|
-
|
445
|
+
def initialize(obj={})
|
446
|
+
|
447
|
+
h = if obj.is_a? Hash then
|
448
|
+
obj
|
449
|
+
elsif obj.is_a? Rexle::Element
|
450
|
+
{}
|
451
|
+
end
|
452
|
+
|
453
|
+
|
423
454
|
options = {
|
424
|
-
constraint_list:
|
455
|
+
constraint_list: []
|
425
456
|
}
|
426
457
|
|
427
458
|
super(options.merge h)
|
@@ -432,6 +463,8 @@ class EndIfAction < Action
|
|
432
463
|
'End If'
|
433
464
|
end
|
434
465
|
|
466
|
+
alias to_summary to_s
|
467
|
+
|
435
468
|
end
|
436
469
|
|
437
470
|
class ConnectivityAction < Action
|
@@ -7,6 +7,17 @@
|
|
7
7
|
#
|
8
8
|
# Macro
|
9
9
|
|
10
|
+
|
11
|
+
|
12
|
+
VAR_TYPES = {
|
13
|
+
String: [2, :string_value],
|
14
|
+
TrueClass: [0, :boolean_value],
|
15
|
+
TrueClass: [0, :boolean_value],
|
16
|
+
Integer: [1, :int_value],
|
17
|
+
Float: [3, :decimal_value]
|
18
|
+
}
|
19
|
+
|
20
|
+
|
10
21
|
class Macro
|
11
22
|
using ColouredText
|
12
23
|
using Params
|
@@ -50,7 +61,7 @@ class Macro
|
|
50
61
|
def to_h()
|
51
62
|
|
52
63
|
h = {
|
53
|
-
local_variables: @local_variables,
|
64
|
+
local_variables: varify(@local_variables),
|
54
65
|
m_trigger_list: @triggers.map(&:to_h),
|
55
66
|
m_action_list: @actions.map(&:to_h),
|
56
67
|
m_category: @category,
|
@@ -183,9 +194,13 @@ class Macro
|
|
183
194
|
|
184
195
|
@title = node.text('macro') || node.attributes[:name]
|
185
196
|
|
197
|
+
@local_variables = node.xpath('variable').map do |e|
|
198
|
+
e.text.split(/: +/,2)
|
199
|
+
end
|
200
|
+
|
186
201
|
#@description = node.attributes[:description]
|
187
202
|
|
188
|
-
tp = TriggersNlp.new
|
203
|
+
tp = TriggersNlp.new(self)
|
189
204
|
|
190
205
|
@triggers = node.xpath('trigger').map do |e|
|
191
206
|
|
@@ -226,8 +241,13 @@ class Macro
|
|
226
241
|
e.text.strip
|
227
242
|
end
|
228
243
|
|
244
|
+
puts 'action: ' + action.inspect if @debug
|
245
|
+
|
229
246
|
r = ap.find_action action
|
230
|
-
r
|
247
|
+
puts 'r: ' + r.inspect if @debug
|
248
|
+
o = r[0].new(description) if r
|
249
|
+
puts 'after o'
|
250
|
+
o
|
231
251
|
|
232
252
|
end
|
233
253
|
|
@@ -354,6 +374,8 @@ EOF
|
|
354
374
|
|
355
375
|
a << vars.join("\n")
|
356
376
|
end
|
377
|
+
|
378
|
+
puts 'before triggers' if @debug
|
357
379
|
|
358
380
|
a << @triggers.map do |x|
|
359
381
|
s =-x.to_s(colour: colour)
|
@@ -367,9 +389,11 @@ EOF
|
|
367
389
|
(colour ? "t".bg_red.gray.bold : 't') + ":" + s2
|
368
390
|
end.join("\n")
|
369
391
|
|
392
|
+
puts 'before actions' if @debug
|
370
393
|
actions = @actions.map do |x|
|
371
394
|
|
372
|
-
|
395
|
+
puts 'x: ' + x.inspect if @debug
|
396
|
+
raise 'Macro#to_s action cannot be nil' if x.nil?
|
373
397
|
s = x.to_s(colour: colour)
|
374
398
|
#puts 's: ' + s.inspect
|
375
399
|
|
@@ -433,6 +457,7 @@ EOF
|
|
433
457
|
a << actions
|
434
458
|
|
435
459
|
|
460
|
+
puts 'before constraints' if @debug
|
436
461
|
if @constraints.any? then
|
437
462
|
a << @constraints.map do |x|
|
438
463
|
(colour ? "c".bg_green.gray.bold : 'c') + ": %s" % x
|
@@ -510,5 +535,27 @@ EOF
|
|
510
535
|
end
|
511
536
|
|
512
537
|
end
|
538
|
+
|
539
|
+
def varify(local_variables)
|
540
|
+
|
541
|
+
|
542
|
+
local_variables.map do |key, value|
|
543
|
+
|
544
|
+
|
545
|
+
type = VAR_TYPES[value.class.to_s.to_sym]
|
546
|
+
|
547
|
+
h = {
|
548
|
+
boolean_value: false,
|
549
|
+
decimal_value: 0.0,
|
550
|
+
int_value: 0,
|
551
|
+
name: key,
|
552
|
+
string_value: '',
|
553
|
+
type: type[0]
|
554
|
+
}
|
555
|
+
h[type[1]] = value
|
556
|
+
h
|
557
|
+
end
|
558
|
+
|
559
|
+
end
|
513
560
|
|
514
561
|
end
|
@@ -421,15 +421,22 @@ class WebHookTrigger < Trigger
|
|
421
421
|
options = {
|
422
422
|
identifier: ''
|
423
423
|
}
|
424
|
+
@deviceid = h[:macro].deviceid
|
424
425
|
|
426
|
+
|
427
|
+
if h[:identifier].nil? or h[:identifier].empty? then
|
428
|
+
h[:identifier] = h[:macro].title.downcase
|
429
|
+
end
|
430
|
+
|
425
431
|
super(options.merge h)
|
432
|
+
@list << 'identifier'
|
426
433
|
|
427
434
|
end
|
428
435
|
|
429
436
|
def to_s(colour: false)
|
430
437
|
|
431
438
|
url = "https://trigger.macrodroid.com/%s/%s" % \
|
432
|
-
[@
|
439
|
+
[@deviceid, @h[:identifier]]
|
433
440
|
@s = 'WebHook (Url)' + "\n " + url
|
434
441
|
super()
|
435
442
|
|
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.
|
4
|
+
version: 0.8.11
|
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-
|
38
|
+
date: 2020-09-30 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: glw
|
metadata.gz.sig
CHANGED
Binary file
|