ruby-macrodroid 0.5.0 → 0.5.1

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: fc528ce6042bfe75807bb76fcc73cc255b45b6fe0bf138d4a643a5facd7fdaf1
4
- data.tar.gz: 294fed6fbe1ff71b05ea4384f9070e5795ceb1c41979bba419f89a4273164124
3
+ metadata.gz: c73d4f6bcddec53817e6ae7c59224759e58dd490ab53b2cab91728ceb98961f7
4
+ data.tar.gz: 37887f1b46a2158d5101b2c51ae444016dcf34606df34f8e6f58aed05482efb9
5
5
  SHA512:
6
- metadata.gz: 76925a5b3cba1509ec62635c04d5d796ded37f2e8cee958748a59c88938876129853adc91df55281e594b6c9043ba5f8fdaba2307a9ff4727d70cf611f4a2d8f
7
- data.tar.gz: 55f01e2512265e988d14cc63f576d18a5cc6fdee2a3d109ed47b0ef54bf3d4947ca4064696e405619bb5c2b5e545866fa771d040a13964e205bd343c7b111325
6
+ metadata.gz: 6bb6b3059e62aa4ce7924207a6fe545bc5b588d4ea4eab315361be595c47f343602a617dc7c2fdbc4701b44456dfcd18b255dc0fccfd904f7b56b5455f6f67a4
7
+ data.tar.gz: 2b7f77a7b582a0a8d7beda8ba09d10973e06a4844d114398a5bf534e755e66914cede0023693605abe0100f882befe7598271d70aaa5747bde9dac39c04d03d3
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -7,6 +7,12 @@ require 'rxfhelper'
7
7
  require 'chronic_cron'
8
8
 
9
9
 
10
+ MODEL =<<EOF
11
+ device
12
+ connectivity
13
+ airplane_mode is disabled
14
+ EOF
15
+
10
16
  class TriggersNlp
11
17
  include AppRoutes
12
18
 
@@ -20,7 +26,7 @@ class TriggersNlp
20
26
 
21
27
  def triggers(params)
22
28
 
23
- get /^at (\d+:\d+(?:[ap]m)?) on (.*)/i do |time, days|
29
+ get /^(?:at )?(\d+:\d+(?:[ap]m)?) (?:on )?(.*)/i do |time, days|
24
30
  [TimerTrigger, {time: time, days: days}]
25
31
  end
26
32
 
@@ -48,6 +54,9 @@ class ActionsNlp
48
54
  [ToastAction, {msg: msg}]
49
55
  end
50
56
 
