ruby-macrodroid 0.3.0 → 0.5.2

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: 5f4e1e8fee18ccf4731c38c61f67b673888872ffa5b33349a6f2da8e9e51535f
4
- data.tar.gz: a3fe55c967182a61cf50514a38e7c3b8521e3efda4ce93d2b99c41e89540408b
3
+ metadata.gz: 8b105d3fc8c1fe8e43ad4ea6b8b9018a26e376949c94c1623a11540ba8d5850c
4
+ data.tar.gz: 22b28e9b200b82fe6c048a0781845c032502c9b24e8ff566e455b8f2193d97f1
5
5
  SHA512:
6
- metadata.gz: 22ec4d0d3b94072c272817def3167dd5b6c8d2874572028bb0f3629dfb0b86e00cbd5779e0f3f99344182819abe556f5ab2440c18621cc50302b35aff40a16bf
7
- data.tar.gz: b61d5d2efe7d8e47d1c99438a837f85d25af466c49c34eb3979d7204c600c4ca017262ba3f311311904abb78973713a8f53db9a17b6dce3c802ca8a651cacd21
6
+ metadata.gz: c09be84265a4961e278e378c346a6152924848f3cf2a347aa3c52c2b87dab6711092c07be1dbb3820576e5779e73818c96b34958c1e2044edf29b24a973c5e35
7
+ data.tar.gz: 333fc854bc4ce0ff61b1921a971835a1f4d1f75d65ae8608de0990c710f5060ecc7bfedb0468baba7f575ca73b3df96e9036d93a64339ba0e08a73d9c9612ecc
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -2,14 +2,17 @@
2
2
 
3
3
  # file: ruby-macrodroid.rb
4
4
 
5
- require 'pp'
6
- require 'json'
7
5
  require 'uuid'
8
- require 'date'
6
+ require 'yaml'
9
7
  require 'rxfhelper'
10
- require 'app-routes'
8
+ require 'chronic_cron'
11
9
 
12
10
 
11
+ MODEL =<<EOF
12
+ device
13
+ connectivity
14
+ airplane_mode is disabled
15
+ EOF
13
16
 
14
17
  class TriggersNlp
15
18
  include AppRoutes
@@ -24,11 +27,41 @@ class TriggersNlp
24
27
 
25
28
  def triggers(params)
26
29
 
27
- get /^at (\d+:\d+(?:[ap]m)?) on (.*)/i do |time, days|
30
+ get /^(?:at )?(\d+:\d+(?:[ap]m)?) (?:on )?(.*)/i do |time, days|
28
31
  [TimerTrigger, {time: time, days: days}]
29
32
  end
30
33
 
