ruby-macrodroid 0.9.3 → 0.9.4
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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -1
- data/lib/ruby-macrodroid/actions.rb +26 -5
- data/lib/ruby-macrodroid/base.rb +88 -0
- data/lib/ruby-macrodroid/constraints.rb +24 -4
- data/lib/ruby-macrodroid/macro.rb +24 -72
- 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: 341332647c11b1d70151aab4625ffefced825585c4814eed7d7aefaf7c96703e
|
4
|
+
data.tar.gz: ac8f26a27b1f9d394174f1d887e8af27a6c551dc55d4cffa89b8fb04f6b1927d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: debe33514bbcd6cbc508c6d6a3d647cd37861bc61168743ed15cb1f1d7cf142cd883fb6059b2b7ad901659314f1dadee8f7610dbc03074f79fc3b95c8abc2f27
|
7
|
+
data.tar.gz: 50e36ff27c737d50b0686610398feae034f21a4cfab3a15b0c6367e278305a5bdc4ed6f699c0a220f0794dcf89cd3a2ec5ae0bdaf25f0d18aa49309206c03659
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
��ocA���Q��.�'�s_�����ߑ(u��:�l�������&���,�_�Y
|
@@ -34,6 +34,7 @@
|
|
34
34
|
|
35
35
|
class Action < MacroObject
|
36
36
|
using Params
|
37
|
+
include ObjectX
|
37
38
|
|
38
39
|
attr_reader :constraints
|
39
40
|
|
@@ -393,6 +394,7 @@ class IfConditionAction < Action
|
|
393
394
|
a: true,
|
394
395
|
constraint_list: []
|
395
396
|
}
|
397
|
+
puts 'obj: ' + obj.inspect #if $debug
|
396
398
|
|
397
399
|
if obj.is_a? Hash then
|
398
400
|
|
@@ -402,13 +404,18 @@ class IfConditionAction < Action
|
|
402
404
|
super(h2)
|
403
405
|
|
404
406
|
elsif obj.is_a? Array
|
407
|
+
|
405
408
|
e, macro = obj
|
406
|
-
super()
|
407
|
-
|
408
|
-
puts '
|
409
|
+
super()
|
410
|
+
puts 'e.xml: ' + e.xml
|
411
|
+
puts 'e.text: ' + e.text.to_s.strip
|
412
|
+
raw_txt = e.text.to_s.strip[/^if [^$]+/i] || e.text('item/description')
|
413
|
+
puts 'raw_txt: ' + raw_txt.inspect #if $debug
|
409
414
|
|
410
|
-
clause = raw_txt[/^
|
415
|
+
clause = raw_txt[/^If (.*)/i,1]
|
416
|
+
puts 'clause: ' + clause.inspect
|
411
417
|
conditions = clause.split(/\s+\b(?:AND|OR)\b\s+/i)
|
418
|
+
puts 'conditions: ' + conditions.inspect
|
412
419
|
|
413
420
|
cp = ConstraintsNlp.new
|
414
421
|
|
@@ -421,6 +428,19 @@ class IfConditionAction < Action
|
|
421
428
|
|
422
429
|
end
|
423
430
|
puts '@constraints: ' + @constraints.inspect if $debug
|
431
|
+
|
432
|
+
# find any nested actions
|
433
|
+
item = e.element('item')
|
434
|
+
|
435
|
+
if item then
|
436
|
+
|
437
|
+
ap = ActionsNlp.new
|
438
|
+
obj2 = action_to_object(ap, item, item, macro)
|
439
|
+
puts 'obj2: ' + obj2.inspect
|
440
|
+
#macro.add obj2
|
441
|
+
|
442
|
+
end
|
443
|
+
|
424
444
|
{}
|
425
445
|
else
|
426
446
|
# get the constraints
|
@@ -450,7 +470,8 @@ class IfConditionAction < Action
|
|
450
470
|
out << s + constraints
|
451
471
|
out.join("\n")
|
452
472
|
|
453
|
-
end
|
473
|
+
end
|
474
|
+
|
454
475
|
end
|
455
476
|
|
456
477
|
class ElseAction < Action
|
data/lib/ruby-macrodroid/base.rb
CHANGED
@@ -7,7 +7,95 @@
|
|
7
7
|
# MacroObject
|
8
8
|
#
|
9
9
|
|
10
|
+
module ObjectX
|
11
|
+
|
12
|
+
def action_to_object(ap, e, item, macro)
|
13
|
+
|
14
|
+
debug = true
|
15
|
+
|
16
|
+
puts 'inside action_to_object: item.xml: ' + item.xml if debug
|
17
|
+
|
18
|
+
if item.element('description') then
|
19
|
+
|
20
|
+
item.xpath('description').map do |description|
|
21
|
+
|
22
|
+
inner_lines = description.text.to_s.strip.lines
|
23
|
+
puts 'inner_lines: ' + inner_lines.inspect if debug
|
24
|
+
|
25
|
+
action = if e.text.to_s.strip.empty? then
|
26
|
+
inner_lines.shift.strip
|
27
|
+
else
|
28
|
+
e.text.strip
|
29
|
+
end
|
30
|
+
|
31
|
+
puts 'action: ' + action.inspect if debug
|
32
|
+
|
33
|
+
r = ap.find_action action
|
34
|
+
puts 'r: ' + r.inspect if debug
|
35
|
+
puts 'description: ' + description.xml.inspect if debug
|
36
|
+
#o = r[0].new([description, self]) if r
|
37
|
+
index = macro.actions.length
|
38
|
+
macro.add Action.new
|
39
|
+
o = object_create(r[0],[description, macro]) if r
|
40
|
+
macro.actions[index] = o
|
41
|
+
puts 'after o' if debug
|
42
|
+
o
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
else
|
47
|
+
|
48
|
+
action = e.text.strip
|
49
|
+
puts 'action: ' + action.inspect if @debug
|
50
|
+
r = ap.find_action action
|
51
|
+
|
52
|
+
a = e.xpath('item/*')
|
53
|
+
|
54
|
+
h = if a.any? then
|
55
|
+
a.map {|node| [node.name.to_sym, node.text.to_s]}.to_h
|
56
|
+
else
|
57
|
+
{}
|
58
|
+
end
|
59
|
+
puts 'h: ' + h.inspect if @debug
|
60
|
+
|
61
|
+
#r = ap.find_action action
|
62
|
+
#r[0].new(h.merge(macro: self)) if r
|
63
|
+
o = object_create(r[0], h.merge(macro: macro)) if r
|
64
|
+
macro.add o
|
65
|
+
o
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
|
70
|
+
end
|
10
71
|
|
72
|
+
def object_create(klass, *args)
|
73
|
+
|
74
|
+
begin
|
75
|
+
klass.new(*args)
|
76
|
+
rescue
|
77
|
+
raise MacroError, klass.to_s + ': ' + ($!).to_s
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def varify(label, value='')
|
82
|
+
|
83
|
+
type = VAR_TYPES[value.class.to_s.to_sym]
|
84
|
+
|
85
|
+
h = {
|
86
|
+
boolean_value: false,
|
87
|
+
decimal_value: 0.0,
|
88
|
+
int_value: 0,
|
89
|
+
name: label,
|
90
|
+
string_value: '',
|
91
|
+
type: type[0]
|
92
|
+
}
|
93
|
+
h[type[1]] = value
|
94
|
+
h
|
95
|
+
|
96
|
+
end
|
97
|
+
|
98
|
+
end
|
11
99
|
|
12
100
|
class MacroObject
|
13
101
|
using ColouredText
|
@@ -794,6 +794,13 @@ class MacroDroidVariableConstraint < Constraint
|
|
794
794
|
|
795
795
|
def initialize(h={})
|
796
796
|
|
797
|
+
if h[:loperand] then
|
798
|
+
h[:variable] = {}
|
799
|
+
h[:variable][:name] = h[:loperand]
|
800
|
+
h[:variable][:type] = 2
|
801
|
+
h[:string_value] = h[:roperand]
|
802
|
+
end
|
803
|
+
|
797
804
|
options = {
|
798
805
|
|
799
806
|
:enable_regex=>false,
|
@@ -825,11 +832,24 @@ class MacroDroidVariableConstraint < Constraint
|
|
825
832
|
|
826
833
|
def to_s(colour: false, indent: 0)
|
827
834
|
|
828
|
-
|
829
|
-
|
830
|
-
|
835
|
+
a = [:int_greater_than, :int_less_than, :int_not_equal,
|
836
|
+
:string_equal].zip(['>','<','!=', '='])
|
837
|
+
operator = a.find {|label,_| @h[label]}.last
|
838
|
+
|
839
|
+
var = @h[:variable]
|
840
|
+
|
841
|
+
type = case var[:type]
|
842
|
+
when 0 # boolean
|
843
|
+
:boolean_value
|
844
|
+
when 1 # integer
|
845
|
+
:int_value
|
846
|
+
when 2 # string
|
847
|
+
:string_value
|
848
|
+
when 3 # decimal
|
849
|
+
:decimal_Value
|
850
|
+
end
|
831
851
|
|
832
|
-
@s = "%s %s %s" % [@h[:variable][:name], operator, @h[
|
852
|
+
@s = "%s %s %s" % [@h[:variable][:name], operator, @h[type]]
|
833
853
|
super()
|
834
854
|
end
|
835
855
|
|
@@ -21,6 +21,8 @@ VAR_TYPES = {
|
|
21
21
|
Float: [3, :decimal_value]
|
22
22
|
}
|
23
23
|
|
24
|
+
|
25
|
+
|
24
26
|
class TriggersNlp
|
25
27
|
include AppRoutes
|
26
28
|
|
@@ -347,6 +349,20 @@ class ConstraintsNlp
|
|
347
349
|
|
348
350
|
#
|
349
351
|
|
352
|
+
# -- MacroDroid specific -----------------------------------------------------------------------
|
353
|
+
|
354
|
+
get /^(\w+) (=) (\[?\w+\]?)/i do |loperand, operator, roperand|
|
355
|
+
|
356
|
+
h = {
|
357
|
+
loperand: loperand,
|
358
|
+
operator: operator,
|
359
|
+
roperand: roperand
|
360
|
+
}
|
361
|
+
|
362
|
+
[MacroDroidVariableConstraint, h]
|
363
|
+
|
364
|
+
end
|
365
|
+
|
350
366
|
# -- Sensors -----------------------------------
|
351
367
|
#
|
352
368
|
get /^Light Sensor (Less|Greater) than (50.0)lx/i do |operator, val|
|
@@ -386,6 +402,7 @@ end
|
|
386
402
|
class Macro
|
387
403
|
using ColouredText
|
388
404
|
using Params
|
405
|
+
include ObjectX
|
389
406
|
|
390
407
|
attr_reader :local_variables, :triggers, :actions, :constraints,
|
391
408
|
:guid, :deviceid
|
@@ -405,6 +422,8 @@ class Macro
|
|
405
422
|
end
|
406
423
|
|
407
424
|
def add(obj)
|
425
|
+
puts 'inside add; ' + obj.inspect
|
426
|
+
puts '@actions: ' + @actions.inspect
|
408
427
|
|
409
428
|
if obj.kind_of? Trigger then
|
410
429
|
|
@@ -663,68 +682,25 @@ class Macro
|
|
663
682
|
|
664
683
|
ap = ActionsNlp.new self
|
665
684
|
|
666
|
-
|
685
|
+
node.xpath('action').each do |e|
|
667
686
|
|
668
687
|
puts 'action e: ' + e.xml.inspect if @debug
|
669
688
|
puts 'e.text ' + e.text if @debug
|
670
689
|
|
671
690
|
item = e.element('item')
|
691
|
+
|
672
692
|
if item then
|
673
693
|
|
674
|
-
|
675
|
-
|
676
|
-
item.xpath('description').map do |description|
|
677
|
-
|
678
|
-
inner_lines = description.text.to_s.strip.lines
|
679
|
-
puts 'inner_lines: ' + inner_lines.inspect if @debug
|
680
|
-
|
681
|
-
action = if e.text.to_s.strip.empty? then
|
682
|
-
inner_lines.shift.strip
|
683
|
-
else
|
684
|
-
e.text.strip
|
685
|
-
end
|
686
|
-
|
687
|
-
puts 'action: ' + action.inspect if @debug
|
688
|
-
|
689
|
-
r = ap.find_action action
|
690
|
-
puts 'r: ' + r.inspect if @debug
|
691
|
-
puts 'description: ' + description.xml.inspect if @debug
|
692
|
-
#o = r[0].new([description, self]) if r
|
693
|
-
o = object_create(r[0],[description, self]) if r
|
694
|
-
puts 'after o' if @debug
|
695
|
-
o
|
696
|
-
|
697
|
-
end
|
698
|
-
|
699
|
-
else
|
700
|
-
|
701
|
-
action = e.text.strip
|
702
|
-
puts 'action: ' + action.inspect if @debug
|
703
|
-
r = ap.find_action action
|
704
|
-
|
705
|
-
a = e.xpath('item/*')
|
706
|
-
|
707
|
-
h = if a.any? then
|
708
|
-
a.map {|node| [node.name.to_sym, node.text.to_s]}.to_h
|
709
|
-
else
|
710
|
-
{}
|
711
|
-
end
|
712
|
-
puts 'h: ' + h.inspect if @debug
|
713
|
-
|
714
|
-
#r = ap.find_action action
|
715
|
-
#r[0].new(h.merge(macro: self)) if r
|
716
|
-
object_create(r[0], h.merge(macro: self)) if r
|
717
|
-
|
718
|
-
end
|
694
|
+
action_to_object(ap, e, item, self)
|
719
695
|
|
720
696
|
else
|
721
697
|
|
722
698
|
action = e.text.strip
|
723
699
|
r = ap.find_action action
|
724
700
|
#r[0].new(r[1]) if r
|
725
|
-
object_create(r[0],r[1]) if r
|
701
|
+
self.add object_create(r[0],r[1]) if r
|
726
702
|
|
727
|
-
end
|
703
|
+
end
|
728
704
|
|
729
705
|
end
|
730
706
|
|
@@ -1012,31 +988,7 @@ EOF
|
|
1012
988
|
|
1013
989
|
end
|
1014
990
|
|
1015
|
-
def object_create(klass, *args)
|
1016
991
|
|
1017
|
-
begin
|
1018
|
-
klass.new(*args)
|
1019
|
-
rescue
|
1020
|
-
raise MacroError, klass.to_s + ': ' + ($!).to_s
|
1021
|
-
end
|
1022
|
-
end
|
1023
|
-
|
1024
|
-
def varify(label, value='')
|
1025
|
-
|
1026
|
-
|
1027
|
-
type = VAR_TYPES[value.class.to_s.to_sym]
|
1028
992
|
|
1029
|
-
h = {
|
1030
|
-
boolean_value: false,
|
1031
|
-
decimal_value: 0.0,
|
1032
|
-
int_value: 0,
|
1033
|
-
name: label,
|
1034
|
-
string_value: '',
|
1035
|
-
type: type[0]
|
1036
|
-
}
|
1037
|
-
h[type[1]] = value
|
1038
|
-
h
|
1039
|
-
|
1040
|
-
end
|
1041
993
|
|
1042
994
|
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.9.
|
4
|
+
version: 0.9.4
|
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-
|
38
|
+
date: 2020-10-11 00:00:00.000000000 Z
|
39
39
|
dependencies:
|
40
40
|
- !ruby/object:Gem::Dependency
|
41
41
|
name: glw
|
metadata.gz.sig
CHANGED
Binary file
|