57
+ get /^Popup Message ['"][^'"]+/i do |msg|
58
+ [ToastAction, {msg: msg}]
59
+ end
51
60
 
52
61
  end
53
62
 
@@ -178,7 +187,7 @@ class Macro
178
187
  m_action_list: @actions.map(&:to_h),
179
188
  m_constraint_list: @constraints.map(&:to_h),
180
189
  m_description: '',
181
- m_name: @title,
190
+ m_name: title(),
182
191
  m_excludeLog: false,
183
192
  m_GUID: guid(),
184
193
  m_isOrCondition: false,
@@ -194,6 +203,13 @@ class Macro
194
203
 
195
204
  def import_h(h)
196
205
 
206
+ if @debug then
207
+ puts 'inside import_h'
208
+ puts 'h:' + h.inspect
209
+ end
210
+
211
+ @title = h[:name]
212
+
197
213
  # fetch the local variables
198
214
  @local_variables = h['local_variables']
199
215
 
@@ -316,16 +332,16 @@ class Macro
316
332
 
317
333
  end
318
334
 
319
- def match?(triggerx, detail={time: $env[:time]} )
335
+ def match?(triggerx, detail={time: $env[:time]}, model=nil )
320
336
 
321
- if @triggers.any? {|x| x.type == triggerx and x.match?(detail) } then
337
+ if @triggers.any? {|x| x.type == triggerx and x.match?(detail, model) } then
322
338
 
323
339
  if @debug then
324
340
  puts 'checking constraints ...'
325
341
  puts '@constraints: ' + @constraints.inspect
326
342
  end
327
343
 
328
- if @constraints.all? {|x| x.match?($env.merge(detail)) } then
344
+ if @constraints.all? {|x| x.match?($env.merge(detail), model) } then
329
345
 
330
346
  true
331
347
 
@@ -342,6 +358,15 @@ class Macro
342
358
  def run()
343
359
  @actions.map(&:invoke)
344
360
  end
361
+
362
+ def to_s()
363
+ [
364
+ 'm: ' + @title,
365
+ @triggers.map {|x| "t: %s" % x}.join("\n"),
366
+ @actions.map {|x| "a: %s" % x}.join("\n"),
367
+ @constraints.map {|x| "a: %s" % x}.join("\n")
368
+ ].join("\n")
369
+ end
345
370
 
346
371
  private
347
372
 
@@ -435,11 +460,11 @@ class MacroDroid
435
460
  def import_json(s)
436
461
 
437
462
  @h = JSON.parse(s, symbolize_names: true).to_snake_case
438
- puts ('@h: ' + @h.pretty_inspect).debug if @debug
463
+ puts ('@h: ' + @h.inspect).debug if @debug
439
464
 
440
465
  @macros = @h[:macro_list].map do |macro|
441
466
 
442
- puts ('macro: ' + macro.pretty_inspect).debug if @debug
467
+ puts ('macro: ' + macro.inspect).debug if @debug
443
468
  m = Macro.new(debug: @debug)
444
469
  m.import_h(macro)
445
470
  m
@@ -499,7 +524,9 @@ class MacroDroid
499
524
 
500
525
  end
501
526
 
502
-
527
+ def to_s()
528
+ @macros.map(&:to_s).join("\n\n")
529
+ end
503
530
 
504
531
  end
505
532
 
@@ -562,10 +589,11 @@ class Trigger < MacroObject
562
589
  @list << 'fakeIcon'
563
590
  end
564
591
 
565
- def match?(detail={})
592
+ def match?(detail={}, model=nil)
593
+
594
+ # only match where the key exists in the trigger object
595
+ detail.select {|k,v| @h.include? k }.all? {|key,value| @h[key] == value}
566
596
 
567
- detail.all? {|key,value| @h[key] == value}
568
-
569
597
  end
570
598
 
571
599
  end
@@ -1056,7 +1084,7 @@ class TimerTrigger < Trigger
1056
1084
 
1057
1085
  end
1058
1086
 
1059
- def match?(detail={time: $env[:time]})
1087
+ def match?(detail={time: $env[:time]}, model=nil)
1060
1088
 
1061
1089
  a = @h[:days_of_week]
1062
1090
  a.unshift a.pop
@@ -1074,6 +1102,18 @@ class TimerTrigger < Trigger
1074
1102
  ChronicCron.new(s, detail[:time]).to_time == detail[:time]
1075
1103
 
1076
1104
  end
1105
+
1106
+ def to_s()
1107
+
1108
+ dow = @h[:days_of_week]
1109
+
1110
+ a = Date::ABBR_DAYNAMES
1111
+
1112
+ time = Time.parse("%s:%s" % [@h[:hour], @h[:minute]]).strftime("%-H:%M%P")
1113
+ days = (a[1..-1] << a.first).zip(dow).select {|_,b| b}.map(&:first)
1114
+
1115
+ "at %s on %s" % [time, days.join(', ')]
1116
+ end
1077
1117
 
1078
1118
  end
1079
1119
 
@@ -2709,6 +2749,10 @@ class ToastAction < NotificationsAction
2709
2749
  def invoke()
2710
2750
  super(@h[:message_text])
2711
2751
  end
2752
+
2753
+ def to_s()
2754
+ "Popup Message '%s'" % @h[:message_text]
2755
+ end
2712
2756
 
2713
2757
  end
2714
2758
 
@@ -3037,6 +3081,30 @@ class Constraint < MacroObject
3037
3081
  def initialize(h={})
3038
3082
  super(h)
3039
3083
  end
3084
+
3085
+ def match?(detail={}, model=nil)
3086
+
3087
+ detail.select {|k,v| @h.include? k }.all? {|key,value| @h[key] == value}
3088
+
3089
+ end
3090
+
3091
+ #def to_s()
3092
+ # ''
3093
+ #end
3094
+
3095
+ protected
3096
+
3097
+ def toggle_match?(key, val)
3098
+
3099
+ if @h[key] == true and val == key.to_s then
3100
+ true
3101
+ elsif @h[key] == false and val != key.to_s
3102
+ true
3103
+ else
3104
+ false
3105
+ end
3106
+
3107
+ end
3040
3108
 
3041
3109
  end
3042
3110
 
@@ -3398,6 +3466,29 @@ class AirplaneModeConstraint < Constraint
3398
3466
  super(options.merge h)
3399
3467
 
3400
3468
  end
3469
+
3470
+ def match?(detail={}, model=nil)
3471
+
3472
+ puts 'inside airplaneModeConstraint#match?' if $debug
3473
+
3474
+ if detail.has_key? :enabled then
3475
+
3476
+ puts 'detail has the key' if $debug
3477
+ super(detail)
3478
+
3479
+ elsif model
3480
+
3481
+ if $debug then
3482
+ puts 'checking the model'
3483
+ switch = model.connectivity.airplane_mode.switch
3484
+ puts 'switch: ' + switch.inspect
3485
+ end
3486
+
3487
+ toggle_match?(:enabled, switch)
3488
+
3489
+ end
3490
+
3491
+ end
3401
3492
 
3402
3493
  end
3403
3494
 
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.5.0
4
+ version: 0.5.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-08-19 00:00:00.000000000 Z
38
+ date: 2020-09-03 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: uuid
@@ -61,22 +61,22 @@ dependencies:
61
61
  name: rxfhelper
62
62
  requirement: !ruby/object:Gem::Requirement
63
63
  requirements:
64
- - - ">="
65
- - !ruby/object:Gem::Version
66
- version: 1.0.0
67
64
  - - "~>"
68
65
  - !ruby/object:Gem::Version
69
66
  version: '1.0'
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ version: 1.0.4
70
70
  type: :runtime
71
71
  prerelease: false
72
72
  version_requirements: !ruby/object:Gem::Requirement
73
73
  requirements:
74
- - - ">="
75
- - !ruby/object:Gem::Version
76
- version: 1.0.0
77
74
  - - "~>"
78
75
  - !ruby/object:Gem::Version
79
76
  version: '1.0'
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: 1.0.4
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: chronic_cron
82
82
  requirement: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file