34
+ # time.is? 'at 18:30pm on Mon or Tue'
35
+ get /^time.is\? ['"](?:at )?(\d+:\d+(?:[ap]m)?) (?:on )?(.*)['"]/i do |time, days|
36
+ [TimerTrigger, {time: time, days: days.gsub(' or ',', ')}]
37
+ end
38
+
39
+ get /^shake[ _]device\??$/i do
40
+ [ShakeDeviceTrigger, {}]
41
+ end
42
+
43
+ get /^Flip Device (.*)$/i do |motion|
44
+ facedown = motion =~ /Face Up (?:->|to) Face Down/i
45
+ [FlipDeviceTrigger, {face_down: facedown }]
46
+ end
47
+
48
+ get /^flip_device_down\?$/i do
49
+ [FlipDeviceTrigger, {face_down: true }]
50
+ end
31
51
 
52
+ get /^flip_device_up\?$/i do
53
+ [FlipDeviceTrigger, {face_down: false }]
54
+ end
55
+
56
+ get /^Failed Login Attempt$/i do
57
+ [FailedLoginTrigger, {}]
58
+ end
59
+
60
+ get /^failed_login?$/i do
61
+ [FailedLoginTrigger, {}]
62
+ end
63
+
64
+
32
65
  end
33
66
 
34
67
  alias find_trigger run_route
@@ -52,6 +85,26 @@ class ActionsNlp
52
85
  [ToastAction, {msg: msg}]
53
86
  end
54
87
 
88
+ get /^Popup[ _]Message ['"]([^'"]+)/i do |msg|
89
+ [ToastAction, {msg: msg}]
90
+ end
91
+
92
+ get /^say current[ _]time/i do
93
+ [SayTimeAction, {}]
94
+ end
95
+
96
+ get /^Torch :?(.*)/i do |onoffstate|
97
+ state = onoffstate.downcase == 'on' ? 0 : 1
98
+ [CameraFlashLightAction, {state: state}]
99
+ end
100
+
101
+ get /^Take Picture/i do
102
+ [TakePictureAction, {}]
103
+ end
104
+
105
+ get /^take_picture/i do
106
+ [TakePictureAction, {}]
107
+ end
55
108
 
56
109
  end
57
110
 
@@ -59,6 +112,29 @@ class ActionsNlp
59
112
 
60
113
  end
61
114
 
115
+ class ConstraintsNlp
116
+ include AppRoutes
117
+
118
+ def initialize()
119
+
120
+ super()
121
+ params = {}
122
+ constraints(params)
123
+
124
+ end
125
+
126
+ def constraints(params)
127
+
128
+ get /^airplane mode (.*)/i do |state|
129
+ [AirplaneModeConstraint, {enabled: (state =~ /^enabled|on$/) == 0}]
130
+ end
131
+
132
+ end
133
+
134
+ alias find_constraint run_route
135
+
136
+ end
137
+
62
138
  module Params
63
139
 
64
140
  refine Hash do
@@ -70,7 +146,7 @@ module Params
70
146
  h.inject({}) do |r, x|
71
147
 
72
148
  key, value = x
73
- puts 'value: ' + value.inspect
149
+ #puts 'value: ' + value.inspect
74
150
 
75
151
  val = if value.is_a?(Hash) then
76
152
  to_snake_case(value)
@@ -116,16 +192,16 @@ class Macro
116
192
  using ColouredText
117
193
  using Params
118
194
 
119
- attr_reader :local_variables, :triggers, :actions, :guid
120
- attr_accessor :name
195
+ attr_reader :local_variables, :triggers, :actions, :constraints, :guid
196
+ attr_accessor :title, :description
121
197
 
122
198
  def initialize(name=nil, debug: false)
123
199
 
124
- @name, @debug = name, debug
125
- lv=[], triggers=[], actions=[]
126
- @local_variables, @triggers, @actions = lv, triggers, actions
200
+ @title, @debug = name, debug
201
+
202
+ puts 'inside Macro#initialize' if @debug
127
203
 
128
- @triggers, @actions = [], []
204
+ @local_variables, @triggers, @actions, @constraints = [], [], [], []
129
205
  @h = {}
130
206
 
131
207
  end
@@ -157,9 +233,9 @@ class Macro
157
233
  local_variables: @local_variables,
158
234
  m_trigger_list: @triggers.map(&:to_h),
159
235
  m_action_list: @actions.map(&:to_h),
160
- m_constraint_list: [],
236
+ m_constraint_list: @constraints.map(&:to_h),
161
237
  m_description: '',
162
- m_name: @name,
238
+ m_name: title(),
163
239
  m_excludeLog: false,
164
240
  m_GUID: guid(),
165
241
  m_isOrCondition: false,
@@ -175,6 +251,14 @@ class Macro
175
251
 
176
252
  def import_h(h)
177
253
 
254
+ if @debug then
255
+ puts 'inside import_h'
256
+ puts 'h:' + h.inspect
257
+ end
258
+
259
+ @title = h[:name]
260
+ @description = h[:description]
261
+
178
262
  # fetch the local variables
179
263
  @local_variables = h['local_variables']
180
264
 
@@ -189,13 +273,15 @@ class Macro
189
273
  object(action.to_snake_case)
190
274
  end
191
275
 
192
- # fetch the constraints (not yet implemented)
276
+ # fetch the constraints
277
+ @constraints = h[:constraint_list].map do |constraint|
278
+ object(constraint.to_snake_case)
279
+ end
193
280
 
194
281
  @h = h
195
282
 
196
- %i(local_variables m_trigger_list m_action_list).each do |x|
197
- @h[x] = []
198
- end
283
+ %i(local_variables m_trigger_list m_action_list m_constraint_list)\
284
+ .each {|x| @h[x] = [] }
199
285
 
200
286
  @h
201
287
 
@@ -203,7 +289,13 @@ class Macro
203
289
 
204
290
  def import_xml(node)
205
291
 
206
- @name = node.attributes[:name]
292
+ if @debug then
293
+ puts 'inside Macro#import_xml'
294
+ puts 'node: ' + node.xml.inspect
295
+ end
296
+
297
+ @title = node.attributes[:name]
298
+ @description = node.attributes[:description]
207
299
 
208
300
  if node.element('triggers') then
209
301
 
@@ -231,6 +323,14 @@ class Macro
231
323
  end
232
324
 
233
325
  end
326
+
327
+ # get all the constraints
328
+ @constraints = node.xpath('constraints/*').map do |e|
329
+
330
+ puts 'e.name: ' + e.name.inspect if @debug
331
+ {airplanemode: AirplaneModeConstraint}[e.name.to_sym].new(e.attributes.to_h)
332
+
333
+ end
234
334
 
235
335
  else
236
336
 
@@ -242,6 +342,8 @@ class Macro
242
342
 
243
343
  r = tp.find_trigger e.text
244
344
 
345
+ puts 'found trigger ' + r.inspect if @debug
346
+
245
347
  if r then
246
348
  r[0].new(r[1])
247
349
  end
@@ -253,18 +355,86 @@ class Macro
253
355
  @actions = node.xpath('action').map do |e|
254
356
 
255
357
  r = ap.find_action e.text
358
+ puts 'found action ' + r.inspect if @debug
256
359
 
257
360
  if r then
258
361
  r[0].new(r[1])
259
362
  end
260
363
 
261
364
  end
365
+
366
+ cp = ConstraintsNlp.new
367
+
368
+ @constraints = node.xpath('constraint').map do |e|
369
+
370
+ r = cp.find_constraint e.text
371
+ puts 'found constraint ' + r.inspect if @debug
372
+
373
+ if r then
374
+ r[0].new(r[1])
375
+ end
376
+
377
+ end
262
378
 
263
379
  end
264
380
 
265
381
  self
266
382
 
267
383
  end
384
+
385
+ def match?(triggerx, detail={time: $env[:time]}, model=nil )
386
+
387
+ if @triggers.any? {|x| x.type == triggerx and x.match?(detail, model) } then
388
+
389
+ if @debug then
390
+ puts 'checking constraints ...'
391
+ puts '@constraints: ' + @constraints.inspect
392
+ end
393
+
394
+ if @constraints.all? {|x| x.match?($env.merge(detail), model) } then
395
+
396
+ true
397
+
398
+ else
399
+
400
+ return false
401
+
402
+ end
403
+
404
+ end
405
+
406
+ end
407
+
408
+ def run()
409
+ @actions.map(&:invoke)
410
+ end
411
+
412
+ def to_pc()
413
+
414
+ heading = '# ' + @title + "\n"
415
+ heading += '# ' + @description if @description
416
+ condition = @triggers.first.to_pc
417
+ actions = @actions.map(&:to_pc).join("\n")
418
+
419
+ <<EOF
420
+ #{heading}
421
+
422
+ if #{condition} then
423
+ #{actions}
424
+ end
425
+ EOF
426
+ end
427
+
428
+ def to_s()
429
+ a = [
430
+ 'm: ' + @title,
431
+ @triggers.map {|x| "t: %s" % x}.join("\n"),
432
+ @actions.map {|x| "a: %s" % x}.join("\n"),
433
+ @constraints.map {|x| "a: %s" % x}.join("\n")
434
+ ]
435
+ a.insert(1, 'd: ' + @description) if @description
436
+ a.join("\n")
437
+ end
268
438
 
269
439
  private
270
440
 
@@ -282,6 +452,9 @@ class Macro
282
452
  end
283
453
 
284
454
 
455
+ class MacroDroidError < Exception
456
+ end
457
+
285
458
  class MacroDroid
286
459
  using ColouredText
287
460
  using Params
@@ -294,14 +467,33 @@ class MacroDroid
294
467
 
295
468
  if obj then
296
469
 
297
- s, _ = RXFHelper.read(obj)
470
+ raw_s, _ = RXFHelper.read(obj)
471
+
472
+ s = raw_s.strip
298
473
 
299
474
  if s[0] == '{' then
475
+
300
476
  import_json(s)
301
- else
302
- s[0] == '<'
477
+
478
+ elsif s[0] == '<'
479
+
303
480
  import_xml(s)
304
481
  @h = build_h
482
+
483
+ else
484
+
485
+ xml = if s =~ /^m: / then
486
+ text_to_xml(s)
487
+ elsif s =~ /^# /
488
+ pc_to_xml(s)
489
+ else
490
+ raise MacroDroidError, 'invalid input'
491
+ end
492
+ import_xml(xml)
493
+ @h = build_h
494
+
495
+
496
+
305
497
  end
306
498
 
307
499
  else
@@ -319,6 +511,7 @@ class MacroDroid
319
511
 
320
512
  def build_h()
321
513
 
514
+ puts 'inside Macro#build_h' if @debug
322
515
  {
323
516
  cell_tower_groups: [],
324
517
  cell_towers_ignore: [],
@@ -354,12 +547,15 @@ class MacroDroid
354
547
 
355
548
  def import_json(s)
356
549
 
357
- @h = JSON.parse(s, symbolize_names: true).to_snake_case
358
- puts ('@h: ' + @h.pretty_inspect).debug if @debug
550
+ h = JSON.parse(s, symbolize_names: true)
551
+ puts 'json_to_yaml: ' + h.to_yaml if @debug
552
+
553
+ @h = h.to_snake_case
554
+ puts ('@h: ' + @h.inspect).debug if @debug
359
555
 
360
556
  @macros = @h[:macro_list].map do |macro|
361
557
 
362
- puts ('macro: ' + macro.pretty_inspect).debug if @debug
558
+ puts ('macro: ' + macro.inspect).debug if @debug
363
559
  m = Macro.new(debug: @debug)
364
560
  m.import_h(macro)
365
561
  m
@@ -372,37 +568,110 @@ class MacroDroid
372
568
 
373
569
  def import_xml(raws)
374
570
 
571
+ puts 'raws: ' + raws.inspect if @debug
375
572
  s = RXFHelper.read(raws).first
376
573
  puts 's: ' + s.inspect if @debug
377
574
  doc = Rexle.new(s)
378
- puts 'after doc' if @debug
575
+
576
+ if @debug then
577
+ puts 'doc: ' + doc.root.xml
578
+ end
579
+
580
+ debug = @debug
379
581
 
380
582
  @macros = doc.root.xpath('macro').map do |node|
381
583
 
382
- macro = Macro.new @name
584
+ macro = Macro.new @title, debug: debug
383
585
  macro.import_xml(node)
384
586
  macro
385
587
 
386
588
  end
387
589
  end
590
+
591
+ def pc_to_xml(s)
592
+
593
+ macros = s.strip.split(/(?=#)/).map do |raw_macro|
594
+
595
+ a = raw_macro.lines
596
+ name = a.shift[/(?<=# ).*/]
597
+ description = a.shift[/(?<=# ).*/] if a[0][/^# /]
598
+ body = a.join.strip
599
+
600
+ a2 = body.lines
601
+ # get the trigger
602
+ trigger = [:trigger, {}, a2[0][/^if (.*) then/,1]]
603
+ action = [:action, {}, a2[1].strip]
604
+ [:macro, {name: name, description: description}, trigger, action, []]
605
+
606
+ end
607
+
608
+ doc = Rexle.new([:macros, {}, '', *macros])
609
+ doc.root.xml pretty: true
610
+
611
+ end
612
+
613
+ def text_to_xml(s)
614
+
615
+ a = s.split(/.*(?=^m:)/); a.shift
616
+ a.map!(&:chomp)
617
+
618
+ macros = a.map do |x|
619
+
620
+ lines = x.lines
621
+ puts 'lines: ' + lines.inspect if @debug
622
+
623
+ name = lines.shift[/^m: +(.*)/,1]
624
+ h = {t: [], a: [], c: []}
625
+
626
+ lines.each {|line| h[line[0].to_sym] << line[/^\w: +(.*)/,1] }
627
+ triggers = h[:t].map {|text| [:trigger, {}, text]}
628
+ actions = h[:a].map {|text| [:action, {}, text]}
629
+ constraints = h[:c].map {|text| [:constraint, {}, text]}
630
+
631
+ [:macro, {name: name},'', *triggers, *actions, *constraints]
632
+
633
+ end
634
+
635
+ doc = Rexle.new([:macros, {}, '', *macros])
636
+ doc.root.xml pretty: true
637
+
638
+ end
388
639
 
389
640
  def to_h()
390
641
 
391
642
  @h.merge(macro_list: @macros.map(&:to_h)).to_camel_case
392
643
 
393
644
  end
645
+
646
+ # returns pseudocode
647
+ #
648
+ def to_pc()
649
+ @macros.map(&:to_pc).join("\n\n")
650
+ end
394
651
 
395
-
652
+ def to_s()
653
+ @macros.map(&:to_s).join("\n")
654
+ end
396
655
 
397
656
  end
398
657
 
399
658
  class MacroObject
659
+ using ColouredText
660
+
661
+ attr_reader :type
662
+ attr_accessor :options
400
663
 
401
664
  def initialize(h={})
402
665
 
403
666
  @h = {constraint_list: [], is_or_condition: false,
404
667
  is_disabled: false}.merge(h)
405
668
  @list = []
669
+
670
+ # fetch the class name and convert from camelCase to snake_eyes
671
+ @type = self.class.to_s.sub(/Trigger|Action$/,'')\
672
+ .gsub(/\B[A-Z][a-z]/){|x| '_' + x.downcase}\
673
+ .gsub(/[a-z][A-Z]/){|x| x[0] + '_' + x[1].downcase}\
674
+ .downcase.to_sym
406
675
  end
407
676
 
408
677
  def to_h()
@@ -425,6 +694,13 @@ class MacroObject
425
694
 
426
695
  protected
427
696
 
697
+ def filter(options, h)
698
+
699
+ (h.keys - options.keys).each {|key| h.delete key }
700
+ return h
701
+
702
+ end
703
+
428
704
  def uuid()
429
705
  UUID.new.generate
430
706
  end
@@ -437,11 +713,19 @@ class Trigger < MacroObject
437
713
  super({fakeIcon: 0}.merge(h))
438
714
  @list << 'fakeIcon'
439
715
  end
716
+
717
+ def match?(detail={}, model=nil)
718
+
719
+ # only match where the key exists in the trigger object
720
+ detail.select {|k,v| @h.include? k }.all? {|key,value| @h[key] == value}
721
+
722
+ end
440
723
 
441
724
  end
442
725
 
443
726
 
444
-
727
+ # Category: Applications
728
+ #
445
729
  class WebHookTrigger < Trigger
446
730
 
447
731
  def initialize(h={})
@@ -456,6 +740,22 @@ class WebHookTrigger < Trigger
456
740
 
457
741
  end
458
742
 
743
+ # Category: Applications
744
+ #
745
+ # Also known as Wifi State Change
746
+ #
747
+ # wifi_state options:
748
+ # 0 - Wifi Enabled
749
+ # 1 - Wifi Disabled
750
+ # 2 - Connected to network
751
+ # ssid_list options:
752
+ # ["Any Network"]
753
+ # ["some Wifi SSID"] - 1 or more SSID can be supplied
754
+ # 3 - Disconnected from network
755
+ # ssid_list options:
756
+ # ["Any Network"]
757
+ # ["some Wifi SSID"] - 1 or more SSID can be supplied
758
+
459
759
  class WifiConnectionTrigger < Trigger
460
760
 
461
761
  def initialize(h={})
@@ -471,6 +771,8 @@ class WifiConnectionTrigger < Trigger
471
771
 
472
772
  end
473
773
 
774
+ # Category: Applications
775
+ #
474
776
  class ApplicationInstalledRemovedTrigger < Trigger
475
777
 
476
778
  def initialize(h={})
@@ -489,6 +791,8 @@ class ApplicationInstalledRemovedTrigger < Trigger
489
791
 
490
792
  end
491
793
 
794
+ # Category: Applications
795
+ #
492
796
  class ApplicationLaunchedTrigger < Trigger
493
797
 
494
798
  def initialize(h={})
@@ -505,6 +809,8 @@ class ApplicationLaunchedTrigger < Trigger
505
809
 
506
810
  end
507
811
 
812
+ # Category: Battery/Power
813
+ #
508
814
  class BatteryLevelTrigger < Trigger
509
815
 
510
816
  def initialize(h={})
@@ -521,6 +827,8 @@ class BatteryLevelTrigger < Trigger
521
827
 
522
828
  end
523
829
 
830
+ # Category: Battery/Power
831
+ #
524
832
  class BatteryTemperatureTrigger < Trigger
525
833
 
526
834
  def initialize(h={})
@@ -537,6 +845,8 @@ class BatteryTemperatureTrigger < Trigger
537
845
 
538
846
  end
539
847
 
848
+ # Category: Battery/Power
849
+ #
540
850
  class PowerButtonToggleTrigger < Trigger
541
851
 
542
852
  def initialize(h={})
@@ -551,6 +861,9 @@ class PowerButtonToggleTrigger < Trigger
551
861
 
552
862
  end
553
863
 
864
+
865
+ # Category: Battery/Power
866
+ #
554
867
  class ExternalPowerTrigger < Trigger
555
868
 
556
869
  def initialize(h={})
@@ -568,6 +881,8 @@ class ExternalPowerTrigger < Trigger
568
881
 
569
882
  end
570
883
 
884
+ # Category: Call/SMS
885
+ #
571
886
  class CallActiveTrigger < Trigger
572
887
 
573
888
  def initialize(h={})
@@ -584,6 +899,8 @@ class CallActiveTrigger < Trigger
584
899
 
585
900
  end
586
901
 
902
+ # Category: Call/SMS
903
+ #
587
904
  class IncomingCallTrigger < Trigger
588
905
 
589
906
  def initialize(h={})
@@ -602,6 +919,8 @@ class IncomingCallTrigger < Trigger
602
919
 
603
920
  end
604
921
 
922
+ # Category: Call/SMS
923
+ #
605
924
  class OutgoingCallTrigger < Trigger
606
925
 
607
926
  def initialize(h={})
@@ -620,6 +939,8 @@ class OutgoingCallTrigger < Trigger
620
939
 
621
940
  end
622
941
 
942
+ # Category: Call/SMS
943
+ #
623
944
  class CallEndedTrigger < Trigger
624
945
 
625
946
  def initialize(h={})
@@ -638,6 +959,8 @@ class CallEndedTrigger < Trigger
638
959
 
639
960
  end
640
961
 
962
+ # Category: Call/SMS
963
+ #
641
964
  class CallMissedTrigger < Trigger
642
965
 
643
966
  def initialize(h={})
@@ -652,6 +975,8 @@ class CallMissedTrigger < Trigger
652
975
 
653
976
  end
654
977
 
978
+ # Category: Call/SMS
979
+ #
655
980
  class IncomingSMSTrigger < Trigger
656
981
 
657
982
  def initialize(h={})
@@ -674,6 +999,8 @@ class IncomingSMSTrigger < Trigger
674
999
 
675
1000
  end
676
1001
 
1002
+ # Category: Connectivity
1003
+ #
677
1004
  class WebHookTrigger < Trigger
678
1005
 
679
1006
  def initialize(h={})
@@ -688,6 +1015,8 @@ class WebHookTrigger < Trigger
688
1015
 
689
1016
  end
690
1017
 
1018
+ # Category: Connectivity
1019
+ #
691
1020
  class WifiConnectionTrigger < Trigger
692
1021
 
693
1022
  def initialize(h={})
@@ -703,6 +1032,8 @@ class WifiConnectionTrigger < Trigger
703
1032
 
704
1033
  end
705
1034
 
1035
+ # Category: Connectivity
1036
+ #
706
1037
  class BluetoothTrigger < Trigger
707
1038
 
708
1039
  def initialize(h={})
@@ -719,6 +1050,8 @@ class BluetoothTrigger < Trigger
719
1050
 
720
1051
  end
721
1052
 
1053
+ # Category: Connectivity
1054
+ #
722
1055
  class HeadphonesTrigger < Trigger
723
1056
 
724
1057
  def initialize(h={})
@@ -734,6 +1067,8 @@ class HeadphonesTrigger < Trigger
734
1067
 
735
1068
  end
736
1069
 
1070
+ # Category: Connectivity
1071
+ #
737
1072
  class SignalOnOffTrigger < Trigger
738
1073
 
739
1074
  def initialize(h={})
@@ -748,6 +1083,8 @@ class SignalOnOffTrigger < Trigger
748
1083
 
749
1084
  end
750
1085
 
1086
+ # Category: Connectivity
1087
+ #
751
1088
  class UsbDeviceConnectionTrigger < Trigger
752
1089
 
753
1090
  def initialize(h={})
@@ -762,22 +1099,45 @@ class UsbDeviceConnectionTrigger < Trigger
762
1099
 
763
1100
  end
764
1101
 
1102
+ # Category: Connectivity
1103
+ #
1104
+ # Also known as Wifi SSID Transition
1105
+ #
1106
+ # options:
1107
+ # in_range: true | false
1108
+ # wifi_cell_info: {display_name: "some Wifi SSID",
1109
+ # ssid: "some Wifi SSID"} - 1 or more allowed
1110
+ #
765
1111
  class WifiSSIDTrigger < Trigger
766
1112
 
767
1113
  def initialize(h={})
768
1114
 
769
1115
  options = {
770
- wifi_cell_info_list: [{:displayName=>"", :ssid=>""}],
1116
+ wifi_cell_info_list: [{:display_name=>"", :ssid=>""}],
771
1117
  ssid_list: [],
772
- _in_range: true
1118
+ in_range: true
773
1119
  }
774
1120
 
775
1121
  super(options.merge h)
776
1122
 
777
1123
  end
1124
+
1125
+ def to_h()
1126
+
1127
+ h = super()
1128
+ val = h[:m_inRange]
1129
+
1130
+ h[:m_InRange] = val
1131
+ h.delete :m_inRange
1132
+
1133
+ return h
1134
+
1135
+ end
778
1136
 
779
1137
  end
780
1138
 
1139
+ # Category: Date/Time
1140
+ #
781
1141
  class CalendarTrigger < Trigger
782
1142
 
783
1143
  def initialize(h={})
@@ -802,15 +1162,21 @@ class CalendarTrigger < Trigger
802
1162
 
803
1163
  end
804
1164
 
1165
+ # Category: Date/Time
1166
+ #
805
1167
  class TimerTrigger < Trigger
1168
+ using ColouredText
1169
+
806
1170
 
807
1171
  def initialize(h={})
1172
+
1173
+ puts 'TimerTrigger h: ' + h.inspect if $debug
808
1174
 
809
1175
  if h[:days] then
810
1176
 
811
1177
  days = [false] * 7
812
-
813
- h[:days].split(/, +/).each do |x|
1178
+
1179
+ h[:days].split(/, */).each do |x|
814
1180
 
815
1181
  r = Date::DAYNAMES.grep /#{x}/i
816
1182
  i = Date::DAYNAMES.index(r.first)
@@ -819,7 +1185,6 @@ class TimerTrigger < Trigger
819
1185
  end
820
1186
 
821
1187
  h[:days_of_week] = days
822
- h.delete :days
823
1188
 
824
1189
  end
825
1190
 
@@ -827,24 +1192,62 @@ class TimerTrigger < Trigger
827
1192
 
828
1193
  t = Time.parse(h[:time])
829
1194
  h[:hour], h[:minute] = t.hour, t.min
830
- h.delete :time
831
1195
 
832
1196
  end
1197
+
1198
+ #puts ('h: ' + h.inspect).debug
833
1199
 
834
1200
  options = {
835
1201
  alarm_id: uuid(),
836
- days_of_week: [false, true, false, false, false, false, false],
1202
+ days_of_week: [false, false, false, false, false, false, false],
837
1203
  minute: 10,
838
1204
  hour: 7,
839
1205
  use_alarm: false
840
1206
  }
1207
+
1208
+ super(options.merge filter(options,h))
841
1209
 
842
- super(options.merge h)
1210
+ end
1211
+
1212
+ def match?(detail={time: $env[:time]}, model=nil)
1213
+
1214
+ a = @h[:days_of_week]
1215
+ a.unshift a.pop
1216
+
1217
+ dow = a.map.with_index {|x, i| x ? i : nil }.compact.join(',')
1218
+
1219
+ s = "%s %s * * %s" % [@h[:minute], @h[:hour], dow]
1220
+
1221
+ if $debug then
1222
+ puts 's: ' + s.inspect
1223
+ puts 'detail: ' + detail.inspect
1224
+ puts '@h: ' + @h.inspect
1225
+ end
1226
+
1227
+ ChronicCron.new(s, detail[:time]).to_time == detail[:time]
1228
+
1229
+ end
1230
+
1231
+ def to_pc()
1232
+ "time.is? '%s'" % self.to_s.gsub(',', ' or')
1233
+ end
1234
+
1235
+ def to_s()
1236
+
1237
+ dow = @h[:days_of_week]
1238
+
1239
+ a = Date::ABBR_DAYNAMES
843
1240
 
1241
+ time = Time.parse("%s:%s" % [@h[:hour], @h[:minute]]).strftime("%-H:%M%P")
1242
+ days = (a[1..-1] << a.first).zip(dow).select {|_,b| b}.map(&:first)
1243
+
1244
+ "at %s on %s" % [time, days.join(', ')]
844
1245
  end
845
1246
 
846
1247
  end
847
1248
 
1249
+ # Category: Date/Time
1250
+ #
848
1251
  class StopwatchTrigger < Trigger
849
1252
 
850
1253
  def initialize(h={})
@@ -860,6 +1263,13 @@ class StopwatchTrigger < Trigger
860
1263
 
861
1264
  end
862
1265
 
1266
+ # Category: Date/Time
1267
+ #
1268
+ # Also known as Day of Week/Month
1269
+ #
1270
+ # month_of_year equal to 0 means it occurs every month
1271
+ # day_of_week starts with a Monday (value is 0)
1272
+ #
863
1273
  class DayTrigger < Trigger
864
1274
 
865
1275
  def initialize(h={})
@@ -881,6 +1291,10 @@ class DayTrigger < Trigger
881
1291
 
882
1292
  end
883
1293
 
1294
+ # Category: Date/Time
1295
+ #
1296
+ # Regular Interval
1297
+ #
884
1298
  class RegularIntervalTrigger < Trigger
885
1299
 
886
1300
  def initialize(h={})
@@ -900,7 +1314,27 @@ class RegularIntervalTrigger < Trigger
900
1314
 
901
1315
  end
902
1316
 
903
- class AirplaneModeTrigger < Trigger
1317
+ class DeviceEventsTrigger < Trigger
1318
+
1319
+ def initialize(h={})
1320
+ super(h)
1321
+ @group = 'device_events'
1322
+ end
1323
+
1324
+ end
1325
+
1326
+ # Category: Device Events
1327
+ #
1328
+ # Airplane Mode Changed
1329
+ #
1330
+ # options:
1331
+ # Airplane Mode Enabled
1332
+ # Airplane Mode Disabled
1333
+ #
1334
+ # shorthand example:
1335
+ # airplanemode: enabled
1336
+ #
1337
+ class AirplaneModeTrigger < DeviceEventsTrigger
904
1338
 
905
1339
  def initialize(h={})
906
1340
 
@@ -914,7 +1348,9 @@ class AirplaneModeTrigger < Trigger
914
1348
 
915
1349
  end
916
1350
 
917
- class AutoSyncChangeTrigger < Trigger
1351
+ # Category: Device Events
1352
+ #
1353
+ class AutoSyncChangeTrigger < DeviceEventsTrigger
918
1354
 
919
1355
  def initialize(h={})
920
1356
 
@@ -928,7 +1364,9 @@ class AutoSyncChangeTrigger < Trigger
928
1364
 
929
1365
  end
930
1366
 
931
- class DayDreamTrigger < Trigger
1367
+ # Category: Device Events
1368
+ #
1369
+ class DayDreamTrigger < DeviceEventsTrigger
932
1370
 
933
1371
  def initialize(h={})
934
1372
 
@@ -942,7 +1380,9 @@ class DayDreamTrigger < Trigger
942
1380
 
943
1381
  end
944
1382
 
945
- class DockTrigger < Trigger
1383
+ # Category: Device Events
1384
+ #
1385
+ class DockTrigger < DeviceEventsTrigger
946
1386
 
947
1387
  def initialize(h={})
948
1388
 
@@ -956,26 +1396,37 @@ class DockTrigger < Trigger
956
1396
 
957
1397
  end
958
1398
 
959
- class GPSEnabledTrigger < Trigger
960
-
1399
+ # Category: Device Events
1400
+ #
1401
+ class FailedLoginTrigger < DeviceEventsTrigger
1402
+
961
1403
  def initialize(h={})
962
1404
 
963
1405
  options = {
964
- gps_mode_enabled: true
1406
+ num_failures: 1
965
1407
  }
966
1408
 
967
1409
  super(options.merge h)
968
1410
 
969
1411
  end
1412
+
1413
+ def to_pc()
1414
+ 'failed_login?'
1415
+ end
970
1416
 
1417
+ def to_s()
1418
+ 'Failed Login Attempt'
1419
+ end
971
1420
  end
972
1421
 
973
- class MusicPlayingTrigger < Trigger
1422
+ # Category: Device Events
1423
+ #
1424
+ class GPSEnabledTrigger < DeviceEventsTrigger
974
1425
 
975
1426
  def initialize(h={})
976
1427
 
977
1428
  options = {
978
- option: 0
1429
+ gps_mode_enabled: true
979
1430
  }
980
1431
 
981
1432
  super(options.merge h)
@@ -984,11 +1435,14 @@ class MusicPlayingTrigger < Trigger
984
1435
 
985
1436
  end
986
1437
 
987
- class DeviceUnlockedTrigger < Trigger
1438
+ # Category: Device Events
1439
+ #
1440
+ class MusicPlayingTrigger < DeviceEventsTrigger
988
1441
 
989
1442
  def initialize(h={})
990
1443
 
991
1444
  options = {
1445
+ option: 0
992
1446
  }
993
1447
 
994
1448
  super(options.merge h)
@@ -997,7 +1451,10 @@ class DeviceUnlockedTrigger < Trigger
997
1451
 
998
1452
  end
999
1453
 
1000
- class DeviceUnlockedTrigger < Trigger
1454
+
1455
+ # Category: Device Events
1456
+ #
1457
+ class DeviceUnlockedTrigger < DeviceEventsTrigger
1001
1458
 
1002
1459
  def initialize(h={})
1003
1460
 
@@ -1010,7 +1467,9 @@ class DeviceUnlockedTrigger < Trigger
1010
1467
 
1011
1468
  end
1012
1469
 
1013
- class AutoRotateChangeTrigger < Trigger
1470
+ # Category: Device Events
1471
+ #
1472
+ class AutoRotateChangeTrigger < DeviceEventsTrigger
1014
1473
 
1015
1474
  def initialize(h={})
1016
1475
 
@@ -1024,7 +1483,9 @@ class AutoRotateChangeTrigger < Trigger
1024
1483
 
1025
1484
  end
1026
1485
 
1027
- class ClipboardChangeTrigger < Trigger
1486
+ # Category: Device Events
1487
+ #
1488
+ class ClipboardChangeTrigger < DeviceEventsTrigger
1028
1489
 
1029
1490
  def initialize(h={})
1030
1491
 
@@ -1039,20 +1500,9 @@ class ClipboardChangeTrigger < Trigger
1039
1500
 
1040
1501
  end
1041
1502
 
1042
- class BootTrigger < Trigger
1043
-
1044
- def initialize(h={})
1045
-
1046
- options = {
1047
- }
1048
-
1049
- super(options.merge h)
1050
-
1051
- end
1052
-
1053
- end
1054
-
1055
- class BootTrigger < Trigger
1503
+ # Category: Device Events
1504
+ #
1505
+ class BootTrigger < DeviceEventsTrigger
1056
1506
 
1057
1507
  def initialize(h={})
1058
1508
 
@@ -1065,7 +1515,9 @@ class BootTrigger < Trigger
1065
1515
 
1066
1516
  end
1067
1517
 
1068
- class IntentReceivedTrigger < Trigger
1518
+ # Category: Device Events
1519
+ #
1520
+ class IntentReceivedTrigger < DeviceEventsTrigger
1069
1521
 
1070
1522
  def initialize(h={})
1071
1523
 
@@ -1083,7 +1535,9 @@ class IntentReceivedTrigger < Trigger
1083
1535
 
1084
1536
  end
1085
1537
 
1086
- class NotificationTrigger < Trigger
1538
+ # Category: Device Events
1539
+ #
1540
+ class NotificationTrigger < DeviceEventsTrigger
1087
1541
 
1088
1542
  def initialize(h={})
1089
1543
 
@@ -1107,7 +1561,9 @@ class NotificationTrigger < Trigger
1107
1561
 
1108
1562
  end
1109
1563
 
1110
- class ScreenOnOffTrigger < Trigger
1564
+ # Category: Device Events
1565
+ #
1566
+ class ScreenOnOffTrigger < DeviceEventsTrigger
1111
1567
 
1112
1568
  def initialize(h={})
1113
1569
 
@@ -1121,7 +1577,9 @@ class ScreenOnOffTrigger < Trigger
1121
1577
 
1122
1578
  end
1123
1579
 
1124
- class SilentModeTrigger < Trigger
1580
+ # Category: Device Events
1581
+ #
1582
+ class SilentModeTrigger < DeviceEventsTrigger
1125
1583
 
1126
1584
  def initialize(h={})
1127
1585
 
@@ -1135,6 +1593,8 @@ class SilentModeTrigger < Trigger
1135
1593
 
1136
1594
  end
1137
1595
 
1596
+ # Category: Location
1597
+ #
1138
1598
  class WeatherTrigger < Trigger
1139
1599
 
1140
1600
  def initialize(h={})
@@ -1158,6 +1618,8 @@ class WeatherTrigger < Trigger
1158
1618
 
1159
1619
  end
1160
1620
 
1621
+ # Category: Location
1622
+ #
1161
1623
  class GeofenceTrigger < Trigger
1162
1624
 
1163
1625
  def initialize(h={})
@@ -1176,6 +1638,8 @@ class GeofenceTrigger < Trigger
1176
1638
 
1177
1639
  end
1178
1640
 
1641
+ # Category: Location
1642
+ #
1179
1643
  class SunriseSunsetTrigger < Trigger
1180
1644
 
1181
1645
  def initialize(h={})
@@ -1192,7 +1656,18 @@ class SunriseSunsetTrigger < Trigger
1192
1656
  end
1193
1657
 
1194
1658
 
1195
- class ActivityRecognitionTrigger < Trigger
1659
+ class SensorsTrigger < Trigger
1660
+
1661
+ def initialize(h={})
1662
+ super(h)
1663
+ @group = 'sensors'
1664
+ end
1665
+
1666
+ end
1667
+
1668
+ # Category: Sensors
1669
+ #
1670
+ class ActivityRecognitionTrigger < SensorsTrigger
1196
1671
 
1197
1672
  def initialize(h={})
1198
1673
 
@@ -1207,8 +1682,9 @@ class ActivityRecognitionTrigger < Trigger
1207
1682
 
1208
1683
  end
1209
1684
 
1210
-
1211
- class ProximityTrigger < Trigger
1685
+ # Category: Sensors
1686
+ #
1687
+ class ProximityTrigger < SensorsTrigger
1212
1688
 
1213
1689
  def initialize(h={})
1214
1690
 
@@ -1223,7 +1699,9 @@ class ProximityTrigger < Trigger
1223
1699
 
1224
1700
  end
1225
1701
 
1226
- class ShakeDeviceTrigger < Trigger
1702
+ # Category: Sensors
1703
+ #
1704
+ class ShakeDeviceTrigger < SensorsTrigger
1227
1705
 
1228
1706
  def initialize(h={})
1229
1707
 
@@ -1233,10 +1711,25 @@ class ShakeDeviceTrigger < Trigger
1233
1711
  super(options.merge h)
1234
1712
 
1235
1713
  end
1714
+
1715
+ def to_pc()
1716
+ 'shake_device?'
1717
+ end
1718
+
1719
+ def to_s()
1720
+ 'Shake Device'
1721
+ end
1236
1722
 
1237
1723
  end
1238
1724
 
1239
- class FlipDeviceTrigger < Trigger
1725
+ # Category: Sensors
1726
+ #
1727
+ # options:
1728
+ # Face Up -> Face Down
1729
+ # Face Down -> Face Up
1730
+ # Any -> Face Down
1731
+ #
1732
+ class FlipDeviceTrigger < SensorsTrigger
1240
1733
 
1241
1734
  def initialize(h={})
1242
1735
 
@@ -1248,11 +1741,23 @@ class FlipDeviceTrigger < Trigger
1248
1741
 
1249
1742
  super(options.merge h)
1250
1743
 
1744
+ end
1745
+
1746
+ def to_pc()
1747
+ @h[:face_down] ? 'flip_device_down?' : 'flip_device_up?'
1251
1748
  end
1749
+
1750
+ def to_s()
1751
+
1752
+ action = @h[:face_down] ? 'Face Up -> Face Down' : 'Face Down -> Face Up'
1753
+ 'Flip Device ' + action
1754
+ end
1252
1755
 
1253
1756
  end
1254
1757
 
1255
- class OrientationTrigger < Trigger
1758
+ # Category: Sensors
1759
+ #
1760
+ class OrientationTrigger < SensorsTrigger
1256
1761
 
1257
1762
  def initialize(h={})
1258
1763
 
@@ -1267,6 +1772,8 @@ class OrientationTrigger < Trigger
1267
1772
 
1268
1773
  end
1269
1774
 
1775
+ # Category: User Input
1776
+ #
1270
1777
  class FloatingButtonTrigger < Trigger
1271
1778
 
1272
1779
  def initialize(h={})
@@ -1290,6 +1797,8 @@ class FloatingButtonTrigger < Trigger
1290
1797
 
1291
1798
  end
1292
1799
 
1800
+ # Category: User Input
1801
+ #
1293
1802
  class ShortcutTrigger < Trigger
1294
1803
 
1295
1804
  def initialize(h={})
@@ -1303,6 +1812,8 @@ class ShortcutTrigger < Trigger
1303
1812
 
1304
1813
  end
1305
1814
 
1815
+ # Category: User Input
1816
+ #
1306
1817
  class VolumeButtonTrigger < Trigger
1307
1818
 
1308
1819
  def initialize(h={})
@@ -1320,6 +1831,8 @@ class VolumeButtonTrigger < Trigger
1320
1831
 
1321
1832
  end
1322
1833
 
1834
+ # Category: User Input
1835
+ #
1323
1836
  class MediaButtonPressedTrigger < Trigger
1324
1837
 
1325
1838
  def initialize(h={})
@@ -1335,6 +1848,8 @@ class MediaButtonPressedTrigger < Trigger
1335
1848
 
1336
1849
  end
1337
1850
 
1851
+ # Category: User Input
1852
+ #
1338
1853
  class SwipeTrigger < Trigger
1339
1854
 
1340
1855
  def initialize(h={})
@@ -1357,14 +1872,30 @@ class Action < MacroObject
1357
1872
  def initialize(h={})
1358
1873
  super(h)
1359
1874
  end
1875
+
1876
+ def invoke(s='')
1877
+ "%s/%s: %s" % [@group, @type, s]
1878
+ end
1360
1879
 
1361
1880
  end
1362
1881
 
1363
1882
 
1883
+ class LocationAction < Action
1884
+
1885
+ def initialize(h={})
1886
+ super(h)
1887
+ @group = 'location'
1888
+ end
1889
+
1890
+ end
1364
1891
 
1365
- class ShareLocationAction < Action
1892
+ # Category: Location
1893
+ #
1894
+ class ShareLocationAction < LocationAction
1366
1895
 
1367
1896
  def initialize(h={})
1897
+
1898
+ super()
1368
1899
 
1369
1900
  options = {
1370
1901
  email: '',
@@ -1382,39 +1913,19 @@ class ShareLocationAction < Action
1382
1913
 
1383
1914
  end
1384
1915
 
1385
- class UDPCommandAction < Action
1386
-
1387
- def initialize(h={})
1388
-
1389
- options = {
1390
- destination: '',
1391
- message: '',
1392
- port: 1024
1393
- }
1394
-
1395
- super(options.merge h)
1396
-
1397
- end
1398
-
1399
- end
1400
-
1401
- class UDPCommandAction < Action
1402
1916
 
1917
+ class ApplicationAction < Action
1918
+
1403
1919
  def initialize(h={})
1404
-
1405
- options = {
1406
- destination: '',
1407
- message: '',
1408
- port: 1024
1409
- }
1410
-
1411
- super(options.merge h)
1412
-
1920
+ super(h)
1921
+ @group = 'application'
1413
1922
  end
1414
-
1923
+
1415
1924
  end
1416
1925
 
1417
- class LaunchActivityAction < Action
1926
+ # Category: Applications
1927
+ #
1928
+ class LaunchActivityAction < ApplicationAction
1418
1929
 
1419
1930
  def initialize(h={})
1420
1931
 
@@ -1431,7 +1942,9 @@ class LaunchActivityAction < Action
1431
1942
 
1432
1943
  end
1433
1944
 
1434
- class KillBackgroundAppAction < Action
1945
+ # Category: Applications
1946
+ #
1947
+ class KillBackgroundAppAction < ApplicationAction
1435
1948
 
1436
1949
  def initialize(h={})
1437
1950
 
@@ -1446,7 +1959,9 @@ class KillBackgroundAppAction < Action
1446
1959
 
1447
1960
  end
1448
1961
 
1449
- class OpenWebPageAction < Action
1962
+ # Category: Applications
1963
+ #
1964
+ class OpenWebPageAction < ApplicationAction
1450
1965
 
1451
1966
  def initialize(h={})
1452
1967
 
@@ -1464,12 +1979,24 @@ class OpenWebPageAction < Action
1464
1979
 
1465
1980
  end
1466
1981
 
1467
- class UploadPhotoAction < Action
1468
1982
 
1983
+ class CameraAction < Action
1984
+
1469
1985
  def initialize(h={})
1986
+ super(h)
1987
+ @group = 'camera'
1988
+ end
1989
+
1990
+ end
1470
1991
 
1471
- options = {
1472
- option: 'Via Intent',
1992
+ # Category: Camera/Photo
1993
+ #
1994
+ class UploadPhotoAction < CameraAction
1995
+
1996
+ def initialize(h={})
1997
+
1998
+ options = {
1999
+ option: 'Via Intent',
1473
2000
  use_smtp_email: false
1474
2001
  }
1475
2002
 
@@ -1479,7 +2006,9 @@ class UploadPhotoAction < Action
1479
2006
 
1480
2007
  end
1481
2008
 
1482
- class TakePictureAction < Action
2009
+ # Category: Camera/Photo
2010
+ #
2011
+ class TakePictureAction < CameraAction
1483
2012
 
1484
2013
  def initialize(h={})
1485
2014
 
@@ -1494,10 +2023,31 @@ class TakePictureAction < Action
1494
2023
  super(options.merge h)
1495
2024
 
1496
2025
  end
2026
+
2027
+ def to_pc()
2028
+ camera = @h[:use_front_camera] ? :front : :back
2029
+ 'take_photo :' + camera.to_s
2030
+ end
2031
+
2032
+ def to_s()
2033
+ 'Take Picture'
2034
+ end
1497
2035
 
1498
2036
  end
1499
2037
 
1500
- class SetWifiAction < Action
2038
+
2039
+ class ConnectivityAction < Action
2040
+
2041
+ def initialize(h={})
2042
+ super(h)
2043
+ @group = 'connectivity'
2044
+ end
2045
+
2046
+ end
2047
+
2048
+ # Category: Connectivity
2049
+ #
2050
+ class SetWifiAction < ConnectivityAction
1501
2051
 
1502
2052
  def initialize(h={})
1503
2053
 
@@ -1513,7 +2063,9 @@ class SetWifiAction < Action
1513
2063
 
1514
2064
  end
1515
2065
 
1516
- class SetBluetoothAction < Action
2066
+ # Category: Connectivity
2067
+ #
2068
+ class SetBluetoothAction < ConnectivityAction
1517
2069
 
1518
2070
  def initialize(h={})
1519
2071
 
@@ -1528,7 +2080,9 @@ class SetBluetoothAction < Action
1528
2080
 
1529
2081
  end
1530
2082
 
1531
- class SetBluetoothAction < Action
2083
+ # Category: Connectivity
2084
+ #
2085
+ class SetBluetoothAction < ConnectivityAction
1532
2086
 
1533
2087
  def initialize(h={})
1534
2088
 
@@ -1543,7 +2097,9 @@ class SetBluetoothAction < Action
1543
2097
 
1544
2098
  end
1545
2099
 
1546
- class SendIntentAction < Action
2100
+ # Category: Connectivity
2101
+ #
2102
+ class SendIntentAction < ConnectivityAction
1547
2103
 
1548
2104
  def initialize(h={})
1549
2105
 
@@ -1569,7 +2125,19 @@ class SendIntentAction < Action
1569
2125
 
1570
2126
  end
1571
2127
 
1572
- class SetAlarmClockAction < Action
2128
+
2129
+ class DateTimeAction < Action
2130
+
2131
+ def initialize(h={})
2132
+ super(h)
2133
+ @group = 'datetime'
2134
+ end
2135
+
2136
+ end
2137
+
2138
+ # Category: Date/Time
2139
+ #
2140
+ class SetAlarmClockAction < DateTimeAction
1573
2141
 
1574
2142
  def initialize(h={})
1575
2143
 
@@ -1592,7 +2160,9 @@ class SetAlarmClockAction < Action
1592
2160
 
1593
2161
  end
1594
2162
 
1595
- class StopWatchAction < Action
2163
+ # Category: Date/Time
2164
+ #
2165
+ class StopWatchAction < DateTimeAction
1596
2166
 
1597
2167
  def initialize(h={})
1598
2168
 
@@ -1607,7 +2177,9 @@ class StopWatchAction < Action
1607
2177
 
1608
2178
  end
1609
2179
 
1610
- class SayTimeAction < Action
2180
+ # Category: Date/Time
2181
+ #
2182
+ class SayTimeAction < DateTimeAction
1611
2183
 
1612
2184
  def initialize(h={})
1613
2185
 
@@ -1618,10 +2190,36 @@ class SayTimeAction < Action
1618
2190
  super(options.merge h)
1619
2191
 
1620
2192
  end
2193
+
2194
+ def invoke()
2195
+ time = ($env and $env[:time]) ? $env[:time] : Time.now
2196
+ tformat = @h['12_hour'] ? "%-I:%M%P" : "%H:%M"
2197
+ super(time.strftime(tformat))
2198
+ end
2199
+
2200
+ def to_pc()
2201
+ 'say current_time()'
2202
+ end
2203
+
2204
+ def to_s()
2205
+ 'Say Current Time'
2206
+ end
2207
+
2208
+ end
2209
+
1621
2210
 
2211
+ class DeviceAction < Action
2212
+
2213
+ def initialize(h={})
2214
+ super(h)
2215
+ @group = 'device'
2216
+ end
2217
+
1622
2218
  end
1623
2219
 
1624
- class AndroidShortcutsAction < Action
2220
+ # Category: Device Actions
2221
+ #
2222
+ class AndroidShortcutsAction < DeviceAction
1625
2223
 
1626
2224
  def initialize(h={})
1627
2225
 
@@ -1635,7 +2233,9 @@ class AndroidShortcutsAction < Action
1635
2233
 
1636
2234
  end
1637
2235
 
1638
- class ClipboardAction < Action
2236
+ # Category: Device Actions
2237
+ #
2238
+ class ClipboardAction < DeviceAction
1639
2239
 
1640
2240
  def initialize(h={})
1641
2241
 
@@ -1649,7 +2249,9 @@ class ClipboardAction < Action
1649
2249
 
1650
2250
  end
1651
2251
 
1652
- class PressBackAction < Action
2252
+ # Category: Device Actions
2253
+ #
2254
+ class PressBackAction < DeviceAction
1653
2255
 
1654
2256
  def initialize(h={})
1655
2257
 
@@ -1662,7 +2264,9 @@ class PressBackAction < Action
1662
2264
 
1663
2265
  end
1664
2266
 
1665
- class SpeakTextAction < Action
2267
+ # Category: Device Actions
2268
+ #
2269
+ class SpeakTextAction < DeviceAction
1666
2270
 
1667
2271
  def initialize(h={})
1668
2272
 
@@ -1683,7 +2287,9 @@ class SpeakTextAction < Action
1683
2287
 
1684
2288
  end
1685
2289
 
1686
- class UIInteractionAction < Action
2290
+ # Category: Device Actions
2291
+ #
2292
+ class UIInteractionAction < DeviceAction
1687
2293
 
1688
2294
  def initialize(h={})
1689
2295
 
@@ -1698,7 +2304,9 @@ class UIInteractionAction < Action
1698
2304
 
1699
2305
  end
1700
2306
 
1701
- class VoiceSearchAction < Action
2307
+ # Category: Device Actions
2308
+ #
2309
+ class VoiceSearchAction < DeviceAction
1702
2310
 
1703
2311
  def initialize(h={})
1704
2312
 
@@ -1711,7 +2319,19 @@ class VoiceSearchAction < Action
1711
2319
 
1712
2320
  end
1713
2321
 
1714
- class ExpandCollapseStatusBarAction < Action
2322
+
2323
+ class DeviceSettingsAction < Action
2324
+
2325
+ def initialize(h={})
2326
+ super(h)
2327
+ @group = 'devicesettings'
2328
+ end
2329
+
2330
+ end
2331
+
2332
+ # Category: Device Settings
2333
+ #
2334
+ class ExpandCollapseStatusBarAction < DeviceSettingsAction
1715
2335
 
1716
2336
  def initialize(h={})
1717
2337
 
@@ -1725,7 +2345,9 @@ class ExpandCollapseStatusBarAction < Action
1725
2345
 
1726
2346
  end
1727
2347
 
1728
- class LaunchHomeScreenAction < Action
2348
+ # Category: Device Settings
2349
+ #
2350
+ class LaunchHomeScreenAction < DeviceSettingsAction
1729
2351
 
1730
2352
  def initialize(h={})
1731
2353
 
@@ -1738,7 +2360,9 @@ class LaunchHomeScreenAction < Action
1738
2360
 
1739
2361
  end
1740
2362
 
1741
- class CameraFlashLightAction < Action
2363
+ # Category: Device Settings
2364
+ #
2365
+ class CameraFlashLightAction < DeviceSettingsAction
1742
2366
 
1743
2367
  def initialize(h={})
1744
2368
 
@@ -1751,9 +2375,19 @@ class CameraFlashLightAction < Action
1751
2375
 
1752
2376
  end
1753
2377
 
2378
+ def to_pc()
2379
+ 'torch :on'
2380
+ end
2381
+
2382
+ def to_s()
2383
+ 'Torch On'
2384
+ end
2385
+
1754
2386
  end
1755
2387
 
1756
- class VibrateAction < Action
2388
+ # Category: Device Settings
2389
+ #
2390
+ class VibrateAction < DeviceSettingsAction
1757
2391
 
1758
2392
  def initialize(h={})
1759
2393
 
@@ -1767,7 +2401,9 @@ class VibrateAction < Action
1767
2401
 
1768
2402
  end
1769
2403
 
1770
- class SetAutoRotateAction < Action
2404
+ # Category: Device Settings
2405
+ #
2406
+ class SetAutoRotateAction < DeviceSettingsAction
1771
2407
 
1772
2408
  def initialize(h={})
1773
2409
 
@@ -1781,7 +2417,9 @@ class SetAutoRotateAction < Action
1781
2417
 
1782
2418
  end
1783
2419
 
1784
- class DayDreamAction < Action
2420
+ # Category: Device Settings
2421
+ #
2422
+ class DayDreamAction < DeviceSettingsAction
1785
2423
 
1786
2424
  def initialize(h={})
1787
2425
 
@@ -1794,7 +2432,9 @@ class DayDreamAction < Action
1794
2432
 
1795
2433
  end
1796
2434
 
1797
- class SetKeyboardAction < Action
2435
+ # Category: Device Settings
2436
+ #
2437
+ class SetKeyboardAction < DeviceSettingsAction
1798
2438
 
1799
2439
  def initialize(h={})
1800
2440
 
@@ -1807,7 +2447,9 @@ class SetKeyboardAction < Action
1807
2447
 
1808
2448
  end
1809
2449
 
1810
- class SetKeyguardAction < Action
2450
+ # Category: Device Settings
2451
+ #
2452
+ class SetKeyguardAction < DeviceSettingsAction
1811
2453
 
1812
2454
  def initialize(h={})
1813
2455
 
@@ -1821,7 +2463,9 @@ class SetKeyguardAction < Action
1821
2463
 
1822
2464
  end
1823
2465
 
1824
- class CarModeAction < Action
2466
+ # Category: Device Settings
2467
+ #
2468
+ class CarModeAction < DeviceSettingsAction
1825
2469
 
1826
2470
  def initialize(h={})
1827
2471
 
@@ -1835,7 +2479,9 @@ class CarModeAction < Action
1835
2479
 
1836
2480
  end
1837
2481
 
1838
- class ChangeKeyboardAction < Action
2482
+ # Category: Device Settings
2483
+ #
2484
+ class ChangeKeyboardAction < DeviceSettingsAction
1839
2485
 
1840
2486
  def initialize(h={})
1841
2487
 
@@ -1850,7 +2496,9 @@ class ChangeKeyboardAction < Action
1850
2496
 
1851
2497
  end
1852
2498
 
1853
- class SetWallpaperAction < Action
2499
+ # Category: Device Settings
2500
+ #
2501
+ class SetWallpaperAction < DeviceSettingsAction
1854
2502
 
1855
2503
  def initialize(h={})
1856
2504
 
@@ -1869,7 +2517,18 @@ class SetWallpaperAction < Action
1869
2517
 
1870
2518
  end
1871
2519
 
1872
- class OpenFileAction < Action
2520
+ class FileAction < Action
2521
+
2522
+ def initialize(h={})
2523
+ super(h)
2524
+ @group = 'file'
2525
+ end
2526
+
2527
+ end
2528
+
2529
+ # Category: Files
2530
+ #
2531
+ class OpenFileAction < FileAction
1873
2532
 
1874
2533
  def initialize(h={})
1875
2534
 
@@ -1886,7 +2545,19 @@ class OpenFileAction < Action
1886
2545
 
1887
2546
  end
1888
2547
 
1889
- class ForceLocationUpdateAction < Action
2548
+
2549
+ class LocationAction < Action
2550
+
2551
+ def initialize(h={})
2552
+ super(h)
2553
+ @group = 'location'
2554
+ end
2555
+
2556
+ end
2557
+
2558
+ # Category: Location
2559
+ #
2560
+ class ForceLocationUpdateAction < LocationAction
1890
2561
 
1891
2562
  def initialize(h={})
1892
2563
 
@@ -1899,7 +2570,9 @@ class ForceLocationUpdateAction < Action
1899
2570
 
1900
2571
  end
1901
2572
 
1902
- class ShareLocationAction < Action
2573
+ # Category: Location
2574
+ #
2575
+ class ShareLocationAction < LocationAction
1903
2576
 
1904
2577
  def initialize(h={})
1905
2578
 
@@ -1917,7 +2590,9 @@ class ShareLocationAction < Action
1917
2590
 
1918
2591
  end
1919
2592
 
1920
- class SetLocationUpdateRateAction < Action
2593
+ # Category: Location
2594
+ #
2595
+ class SetLocationUpdateRateAction < LocationAction
1921
2596
 
1922
2597
  def initialize(h={})
1923
2598
 
@@ -1932,7 +2607,18 @@ class SetLocationUpdateRateAction < Action
1932
2607
 
1933
2608
  end
1934
2609
 
1935
- class AddCalendarEntryAction < Action
2610
+ class LoggingAction < Action
2611
+
2612
+ def initialize(h={})
2613
+ super(h)
2614
+ @group = 'logging'
2615
+ end
2616
+
2617
+ end
2618
+
2619
+ # Category: Logging
2620
+ #
2621
+ class AddCalendarEntryAction < LoggingAction
1936
2622
 
1937
2623
  def initialize(h={})
1938
2624
 
@@ -1959,7 +2645,9 @@ class AddCalendarEntryAction < Action
1959
2645
 
1960
2646
  end
1961
2647
 
1962
- class LogAction < Action
2648
+ # Category: Logging
2649
+ #
2650
+ class LogAction < LoggingAction
1963
2651
 
1964
2652
  def initialize(h={})
1965
2653
 
@@ -1974,7 +2662,9 @@ class LogAction < Action
1974
2662
 
1975
2663
  end
1976
2664
 
1977
- class ClearLogAction < Action
2665
+ # Category: Logging
2666
+ #
2667
+ class ClearLogAction < LoggingAction
1978
2668
 
1979
2669
  def initialize(h={})
1980
2670
 
@@ -1988,24 +2678,18 @@ class ClearLogAction < Action
1988
2678
 
1989
2679
  end
1990
2680
 
1991
- class RecordMicrophoneAction < Action
1992
-
2681
+ class MediaAction < Action
2682
+
1993
2683
  def initialize(h={})
1994
-
1995
- options = {
1996
- path: '',
1997
- record_time_string: 'Until Cancelled',
1998
- recording_format: 0,
1999
- seconds_to_record_for: -1
2000
- }
2001
-
2002
- super(options.merge h)
2003
-
2684
+ super(h)
2685
+ @group = 'media'
2004
2686
  end
2005
-
2687
+
2006
2688
  end
2007
2689
 
2008
- class RecordMicrophoneAction < Action
2690
+ # Category: Media
2691
+ #
2692
+ class RecordMicrophoneAction < MediaAction
2009
2693
 
2010
2694
  def initialize(h={})
2011
2695
 
@@ -2022,7 +2706,9 @@ class RecordMicrophoneAction < Action
2022
2706
 
2023
2707
  end
2024
2708
 
2025
- class PlaySoundAction < Action
2709
+ # Category: Media
2710
+ #
2711
+ class PlaySoundAction < MediaAction
2026
2712
 
2027
2713
  def initialize(h={})
2028
2714
 
@@ -2038,7 +2724,18 @@ class PlaySoundAction < Action
2038
2724
  end
2039
2725
 
2040
2726
 
2041
- class SendEmailAction < Action
2727
+ class MessagingAction < Action
2728
+
2729
+ def initialize(h={})
2730
+ super(h)
2731
+ @group = 'messaging'
2732
+ end
2733
+
2734
+ end
2735
+
2736
+ # Category: Messaging
2737
+ #
2738
+ class SendEmailAction < MessagingAction
2042
2739
 
2043
2740
  def initialize(h={})
2044
2741
 
@@ -2058,7 +2755,9 @@ class SendEmailAction < Action
2058
2755
 
2059
2756
  end
2060
2757
 
2061
- class SendSMSAction < Action
2758
+ # Category: Messaging
2759
+ #
2760
+ class SendSMSAction < MessagingAction
2062
2761
 
2063
2762
  def initialize(h={})
2064
2763
 
@@ -2077,7 +2776,9 @@ class SendSMSAction < Action
2077
2776
 
2078
2777
  end
2079
2778
 
2080
- class UDPCommandAction < Action
2779
+ # Category: Messaging
2780
+ #
2781
+ class UDPCommandAction < MessagingAction
2081
2782
 
2082
2783
  def initialize(h={})
2083
2784
 
@@ -2093,7 +2794,19 @@ class UDPCommandAction < Action
2093
2794
 
2094
2795
  end
2095
2796
 
2096
- class ClearNotificationsAction < Action
2797
+
2798
+ class NotificationsAction < Action
2799
+
2800
+ def initialize(h={})
2801
+ super(h)
2802
+ @group = 'notifications'
2803
+ end
2804
+
2805
+ end
2806
+
2807
+ # Category: Notifications
2808
+ #
2809
+ class ClearNotificationsAction < NotificationsAction
2097
2810
 
2098
2811
  def initialize(h={})
2099
2812
 
@@ -2115,7 +2828,9 @@ class ClearNotificationsAction < Action
2115
2828
 
2116
2829
  end
2117
2830
 
2118
- class MessageDialogAction < Action
2831
+ # Category: Notifications
2832
+ #
2833
+ class MessageDialogAction < NotificationsAction
2119
2834
 
2120
2835
  def initialize(h={})
2121
2836
 
@@ -2140,7 +2855,9 @@ class MessageDialogAction < Action
2140
2855
 
2141
2856
  end
2142
2857
 
2143
- class AllowLEDNotificationLightAction < Action
2858
+ # Category: Notifications
2859
+ #
2860
+ class AllowLEDNotificationLightAction < NotificationsAction
2144
2861
 
2145
2862
  def initialize(h={})
2146
2863
 
@@ -2154,7 +2871,9 @@ class AllowLEDNotificationLightAction < Action
2154
2871
 
2155
2872
  end
2156
2873
 
2157
- class SetNotificationSoundAction < Action
2874
+ # Category: Notifications
2875
+ #
2876
+ class SetNotificationSoundAction < NotificationsAction
2158
2877
 
2159
2878
  def initialize(h={})
2160
2879
 
@@ -2168,7 +2887,9 @@ class SetNotificationSoundAction < Action
2168
2887
 
2169
2888
  end
2170
2889
 
2171
- class SetNotificationSoundAction < Action
2890
+ # Category: Notifications
2891
+ #
2892
+ class SetNotificationSoundAction < NotificationsAction
2172
2893
 
2173
2894
  def initialize(h={})
2174
2895
 
@@ -2182,7 +2903,9 @@ class SetNotificationSoundAction < Action
2182
2903
 
2183
2904
  end
2184
2905
 
2185
- class SetNotificationSoundAction < Action
2906
+ # Category: Notifications
2907
+ #
2908
+ class SetNotificationSoundAction < NotificationsAction
2186
2909
 
2187
2910
  def initialize(h={})
2188
2911
 
@@ -2196,7 +2919,9 @@ class SetNotificationSoundAction < Action
2196
2919
 
2197
2920
  end
2198
2921
 
2199
- class NotificationAction < Action
2922
+ # Category: Notifications
2923
+ #
2924
+ class NotificationAction < NotificationsAction
2200
2925
 
2201
2926
  def initialize(h={})
2202
2927
 
@@ -2220,7 +2945,9 @@ class NotificationAction < Action
2220
2945
 
2221
2946
  end
2222
2947
 
2223
- class ToastAction < Action
2948
+ # Category: Notifications
2949
+ #
2950
+ class ToastAction < NotificationsAction
2224
2951
 
2225
2952
  def initialize(h={})
2226
2953
 
@@ -2243,10 +2970,34 @@ class ToastAction < Action
2243
2970
  super(options.merge h)
2244
2971
 
2245
2972
  end
2973
+
2974
+ def invoke()
2975
+ super(@h[:message_text])
2976
+ end
2977
+
2978
+ def to_pc()
2979
+ "popup_message '%s'" % @h[:message_text]
2980
+ end
2981
+
2982
+ def to_s()
2983
+ "Popup Message '%s'" % @h[:message_text]
2984
+ end
2985
+
2986
+ end
2987
+
2246
2988
 
2989
+ class PhoneAction < Action
2990
+
2991
+ def initialize(h={})
2992
+ super(h)
2993
+ @group = 'phone'
2994
+ end
2995
+
2247
2996
  end
2248
2997
 
2249
- class AnswerCallAction < Action
2998
+ # Category: Phone
2999
+ #
3000
+ class AnswerCallAction < PhoneAction
2250
3001
 
2251
3002
  def initialize(h={})
2252
3003
 
@@ -2260,7 +3011,9 @@ class AnswerCallAction < Action
2260
3011
 
2261
3012
  end
2262
3013
 
2263
- class ClearCallLogAction < Action
3014
+ # Category: Phone
3015
+ #
3016
+ class ClearCallLogAction < PhoneAction
2264
3017
 
2265
3018
  def initialize(h={})
2266
3019
 
@@ -2276,7 +3029,9 @@ class ClearCallLogAction < Action
2276
3029
 
2277
3030
  end
2278
3031
 
2279
- class OpenCallLogAction < Action
3032
+ # Category: Phone
3033
+ #
3034
+ class OpenCallLogAction < PhoneAction
2280
3035
 
2281
3036
  def initialize(h={})
2282
3037
 
@@ -2289,7 +3044,9 @@ class OpenCallLogAction < Action
2289
3044
 
2290
3045
  end
2291
3046
 
2292
- class RejectCallAction < Action
3047
+ # Category: Phone
3048
+ #
3049
+ class RejectCallAction < PhoneAction
2293
3050
 
2294
3051
  def initialize(h={})
2295
3052
 
@@ -2302,7 +3059,9 @@ class RejectCallAction < Action
2302
3059
 
2303
3060
  end
2304
3061
 
2305
- class MakeCallAction < Action
3062
+ # Category: Phone
3063
+ #
3064
+ class MakeCallAction < PhoneAction
2306
3065
 
2307
3066
  def initialize(h={})
2308
3067
 
@@ -2317,7 +3076,10 @@ class MakeCallAction < Action
2317
3076
 
2318
3077
  end
2319
3078
 
2320
- class SetRingtoneAction < Action
3079
+
3080
+ # Category: Phone
3081
+ #
3082
+ class SetRingtoneAction < PhoneAction
2321
3083
 
2322
3084
  def initialize(h={})
2323
3085
 
@@ -2331,7 +3093,18 @@ class SetRingtoneAction < Action
2331
3093
 
2332
3094
  end
2333
3095
 
2334
- class SetBrightnessAction < Action
3096
+ class ScreenAction < Action
3097
+
3098
+ def initialize(h={})
3099
+ super(h)
3100
+ @group = 'screen'
3101
+ end
3102
+
3103
+ end
3104
+
3105
+ # Category: Screen
3106
+ #
3107
+ class SetBrightnessAction < ScreenAction
2335
3108
 
2336
3109
  def initialize(h={})
2337
3110
 
@@ -2347,7 +3120,9 @@ class SetBrightnessAction < Action
2347
3120
 
2348
3121
  end
2349
3122
 
2350
- class ForceScreenRotationAction < Action
3123
+ # Category: Screen
3124
+ #
3125
+ class ForceScreenRotationAction < ScreenAction
2351
3126
 
2352
3127
  def initialize(h={})
2353
3128
 
@@ -2361,7 +3136,9 @@ class ForceScreenRotationAction < Action
2361
3136
 
2362
3137
  end
2363
3138
 
2364
- class ScreenOnAction < Action
3139
+ # Category: Screen
3140
+ #
3141
+ class ScreenOnAction < ScreenAction
2365
3142
 
2366
3143
  def initialize(h={})
2367
3144
 
@@ -2378,7 +3155,9 @@ class ScreenOnAction < Action
2378
3155
 
2379
3156
  end
2380
3157
 
2381
- class DimScreenAction < Action
3158
+ # Category: Screen
3159
+ #
3160
+ class DimScreenAction < ScreenAction
2382
3161
 
2383
3162
  def initialize(h={})
2384
3163
 
@@ -2393,7 +3172,9 @@ class DimScreenAction < Action
2393
3172
 
2394
3173
  end
2395
3174
 
2396
- class KeepAwakeAction < Action
3175
+ # Category: Screen
3176
+ #
3177
+ class KeepAwakeAction < ScreenAction
2397
3178
 
2398
3179
  def initialize(h={})
2399
3180
 
@@ -2410,7 +3191,9 @@ class KeepAwakeAction < Action
2410
3191
 
2411
3192
  end
2412
3193
 
2413
- class SetScreenTimeoutAction < Action
3194
+ # Category: Screen
3195
+ #
3196
+ class SetScreenTimeoutAction < ScreenAction
2414
3197
 
2415
3198
  def initialize(h={})
2416
3199
 
@@ -2427,8 +3210,18 @@ class SetScreenTimeoutAction < Action
2427
3210
  end
2428
3211
 
2429
3212
 
3213
+ class VolumeAction < Action
3214
+
3215
+ def initialize(h={})
3216
+ super(h)
3217
+ @group = 'volume'
3218
+ end
3219
+
3220
+ end
2430
3221
 
2431
- class SilentModeVibrateOffAction < Action
3222
+ # Category: Volume
3223
+ #
3224
+ class SilentModeVibrateOffAction < VolumeAction
2432
3225
 
2433
3226
  def initialize(h={})
2434
3227
 
@@ -2442,7 +3235,9 @@ class SilentModeVibrateOffAction < Action
2442
3235
 
2443
3236
  end
2444
3237
 
2445
- class SetVibrateAction < Action
3238
+ # Category: Volume
3239
+ #
3240
+ class SetVibrateAction < VolumeAction
2446
3241
 
2447
3242
  def initialize(h={})
2448
3243
 
@@ -2457,7 +3252,9 @@ class SetVibrateAction < Action
2457
3252
 
2458
3253
  end
2459
3254
 
2460
- class VolumeIncrementDecrementAction < Action
3255
+ # Category: Volume
3256
+ #
3257
+ class VolumeIncrementDecrementAction < VolumeAction
2461
3258
 
2462
3259
  def initialize(h={})
2463
3260
 
@@ -2471,7 +3268,9 @@ class VolumeIncrementDecrementAction < Action
2471
3268
 
2472
3269
  end
2473
3270
 
2474
- class SpeakerPhoneAction < Action
3271
+ # Category: Volume
3272
+ #
3273
+ class SpeakerPhoneAction < VolumeAction
2475
3274
 
2476
3275
  def initialize(h={})
2477
3276
 
@@ -2486,8 +3285,9 @@ class SpeakerPhoneAction < Action
2486
3285
 
2487
3286
  end
2488
3287
 
2489
-
2490
- class SetVolumeAction < Action
3288
+ # Category: Volume
3289
+ #
3290
+ class SetVolumeAction < VolumeAction
2491
3291
 
2492
3292
  def initialize(h={})
2493
3293
 
@@ -2510,5 +3310,917 @@ class Constraint < MacroObject
2510
3310
  def initialize(h={})
2511
3311
  super(h)
2512
3312
  end
3313
+
3314
+ def match?(detail={}, model=nil)
3315
+
3316
+ detail.select {|k,v| @h.include? k }.all? {|key,value| @h[key] == value}
3317
+
3318
+ end
3319
+
3320
+ #def to_s()
3321
+ # ''
3322
+ #end
3323
+
3324
+ protected
3325
+
3326
+ def toggle_match?(key, val)
3327
+
3328
+ if @h[key] == true and val == key.to_s then
3329
+ true
3330
+ elsif @h[key] == false and val != key.to_s
3331
+ true
3332
+ else
3333
+ false
3334
+ end
3335
+
3336
+ end
3337
+
3338
+ end
3339
+
3340
+ class TimeOfDayConstraint < Constraint
3341
+
3342
+ def initialize(h={})
3343
+
3344
+ options = {
3345
+ end_hour: 8,
3346
+ end_minute: 0,
3347
+ start_hour: 22,
3348
+ start_minute: 0
3349
+ }
3350
+
3351
+ super(options.merge h)
3352
+
3353
+ end
3354
+
3355
+ end
3356
+
3357
+ # Category: Battery/Power
3358
+ #
3359
+ class BatteryLevelConstraint < Constraint
3360
+
3361
+ def initialize(h={})
3362
+
3363
+ options = {
3364
+ battery_level: 23,
3365
+ equals: false,
3366
+ greater_than: false
3367
+ }
3368
+
3369
+ super(options.merge h)
3370
+
3371
+ end
3372
+
3373
+ end
3374
+
3375
+ # Category: Battery/Power
3376
+ #
3377
+ class BatterySaverStateConstraint < Constraint
3378
+
3379
+ def initialize(h={})
3380
+
3381
+ options = {
3382
+ option: 0
3383
+ }
3384
+
3385
+ super(options.merge h)
3386
+
3387
+ end
3388
+
3389
+ end
3390
+
3391
+ # Category: Battery/Power
3392
+ #
3393
+ class BatteryTemperatureConstraint < Constraint
3394
+
3395
+ def initialize(h={})
3396
+
3397
+ options = {
3398
+ equals: false,
3399
+ greater_than: false,
3400
+ temperature: 30
3401
+ }
3402
+
3403
+ super(options.merge h)
3404
+
3405
+ end
3406
+
3407
+ end
3408
+
3409
+ # Category: Battery/Power
3410
+ #
3411
+ class ExternalPowerConstraint < Constraint
3412
+
3413
+ def initialize(h={})
3414
+
3415
+ options = {
3416
+ external_power: true,
3417
+ power_connected_options: [false, true, false]
3418
+ }
3419
+
3420
+ super(options.merge h)
3421
+
3422
+ end
3423
+
3424
+ end
3425
+
3426
+ # Category: Connectivity
3427
+ #
3428
+ class BluetoothConstraint < Constraint
3429
+
3430
+ def initialize(h={})
3431
+
3432
+ options = {
3433
+ any_device: false,
3434
+ bt_state: 0,
3435
+ device_name: 'Any Device'
3436
+ }
3437
+
3438
+ super(options.merge h)
3439
+
3440
+ end
3441
+
3442
+ end
3443
+
3444
+ # Category: Connectivity
3445
+ #
3446
+ class GPSEnabledConstraint < Constraint
3447
+
3448
+ def initialize(h={})
3449
+
3450
+ options = {
3451
+ enabled: true
3452
+ }
3453
+
3454
+ super(options.merge h)
3455
+
3456
+ end
3457
+
3458
+ end
3459
+
3460
+ # Category: Connectivity
3461
+ #
3462
+ class LocationModeConstraint < Constraint
3463
+
3464
+ def initialize(h={})
3465
+
3466
+ options = {
3467
+ options: [false, false, false, true]
3468
+ }
3469
+
3470
+ super(options.merge h)
3471
+
3472
+ end
3473
+
3474
+ end
3475
+
3476
+ # Category: Connectivity
3477
+ #
3478
+ class SignalOnOffConstraint < Constraint
3479
+
3480
+ def initialize(h={})
3481
+
3482
+ options = {
3483
+ option: 0
3484
+ }
3485
+
3486
+ super(options.merge h)
3487
+
3488
+ end
3489
+
3490
+ end
3491
+
3492
+ # Category: Connectivity
3493
+ #
3494
+ class WifiConstraint < Constraint
3495
+
3496
+ def initialize(h={})
3497
+
3498
+ options = {
3499
+ ssid_list: [],
3500
+ wifi_state: 0
3501
+ }
3502
+
3503
+ super(options.merge h)
3504
+
3505
+ end
3506
+
3507
+ end
3508
+
3509
+ # Category: Connectivity
3510
+ #
3511
+ class CellTowerConstraint < Constraint
3512
+
3513
+ def initialize(h={})
3514
+
3515
+ options = {
3516
+ cell_group_name: 'test group',
3517
+ cell_ids: ["524,14,41070731"],
3518
+ in_range: true
3519
+ }
3520
+
3521
+ super(options.merge h)
3522
+
3523
+ end
3524
+
3525
+ end
3526
+
3527
+ # Category: Connectivity
3528
+ #
3529
+ class IsRoamingConstraint < Constraint
3530
+
3531
+ def initialize(h={})
3532
+
3533
+ options = {
3534
+ is_roaming: true
3535
+ }
3536
+
3537
+ super(options.merge h)
3538
+
3539
+ end
3540
+
3541
+ end
3542
+
3543
+ # Category: Connectivity
3544
+ #
3545
+ class DataOnOffConstraint < Constraint
3546
+
3547
+ def initialize(h={})
3548
+
3549
+ options = {
3550
+ data_on: true
3551
+ }
3552
+
3553
+ super(options.merge h)
3554
+
3555
+ end
3556
+
3557
+ end
3558
+
3559
+ # Category: Connectivity
3560
+ #
3561
+ class WifiHotSpotConstraint < Constraint
3562
+
3563
+ def initialize(h={})
3564
+
3565
+ options = {
3566
+ check_connections: false,
3567
+ comparison_value: 0,
3568
+ connected_count: 0,
3569
+ enabled: true
3570
+ }
3571
+
3572
+ super(options.merge h)
3573
+
3574
+ end
3575
+
3576
+ end
3577
+
3578
+ # Category: Date/Time
3579
+ #
3580
+ class CalendarConstraint < Constraint
3581
+
3582
+ def initialize(h={})
3583
+
3584
+ options = {
3585
+ enable_regex: false,
3586
+ availability: 0,
3587
+ calendar_id: '1',
3588
+ calendar_name: 'PC Sync',
3589
+ detail_text: '',
3590
+ entry_set: true,
3591
+ ignore_all_day: false,
3592
+ title_text: ''
3593
+ }
3594
+
3595
+ super(options.merge h)
3596
+
3597
+ end
3598
+
3599
+ end
3600
+
3601
+ # Category: Date/Time
3602
+ #
3603
+ class DayOfWeekConstraint < Constraint
3604
+
3605
+ def initialize(h={})
3606
+
3607
+ options = {
3608
+ days_of_week: [false, false, true, false, false, false, false]
3609
+ }
3610
+
3611
+ super(options.merge h)
3612
+
3613
+ end
3614
+
3615
+ end
3616
+
3617
+ # Category: Date/Time
3618
+ #
3619
+ class TimeOfDayConstraint < Constraint
3620
+
3621
+ def initialize(h={})
3622
+
3623
+ options = {
3624
+ end_hour: 1,
3625
+ end_minute: 1,
3626
+ start_hour: 21,
3627
+ start_minute: 58
3628
+ }
3629
+
3630
+ super(options.merge h)
3631
+
3632
+ end
3633
+
3634
+ end
3635
+
3636
+ # Category: Date/Time
3637
+ #
3638
+ class DayOfMonthConstraint < Constraint
3639
+
3640
+ def initialize(h={})
3641
+
3642
+ options = {
3643
+ day_names: ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"],
3644
+ days_of_month: [false, false, false, false, false, false, false, true, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false, false]
3645
+ }
3646
+
3647
+ super(options.merge h)
3648
+
3649
+ end
3650
+
3651
+ end
3652
+
3653
+ # Category: Date/Time
3654
+ #
3655
+ class MonthOfYearConstraint < Constraint
3656
+
3657
+ def initialize(h={})
3658
+
3659
+ options = {
3660
+ months: [false, false, false, false, false, false, false, true, false, false, false, false]
3661
+ }
3662
+
3663
+ super(options.merge h)
3664
+
3665
+ end
3666
+
3667
+ end
3668
+
3669
+ # Category: Date/Time
3670
+ #
3671
+ class SunsetSunriseConstraint < Constraint
3672
+
3673
+ def initialize(h={})
3674
+
3675
+ options = {
3676
+ option: 0
3677
+ }
3678
+
3679
+ super(options.merge h)
3680
+
3681
+ end
3682
+
3683
+ end
3684
+
3685
+ # Category: Device State
3686
+ #
3687
+ class AirplaneModeConstraint < Constraint
3688
+
3689
+ def initialize(h={})
3690
+
3691
+ options = {
3692
+ enabled: true
3693
+ }
3694
+
3695
+ super(options.merge h)
3696
+
3697
+ end
3698
+
3699
+ def match?(detail={}, model=nil)
3700
+
3701
+ puts 'inside airplaneModeConstraint#match?' if $debug
3702
+
3703
+ if detail.has_key? :enabled then
3704
+
3705
+ puts 'detail has the key' if $debug
3706
+ super(detail)
3707
+
3708
+ elsif model
3709
+
3710
+ if $debug then
3711
+ puts 'checking the model'
3712
+ switch = model.connectivity.airplane_mode.switch
3713
+ puts 'switch: ' + switch.inspect
3714
+ end
3715
+
3716
+ toggle_match?(:enabled, switch)
3717
+
3718
+ end
3719
+
3720
+ end
3721
+
3722
+ def to_pc()
3723
+ status = @h[:enabled] ? 'enabled?' : 'disabled?'
3724
+ 'airplane_mode.' + status
3725
+ end
3726
+
3727
+ def to_s()
3728
+
3729
+ status = @h[:enabled] ? 'Enabled' : 'Disabled'
3730
+ 'Airplane Mode ' + status
3731
+
3732
+ end
3733
+
3734
+ end
3735
+
3736
+ # Category: Device State
3737
+ #
3738
+ class AutoRotateConstraint < Constraint
3739
+
3740
+ def initialize(h={})
3741
+
3742
+ options = {
3743
+ enabled: true
3744
+ }
3745
+
3746
+ super(options.merge h)
3747
+
3748
+ end
3749
+
3750
+ end
3751
+
3752
+ # Category: Device State
3753
+ #
3754
+ class DeviceLockedConstraint < Constraint
3755
+
3756
+ def initialize(h={})
3757
+
3758
+ options = {
3759
+ locked: true
3760
+ }
3761
+
3762
+ super(options.merge h)
3763
+
3764
+ end
3765
+
3766
+ end
3767
+
3768
+ # Category: Device State
3769
+ #
3770
+ class RoamingOnOffConstraint < Constraint
3771
+
3772
+ def initialize(h={})
3773
+
3774
+ options = {
3775
+ roaming_on: true
3776
+ }
3777
+
3778
+ super(options.merge h)
3779
+
3780
+ end
3781
+
3782
+ end
3783
+
3784
+ # Category: Device State
3785
+ #
3786
+ class TimeSinceBootConstraint < Constraint
3787
+
3788
+ def initialize(h={})
3789
+
3790
+ options = {
3791
+ less_than: true,
3792
+ time_period_seconds: 10921
3793
+ }
3794
+
3795
+ super(options.merge h)
3796
+
3797
+ end
3798
+
3799
+ end
3800
+
3801
+ # Category: Device State
3802
+ #
3803
+ class AutoSyncConstraint < Constraint
3804
+
3805
+ def initialize(h={})
3806
+
3807
+ options = {
3808
+ enabled: false
3809
+ }
3810
+
3811
+ super(options.merge h)
3812
+
3813
+ end
3814
+
3815
+ end
3816
+
3817
+ # Category: Device State
3818
+ #
3819
+ class NFCStateConstraint < Constraint
3820
+
3821
+ def initialize(h={})
3822
+
3823
+ options = {
3824
+ enabled: true
3825
+ }
3826
+
3827
+ super(options.merge h)
3828
+
3829
+ end
3830
+
3831
+ end
3832
+
3833
+ # Category: Device State
3834
+ #
3835
+ class IsRootedConstraint < Constraint
3836
+
3837
+ def initialize(h={})
3838
+
3839
+ options = {
3840
+ rooted: true
3841
+ }
3842
+
3843
+ super(options.merge h)
3844
+
3845
+ end
3846
+
3847
+ end
3848
+
3849
+ # Category: Device State
3850
+ #
3851
+ class VpnConstraint < Constraint
3852
+
3853
+ def initialize(h={})
3854
+
3855
+ options = {
3856
+ option: 0
3857
+ }
3858
+
3859
+ super(options.merge h)
3860
+
3861
+ end
3862
+
3863
+ end
3864
+
3865
+ # Category: MacroDroid Specific
3866
+ #
3867
+ class MacroEnabledConstraint < Constraint
3868
+
3869
+ def initialize(h={})
3870
+
3871
+ options = {
3872
+ enabled: true,
3873
+ macro_ids: [-8016812002629322290],
3874
+ macro_names: ["Intruder photo "]
3875
+ }
3876
+
3877
+ super(options.merge h)
3878
+
3879
+ end
3880
+
3881
+ end
3882
+
3883
+ # Category: MacroDroid Specific
3884
+ #
3885
+ class ModeConstraint < Constraint
3886
+
3887
+ def initialize(h={})
3888
+
3889
+ options = {
3890
+ mode: 'Away',
3891
+ mode_selected: true
3892
+ }
3893
+
3894
+ super(options.merge h)
3895
+
3896
+ end
3897
+
3898
+ end
3899
+
3900
+ # Category: MacroDroid Specific
3901
+ #
3902
+ class TriggerThatInvokedConstraint < Constraint
3903
+
3904
+ def initialize(h={})
3905
+
3906
+ options = {
3907
+ not: false,
3908
+ si_guid_that_invoked: -4951291100076165433,
3909
+ trigger_name: 'Shake Device'
3910
+ }
3911
+
3912
+ super(options.merge h)
3913
+
3914
+ end
3915
+
3916
+ end
3917
+
3918
+ # Category: MacroDroid Specific
3919
+ #
3920
+ class LastRunTimeConstraint < Constraint
3921
+
3922
+ def initialize(h={})
3923
+
3924
+ options = {
3925
+ check_this_macro: false,
3926
+ invoked: true,
3927
+ macro_ids: [-6922688338672048267],
3928
+ macro_names: ["Opendoor"],
3929
+ time_period_seconds: 7260
3930
+ }
3931
+
3932
+ super(options.merge h)
3933
+
3934
+ end
3935
+
3936
+ end
3937
+
3938
+ # Category: Media
3939
+ #
3940
+ class HeadphonesConnectionConstraint < Constraint
3941
+
3942
+ def initialize(h={})
3943
+
3944
+ options = {
3945
+ connected: true
3946
+ }
3947
+
3948
+ super(options.merge h)
3949
+
3950
+ end
3951
+
3952
+ end
3953
+
3954
+ # Category: Media
3955
+ #
3956
+ class MusicActiveConstraint < Constraint
3957
+
3958
+ def initialize(h={})
3959
+
3960
+ options = {
3961
+ music_active: true
3962
+ }
3963
+
3964
+ super(options.merge h)
3965
+
3966
+ end
3967
+
3968
+ end
3969
+
3970
+ # Category: Notification
3971
+ #
3972
+ class NotificationPresentConstraint < Constraint
3973
+
3974
+ def initialize(h={})
3975
+
3976
+ options = {
3977
+ enable_regex: false,
3978
+ application_name_list: ["All applications"],
3979
+ exact_match: false,
3980
+ excludes: false,
3981
+ excludes_apps: -1,
3982
+ option: 0,
3983
+ package_name_list: ["allApplications"],
3984
+ text_content: ''
3985
+ }
3986
+
3987
+ super(options.merge h)
3988
+
3989
+ end
3990
+
3991
+ end
3992
+
3993
+ # Category: Notification
3994
+ #
3995
+ class PriorityModeConstraint < Constraint
3996
+
3997
+ def initialize(h={})
3998
+
3999
+ options = {
4000
+ in_mode: true,
4001
+ selected_index: 0
4002
+ }
4003
+
4004
+ super(options.merge h)
4005
+
4006
+ end
4007
+
4008
+ end
4009
+
4010
+ # Category: Notification
4011
+ #
4012
+ class NotificationVolumeConstraint < Constraint
4013
+
4014
+ def initialize(h={})
4015
+
4016
+ options = {
4017
+ option: 1
4018
+ }
4019
+
4020
+ super(options.merge h)
4021
+
4022
+ end
4023
+
4024
+ end
4025
+
4026
+ # Category: Phone
4027
+ #
4028
+ class InCallConstraint < Constraint
4029
+
4030
+ def initialize(h={})
4031
+
4032
+ options = {
4033
+ in_call: true
4034
+ }
4035
+
4036
+ super(options.merge h)
4037
+
4038
+ end
4039
+
4040
+ end
4041
+
4042
+ # Category: Phone
4043
+ #
4044
+ class PhoneRingingConstraint < Constraint
4045
+
4046
+ def initialize(h={})
4047
+
4048
+ options = {
4049
+ ringing: true
4050
+ }
4051
+
4052
+ super(options.merge h)
4053
+
4054
+ end
4055
+
4056
+ end
4057
+
4058
+ # Category: Screen and Speaker
4059
+ #
4060
+ class BrightnessConstraint < Constraint
4061
+
4062
+ def initialize(h={})
4063
+
4064
+ options = {
4065
+ brightness: 35,
4066
+ equals: false,
4067
+ force_pie_mode: false,
4068
+ greater_than: false,
4069
+ is_auto_brightness: false
4070
+ }
4071
+
4072
+ super(options.merge h)
4073
+
4074
+ end
4075
+
4076
+ end
4077
+
4078
+ # Category: Screen and Speaker
4079
+ #
4080
+ class VolumeConstraint < Constraint
4081
+
4082
+ def initialize(h={})
4083
+
4084
+ options = {
4085
+ option: 0
4086
+ }
4087
+
4088
+ super(options.merge h)
4089
+
4090
+ end
4091
+
4092
+ end
4093
+
4094
+ # Category: Screen and Speaker
4095
+ #
4096
+ class SpeakerPhoneConstraint < Constraint
4097
+
4098
+ def initialize(h={})
4099
+
4100
+ options = {
4101
+ enabled: true
4102
+ }
4103
+
4104
+ super(options.merge h)
4105
+
4106
+ end
4107
+
4108
+ end
4109
+
4110
+ # Category: Screen and Speaker
4111
+ #
4112
+ class DarkThemeConstraint < Constraint
4113
+
4114
+ def initialize(h={})
4115
+
4116
+ options = {
4117
+ option: 0
4118
+ }
4119
+
4120
+ super(options.merge h)
4121
+
4122
+ end
4123
+
4124
+ end
4125
+
4126
+ # Category: Screen and Speaker
4127
+ #
4128
+ class ScreenOnOffConstraint < Constraint
4129
+
4130
+ def initialize(h={})
4131
+
4132
+ options = {
4133
+ a: true,
4134
+ screen_on: true
4135
+ }
4136
+
4137
+ super(options.merge h)
4138
+
4139
+ end
4140
+
4141
+ end
4142
+
4143
+ # Category: Screen and Speaker
4144
+ #
4145
+ class VolumeLevelConstraint < Constraint
4146
+
4147
+ def initialize(h={})
4148
+
4149
+ options = {
4150
+ comparison: 0,
4151
+ stream_index_array: [false, true, false, false, false, false, false],
4152
+ volume: 42
4153
+ }
4154
+
4155
+ super(options.merge h)
4156
+
4157
+ end
4158
+
4159
+ end
4160
+
4161
+ # Category: Sensors
4162
+ #
4163
+ class FaceUpDownConstraint < Constraint
4164
+
4165
+ def initialize(h={})
4166
+
4167
+ options = {
4168
+ option: -1,
4169
+ selected_options: [true, false, true, false, false, false]
4170
+ }
4171
+
4172
+ super(options.merge h)
4173
+
4174
+ end
4175
+
4176
+ end
4177
+
4178
+ # Category: Sensors
4179
+ #
4180
+ class LightLevelConstraint < Constraint
4181
+
4182
+ def initialize(h={})
4183
+
4184
+ options = {
4185
+ light_level: -1,
4186
+ light_level_float: 5000.0,
4187
+ option: 1
4188
+ }
4189
+
4190
+ super(options.merge h)
4191
+
4192
+ end
4193
+
4194
+ end
4195
+
4196
+ # Category: Sensors
4197
+ #
4198
+ class DeviceOrientationConstraint < Constraint
4199
+
4200
+ def initialize(h={})
4201
+
4202
+ options = {
4203
+ portrait: true
4204
+ }
4205
+
4206
+ super(options.merge h)
4207
+
4208
+ end
4209
+
4210
+ end
4211
+
4212
+ # Category: Sensors
4213
+ #
4214
+ class ProximitySensorConstraint < Constraint
4215
+
4216
+ def initialize(h={})
4217
+
4218
+ options = {
4219
+ near: true
4220
+ }
4221
+
4222
+ super(options.merge h)
4223
+
4224
+ end
2513
4225
 
2514
4226
  end