ruby-macrodroid 0.7.0 → 0.7.5

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: f4d111f7d953dba3eeb6940e3e1f31af4410765fbd4c739de9b53c0d84bac137
4
- data.tar.gz: 2d8a574b96647abb40194e3885f38153e1de3b50d3f8f86541698b766981f9d8
3
+ metadata.gz: 34125d78f367eeff973953934d50436f964bb073ffef48591ce2f09012fc2a01
4
+ data.tar.gz: 5bb75988f4d979cb80f57c912d8448837848b3d4a5b34a3e524f8fdad3ff62de
5
5
  SHA512:
6
- metadata.gz: 5184ff198c42f2e75dbfd232a9b5e7ef18bd37e0484aa697983f9cf950e0811659cbdc6936d1b5f622f719de1b8bee9ba7c10c5ec22e06be5aac34530ed5d4a2
7
- data.tar.gz: 8f3020868a714825f8e06a04b461761039048e86ecbc22cd70413cbf860bfebb4b61d9c10315530037d1248dcfc3dc8d2d0ccb7be62fe25a625a5045c3a2bade
6
+ metadata.gz: 223c51744d7dde5e4a7130d3141696df1dc4a8cda0227e0f11324c3ac71e53226c95e8acd1ae27ed62ec46d8c1c8b81060e9135d923285e59e89572985dd146c
7
+ data.tar.gz: 39490d0ceeb2bfce5c413607d1ea5a1ca87e8942bdcbfd51ecf32f2baac1a1c6fec7bf8909eda8716cc6b397ef847d4c15de6eca9892f9d244f1724d4956a1fe
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -112,6 +112,7 @@ require 'rowx'
112
112
  require 'uuid'
113
113
  require 'glw'
114
114
  require 'geozone'
115
+ require 'subunit'
115
116
  require 'rxfhelper'
116
117
  require 'chronic_cron'
117
118
 
@@ -134,6 +135,12 @@ class TriggersNlp
134
135
  end
135
136
 
136
137
  def triggers(params)
138
+
139
+ # e.g. at 7:30pm daily
140
+ get /^(?:at )?(\d+:\d+(?:[ap]m)?) daily/i do |time, days|
141
+ [TimerTrigger, {time: time,
142
+ days: %w(Mon Tue Wed Thu Fri Sat Sun).join(', ')}]
143
+ end
137
144
 
138
145
  get /^(?:at )?(\d+:\d+(?:[ap]m)?) (?:on )?(.*)/i do |time, days|
139
146
  [TimerTrigger, {time: time, days: days}]
@@ -142,7 +149,7 @@ class TriggersNlp
142
149
  # time.is? 'at 18:30pm on Mon or Tue'
143
150
  get /^time.is\? ['"](?:at )?(\d+:\d+(?:[ap]m)?) (?:on )?(.*)['"]/i do |time, days|
144
151
  [TimerTrigger, {time: time, days: days.gsub(' or ',', ')}]
145
- end
152
+ end
146
153
 
147
154
  get /^shake[ _]device\??$/i do
148
155
  [ShakeDeviceTrigger, {}]
@@ -177,7 +184,16 @@ class TriggersNlp
177
184
  get /^location (entered|exited) \(([^\)]+)/i do |direction, name|
178
185
  enter_area = direction.downcase.to_sym == :entered
179
186
  [GeofenceTrigger, {name: name, enter_area: enter_area}]
180
- end
187
+ end
188
+
189
+ # eg. Proximity Sensor (Near)
190
+ #
191
+ get /^Proximity Sensor \(([^\)]+)\)/i do |distance|
192
+
193
+ [ProximityTrigger, {distance: distance}]
194
+ end
195
+
196
+
181
197
 
182
198
  end
183
199
 
@@ -269,7 +285,33 @@ class ActionsNlp
269
285
  #
270
286
  get /webhook|HTTP GET/i do
271
287
  [OpenWebPageAction, {}]
272
- end
288
+ end
289
+
290
+ #a: Keep Device Awake Screen On Until Disabled
291
+ #
292
+ get /Keep Device Awake Screen On Until Disabled/i do
293
+ [KeepAwakeAction, {enabled: true, permanent: true, screen_option: 0}]
294
+ end
295
+
296
+
297
+ #a: Keep Device Awake Screen On 1h 1m 1s
298
+ #
299
+ get /Keep Device Awake Screen On ([^$]+)/i do |duration|
300
+
301
+ a = duration.split.map(&:to_i)
302
+ secs = Subunit.new(units={minutes:60, hours:60, seconds: 60}, a).to_i
303
+
304
+ h = {
305
+ permanent: true, screen_option: 0, seconds_to_stay_awake_for: secs
306
+ }
307
+ [KeepAwakeAction, h]
308
+ end
309
+
310
+ #a: Disable Keep Awake
311
+ #
312
+ get /Disable Keep Awake/i do
313
+ [KeepAwakeAction, {enabled: false, screen_option: 0}]
314
+ end
273
315
 
274
316
 
275
317
  end
@@ -361,9 +403,9 @@ class Macro
361
403
  attr_reader :local_variables, :triggers, :actions, :constraints, :guid
362
404
  attr_accessor :title, :description
363
405
 
364
- def initialize(name=nil, geofence: geofence, debug: false)
406
+ def initialize(name=nil, geofences: geofences, debug: false)
365
407
 
366
- @title, @geofence, @debug = name, geofence, debug
408
+ @title, @geofences, @debug = name, geofences, debug
367
409
 
368
410
  puts 'inside Macro#initialize' if @debug
369
411
 
@@ -518,7 +560,11 @@ class Macro
518
560
  puts 'found trigger ' + r.inspect if @debug
519
561
 
520
562
  if r then
521
- r[0].new(r[1])
563
+ if r[0] == GeofenceTrigger then
564
+ GeofenceTrigger.new(r[1], geofences: @geofences)
565
+ else
566
+ r[0].new(r[1])
567
+ end
522
568
  end
523
569
 
524
570
  end
@@ -619,18 +665,56 @@ EOF
619
665
 
620
666
  def to_s()
621
667
 
668
+ indent = 0
669
+ actions = @actions.map do |x|
670
+
671
+ s = x.to_s
672
+
673
+ r = if indent <= 0 then
674
+
675
+ "a: %s" % s
676
+
677
+ elsif indent > 0
678
+
679
+ if s =~ /^Else/ then
680
+ (' ' * (indent-1)) + "%s" % s
681
+ elsif s =~ /^End/
682
+ indent -= 1
683
+ (' ' * indent) + "%s" % s
684
+ else
685
+ (' ' * indent) + "%s" % s
686
+ end
687
+
688
+ end
689
+
690
+ if s =~ /^If/i then
691
+ if indent < 1 then
692
+ r = "a:\n %s" % s
693
+ indent += 1
694
+ else
695
+ r = (' ' * indent) + "%s" % s
696
+ end
697
+
698
+ indent += 1
699
+ end
700
+
701
+ r
702
+
703
+ end.join("\n")
704
+
622
705
  a = [
623
706
  'm: ' + @title,
624
707
  @triggers.map {|x| "t: %s" % x}.join("\n"),
625
- @actions.map {|x| "a: %s" % x}.join("\n"),
626
- @constraints.map {|x| "a: %s" % x}.join("\n")
708
+ actions
627
709
  ]
628
710
 
711
+ a << @constraints.map {|x| "c: %s" % x}.join("\n") if @constraints.any?
712
+
629
713
  if @description and @description.length >= 1 then
630
- a.insert(1, 'd: ' + @description)
714
+ a.insert(1, 'd: ' + @description.gsub(/\n/,"\n "))
631
715
  end
632
716
 
633
- a.join("\n")
717
+ a.join("\n") + "\n"
634
718
 
635
719
  end
636
720
 
@@ -638,11 +722,11 @@ EOF
638
722
 
639
723
  a = [
640
724
  'm: ' + @title,
641
- 't: ' + @triggers.map(&:to_s).join(", "),
642
- 'a: ' + @actions.map(&:to_s).join(", "),
725
+ 't: ' + @triggers.map(&:to_summary).join(", "),
726
+ 'a: ' + @actions.map(&:to_summary).join(", "),
643
727
  ]
644
728
 
645
- a << 'c: ' + @constraints.map(&:to_s).join(", ") if @constraints.any?
729
+ a << 'c: ' + @constraints.map(&:to_summary).join(", ") if @constraints.any?
646
730
 
647
731
  a.join("\n") + "\n"
648
732
 
@@ -662,7 +746,7 @@ EOF
662
746
 
663
747
  if klass == GeofenceTrigger then
664
748
  puts 'GeofenceTrigger found'.highlight if $debug
665
- klass.new(@geofence, h)
749
+ GeofenceTrigger.new(h, geofences: @geofences)
666
750
  else
667
751
  klass.new h
668
752
  end
@@ -679,12 +763,14 @@ class MacroDroid
679
763
  using ColouredText
680
764
  using Params
681
765
 
682
- attr_reader :macros, :geofence
766
+ attr_reader :macros, :geofences, :yaml
683
767
 
684
768
  def initialize(obj=nil, debug: false)
685
769
 
686
770
  @debug = debug
687
771
 
772
+ @geofences = {}
773
+
688
774
  if obj then
689
775
 
690
776
  raw_s, _ = RXFHelper.read(obj)
@@ -708,10 +794,25 @@ class MacroDroid
708
794
 
709
795
  puts 'before RowX.new' if @debug
710
796
 
711
- s2 = s.gsub(/^m:/,'macro:').gsub(/^t:/,'trigger:')\
712
- .gsub(/^a:/,'action:').gsub(/^c:/,'constraint:')
713
- xml = RowX.new(s2.gsub(/^#.*/,'')).to_xml
797
+ s2 = s.gsub(/^g:/,'geofence:').gsub(/^m:/,'macro:')\
798
+ .gsub(/^t:/,'trigger:').gsub(/^a:/,'action:')\
799
+ .gsub(/^c:/,'constraint:').gsub(/^#.*/,'')
800
+
801
+ raw_macros, raw_geofences = s2.split(/(?=^macro:)/,2).reverse
802
+
803
+ if raw_geofences then
804
+
805
+ geoxml = RowX.new(raw_geofences).to_xml
806
+
807
+ geodoc = Rexle.new(geoxml)
808
+ geofences = geodoc.root.xpath('item/geofence')
809
+ @geofences = fetch_geofences(geofences) if geofences.any?
810
+
811
+ end
812
+
813
+ xml = RowX.new(raw_macros).to_xml
714
814
  import_rowxml(xml)
815
+
715
816
  elsif s =~ /^# /
716
817
  xml = pc_to_xml(s)
717
818
  import_xml(xml)
@@ -721,8 +822,6 @@ class MacroDroid
721
822
 
722
823
  @h = build_h
723
824
 
724
-
725
-
726
825
  end
727
826
 
728
827
  else
@@ -777,7 +876,13 @@ class MacroDroid
777
876
 
778
877
  def to_h()
779
878
 
780
- @h.merge(macro_list: @macros.map(&:to_h)).to_camel_case
879
+ h = {
880
+ geofence_data: {
881
+ geofence_map: @geofences.map {|key, value| [key, value.to_h] }.to_h
882
+ },
883
+ macro_list: @macros.map(&:to_h)
884
+ }
885
+ @h.merge(h).to_camel_case
781
886
 
782
887
  end
783
888
 
@@ -788,7 +893,16 @@ class MacroDroid
788
893
  end
789
894
 
790
895
  def to_s()
791
- @macros.map(&:to_s).join("\n")
896
+
897
+ lines = []
898
+
899
+ if @geofences.any? then
900
+ lines << @geofences.map {|_, value| 'g: ' + value.to_s}.join("\n\n") + "\n"
901
+ end
902
+
903
+ lines << @macros.map(&:to_s).join("\n")
904
+ lines.join("\n")
905
+
792
906
  end
793
907
 
794
908
  def to_summary()
@@ -797,10 +911,37 @@ class MacroDroid
797
911
 
798
912
  private
799
913
 
914
+ def fetch_geofences(nodes)
915
+
916
+ nodes.map do |e|
917
+
918
+ name = e.text.to_s.strip
919
+ item = e.element('item')
920
+ coordinates = item.text('coordinates')
921
+ latitude, longitude = coordinates.split(/, */,2)
922
+ radius = item.text('radius')
923
+
924
+ id = UUID.new.generate
925
+
926
+ h = {
927
+ name: name,
928
+ longitude: longitude,
929
+ latitude: latitude,
930
+ radius: radius,
931
+ id: id
932
+ }
933
+
934
+ [id.to_sym, GeofenceMap.new(h)]
935
+
936
+ end.to_h
937
+
938
+ end
939
+
800
940
  def import_json(s)
801
941
 
802
942
  h = JSON.parse(s, symbolize_names: true)
803
943
  puts 'json_to_yaml: ' + h.to_yaml if @debug
944
+ @yaml = h.to_yaml # helpful for debugging and testing
804
945
 
805
946
  @h = h.to_snake_case
806
947
  puts ('@h: ' + @h.inspect).debug if @debug
@@ -809,7 +950,7 @@ class MacroDroid
809
950
  # fetch the geofence data
810
951
  if @h[:geofence_data] then
811
952
 
812
- @geofence = @h[:geofence_data][:geofence_map].map do |id, properties|
953
+ @geofences = @h[:geofence_data][:geofence_map].map do |id, properties|
813
954
  [id, GeofenceMap.new(properties)]
814
955
  end.to_h
815
956
 
@@ -818,9 +959,9 @@ class MacroDroid
818
959
  @macros = @h[:macro_list].map do |macro|
819
960
 
820
961
  puts ('macro: ' + macro.inspect).debug if @debug
821
- puts '@geofence: ' + @geofence.inspect if @debug
962
+ # puts '@geofences: ' + @geofences.inspect if @debug
822
963
 
823
- m = Macro.new(geofence: @geofence, debug: @debug )
964
+ m = Macro.new(geofences: @geofences.map(&:last), debug: @debug )
824
965
  m.import_h(macro)
825
966
  m
826
967
 
@@ -833,13 +974,15 @@ class MacroDroid
833
974
  def import_rowxml(raws)
834
975
 
835
976
  s = RXFHelper.read(raws).first
836
- puts 's: ' + s.inspect if $debug
977
+ puts 's: ' + s.inspect if @debug
837
978
  doc = Rexle.new(s)
838
- puts 'after doc' if $debug
979
+ puts 'after doc' if @debug
980
+ puts 'import_rowxml: @geofences: ' + @geofences.inspect if @debug
981
+ geofences = @geofences
839
982
 
840
983
  @macros = doc.root.xpath('item').map do |node|
841
-
842
- Macro.new.import_xml(node)
984
+ puts ('geofences: ' + geofences.inspect).highlight if @debug
985
+ Macro.new(geofences: geofences.map(&:last), debug: @debug).import_xml(node)
843
986
 
844
987
  end
845
988
 
@@ -862,7 +1005,7 @@ class MacroDroid
862
1005
 
863
1006
  @macros = doc.root.xpath('macro').map do |node|
864
1007
 
865
- Macro.new.import_xml(node)
1008
+ Macro.new(geofences: @geofences.map(&:last), debug: @debug).import_xml(node)
866
1009
 
867
1010
  end
868
1011
  end
@@ -895,8 +1038,30 @@ class GeofenceMap
895
1038
 
896
1039
  attr_accessor :name, :longitude, :latitude, :radius, :id
897
1040
 
898
- def initialize(h)
899
- @id, @latitude, @longitude, @name, @radius = h.values
1041
+ def initialize(id: '', longitude: '', latitude: '', name: '', radius: '')
1042
+
1043
+ @id, @latitude, @longitude, @name, @radius = id, latitude, \
1044
+ longitude, name, radius
1045
+
1046
+ end
1047
+
1048
+ def to_h()
1049
+
1050
+ {
1051
+ id: @id,
1052
+ longitude: @longitude,
1053
+ latitude: @latitude,
1054
+ name: @name,
1055
+ radius: @radius
1056
+ }
1057
+
1058
+ end
1059
+
1060
+ def to_s()
1061
+
1062
+ coordinates = "%s, %s" % [@longitude, @latitude]
1063
+ "%s\n coordinates: %s\n radius: %s" % [@name, coordinates, @radius]
1064
+
900
1065
  end
901
1066
 
902
1067
  end
@@ -943,6 +1108,8 @@ class MacroObject
943
1108
  def to_s()
944
1109
  "#<%s %s>" % [self.class, @h.inspect]
945
1110
  end
1111
+
1112
+ alias to_summary to_s
946
1113
 
947
1114
  protected
948
1115
 
@@ -957,13 +1124,32 @@ class MacroObject
957
1124
  UUID.new.generate
958
1125
  end
959
1126
 
1127
+ def object(h={})
1128
+
1129
+ puts ('inside object h:' + h.inspect).debug if @debug
1130
+ klass = Object.const_get h[:class_type]
1131
+ puts klass.inspect.highlight if $debug
1132
+
1133
+ klass.new h
1134
+
1135
+ end
1136
+
960
1137
  end
961
1138
 
962
1139
  class Trigger < MacroObject
963
-
1140
+ using Params
1141
+
1142
+ attr_reader :constraints
1143
+
964
1144
  def initialize(h={})
965
1145
  super({fakeIcon: 0}.merge(h))
966
1146
  @list << 'fakeIcon'
1147
+
1148
+ # fetch the constraints
1149
+ @constraints = @h[:constraint_list].map do |constraint|
1150
+ object(constraint.to_snake_case)
1151
+ end
1152
+
967
1153
  end
968
1154
 
969
1155
  def match?(detail={}, model=nil)
@@ -1076,6 +1262,11 @@ class BatteryLevelTrigger < Trigger
1076
1262
  super(options.merge h)
1077
1263
 
1078
1264
  end
1265
+
1266
+ def to_s()
1267
+ operator = @h[:decreases_to] ? '<=' : '>='
1268
+ "Battery %s %s%%" % [operator, @h[:battery_level]]
1269
+ end
1079
1270
 
1080
1271
  end
1081
1272
 
@@ -1479,14 +1670,32 @@ class TimerTrigger < Trigger
1479
1670
 
1480
1671
  def to_s()
1481
1672
 
1482
- dow = @h[:days_of_week]
1673
+ dow = @h[:days_of_week]
1483
1674
 
1484
- a = Date::ABBR_DAYNAMES
1485
-
1486
- time = Time.parse("%s:%s" % [@h[:hour], @h[:minute]]).strftime("%-H:%M%P")
1487
- days = (a[1..-1] << a.first).zip(dow).select {|_,b| b}.map(&:first)
1675
+ wd = Date::ABBR_DAYNAMES
1676
+ a = (wd[1..-1] << wd.first)
1677
+
1678
+ a2 = dow.map.with_index.to_a
1679
+ start = a2.find {|x,i| x}.last
1680
+ r = a2[start..-1].take_while {|x,i| x == true}
1681
+ r2 = a2[start..-1].select {|x,i| x}
1682
+
1683
+ days = if r == r2 then
1684
+
1685
+ x1, x2 = a2[start].last, a2[r.length-1].last
1686
+
1687
+ if (x2 - x1) >= 2 then
1688
+ "%s-%s" % [a[x1],a[x2]]
1689
+ else
1690
+ a.zip(dow).select {|_,b| b}.map(&:first).join(', ')
1691
+ end
1692
+ else
1693
+ a.zip(dow).select {|_,b| b}.map(&:first).join(', ')
1694
+ end
1695
+
1696
+ time = Time.parse("%s:%s" % [@h[:hour], @h[:minute]]).strftime("%-H:%M%P")
1488
1697
 
1489
- "at %s on %s" % [time, days.join(', ')]
1698
+ "%s %s" % [time, days]
1490
1699
  end
1491
1700
 
1492
1701
  private
@@ -1723,6 +1932,10 @@ class DeviceUnlockedTrigger < DeviceEventsTrigger
1723
1932
  super(options.merge h)
1724
1933
 
1725
1934
  end
1935
+
1936
+ def to_s()
1937
+ 'Screen Unlocked'
1938
+ end
1726
1939
 
1727
1940
  end
1728
1941
 
@@ -1881,12 +2094,12 @@ end
1881
2094
  #
1882
2095
  class GeofenceTrigger < Trigger
1883
2096
 
1884
- def initialize(geofence, h={})
2097
+ def initialize( h={}, geofences: {})
1885
2098
 
1886
2099
  if h[:name] then
1887
-
1888
- found = geofence.find {|x| x.name == h[:name]}
1889
- h[:geofence_id] = found.id
2100
+ puts ('geofences2: ' + geofences.inspect)
2101
+ found = geofences.find {|x| x.name.downcase == h[:name].downcase}
2102
+ h[:geofence_id] = found.id if found
1890
2103
 
1891
2104
  end
1892
2105
 
@@ -1899,15 +2112,25 @@ class GeofenceTrigger < Trigger
1899
2112
  }
1900
2113
 
1901
2114
  super(options.merge filter(options, h))
1902
- @geofence = geofence
2115
+ @geofences = geofences
1903
2116
 
1904
2117
  end
1905
2118
 
1906
2119
  def to_s()
1907
2120
 
1908
- puts ' @geofence: ' + @geofence.inspect if $debug
2121
+ if $debug then
2122
+ puts ' @geofences: ' + @geofences.inspect
2123
+ puts '@h: ' + @h.inspect
2124
+ puts '@h[:geofence_id]: ' + @h[:geofence_id].inspect
2125
+ end
2126
+
1909
2127
  direction = @h[:enter_area] ? 'Entry' : 'Exit'
1910
- "Geofence %s (%s)" % [direction, @geofence[@h[:geofence_id].to_sym].name]
2128
+
2129
+ found = @geofences.find {|x| x.id == @h[:geofence_id]}
2130
+ puts 'found: ' + found.inspect if @debug
2131
+ label = found ? found.name : 'error: name not found'
2132
+
2133
+ "Geofence %s (%s)" % [direction, label]
1911
2134
 
1912
2135
  end
1913
2136
 
@@ -1952,8 +2175,28 @@ class ActivityRecognitionTrigger < SensorsTrigger
1952
2175
  }
1953
2176
 
1954
2177
  super(options.merge h)
2178
+
2179
+ @activity = ['In Vehicle', 'On Bicycle', 'Running', 'Walking', 'Still']
1955
2180
 
1956
2181
  end
2182
+
2183
+ def to_s()
2184
+ activity = @activity[@h[:selected_index]]
2185
+ 'Activity - ' + activity
2186
+ end
2187
+
2188
+ def to_summary
2189
+
2190
+ activity = @activity[@h[:selected_index]]
2191
+ s = if activity.length > 10 then
2192
+ activity[0..7] + '..'
2193
+ else
2194
+ activity
2195
+ end
2196
+
2197
+ 'Activity - ' + s
2198
+
2199
+ end
1957
2200
 
1958
2201
  end
1959
2202
 
@@ -1963,14 +2206,33 @@ class ProximityTrigger < SensorsTrigger
1963
2206
 
1964
2207
  def initialize(h={})
1965
2208
 
2209
+ if h[:distance] then
2210
+
2211
+ case h[:distance].to_sym
2212
+ when :near
2213
+ options[:near] = true
2214
+ end
2215
+ end
2216
+
1966
2217
  options = {
1967
2218
  near: true,
1968
2219
  selected_option: 0
1969
2220
  }
1970
2221
 
1971
- super(options.merge h)
2222
+ super(options.merge filter(options,h))
1972
2223
 
1973
2224
  end
2225
+
2226
+ def to_s()
2227
+
2228
+ distance = if @h[:near] then
2229
+ 'Near'
2230
+ else
2231
+ 'Far'
2232
+ end
2233
+
2234
+ "Proximity Sensor (%s)" % distance
2235
+ end
1974
2236
 
1975
2237
  end
1976
2238
 
@@ -2143,9 +2405,17 @@ end
2143
2405
 
2144
2406
 
2145
2407
  class Action < MacroObject
2408
+ using Params
2409
+
2410
+ attr_reader :constraints
2146
2411
 
2147
2412
  def initialize(h={})
2148
2413
  super(h)
2414
+
2415
+ # fetch the constraints
2416
+ @constraints = @h[:constraint_list].map do |constraint|
2417
+ object(constraint.to_snake_case)
2418
+ end
2149
2419
  end
2150
2420
 
2151
2421
  def invoke(s='')
@@ -2320,6 +2590,64 @@ class TakePictureAction < CameraAction
2320
2590
 
2321
2591
  end
2322
2592
 
2593
+ class IfConditionAction < Action
2594
+
2595
+ def initialize(h={})
2596
+
2597
+ options = {
2598
+ a: true,
2599
+ constraint_list: ''
2600
+ }
2601
+
2602
+ super(options.merge h)
2603
+
2604
+ end
2605
+
2606
+ def to_s()
2607
+
2608
+ operator = @h[:is_or_condition] ? 'OR' : 'AND'
2609
+ r = 'If ' + @constraints.map(&:to_s).join(" %s " % operator)
2610
+ puts 'if ... @h ' + @h.inspect
2611
+ r
2612
+
2613
+ end
2614
+ end
2615
+
2616
+ class ElseAction < Action
2617
+
2618
+ def initialize(h={})
2619
+
2620
+ options = {
2621
+ constraint_list: ''
2622
+ }
2623
+
2624
+ super(options.merge h)
2625
+
2626
+ end
2627
+
2628
+ def to_s()
2629
+ 'Else'
2630
+ end
2631
+
2632
+ end
2633
+
2634
+ class EndIfAction < Action
2635
+
2636
+ def initialize(h={})
2637
+
2638
+ options = {
2639
+ constraint_list: ''
2640
+ }
2641
+
2642
+ super(options.merge h)
2643
+
2644
+ end
2645
+
2646
+ def to_s()
2647
+ 'End If'
2648
+ end
2649
+
2650
+ end
2323
2651
 
2324
2652
  class ConnectivityAction < Action
2325
2653
 
@@ -2387,6 +2715,25 @@ class SetBluetoothAction < ConnectivityAction
2387
2715
 
2388
2716
  end
2389
2717
 
2718
+ class SetHotspotAction < ConnectivityAction
2719
+
2720
+ def initialize(h={})
2721
+
2722
+ options = {
2723
+ device_name: "", state: 0, turn_wifi_on: true, use_legacy_mechanism: false, mechanism: 0
2724
+
2725
+ }
2726
+
2727
+ super(options.merge h)
2728
+
2729
+ end
2730
+
2731
+ def to_s()
2732
+ action = @h[:turn_wifi_on] ? 'Enable' : 'Disable'
2733
+ action + ' Hotspot'
2734
+ end
2735
+ end
2736
+
2390
2737
  # Category: Connectivity
2391
2738
  #
2392
2739
  class SendIntentAction < ConnectivityAction
@@ -2574,6 +2921,10 @@ class SpeakTextAction < DeviceAction
2574
2921
  super(options.merge h)
2575
2922
 
2576
2923
  end
2924
+
2925
+ def to_s()
2926
+ "Speak Text (%s)" % @h[:text_to_say]
2927
+ end
2577
2928
 
2578
2929
  end
2579
2930
 
@@ -2688,6 +3039,17 @@ class VibrateAction < DeviceSettingsAction
2688
3039
  super(options.merge h)
2689
3040
 
2690
3041
  end
3042
+
3043
+ def to_s()
3044
+
3045
+ pattern = [
3046
+ 'Blip', 'Short Buzz', 'Long Buzz', 'Rapid', 'Slow', 'Increasing',
3047
+ 'Constant', 'Decreasing', 'Final Fantasy', 'Game Over', 'Star Wars',
3048
+ 'Mini Blip', 'Micro Blip'
3049
+ ]
3050
+
3051
+ 'Vibrate ' + "(%s)" % pattern[@h[:vibrate_pattern].to_i]
3052
+ end
2691
3053
 
2692
3054
  end
2693
3055
 
@@ -3475,6 +3837,10 @@ end
3475
3837
 
3476
3838
  # Category: Screen
3477
3839
  #
3840
+ # options:
3841
+ # keep awake, screen on => enabled: true
3842
+ # disable keep awake => enabled: false
3843
+ #
3478
3844
  class KeepAwakeAction < ScreenAction
3479
3845
 
3480
3846
  def initialize(h={})
@@ -3489,7 +3855,30 @@ class KeepAwakeAction < ScreenAction
3489
3855
  super(options.merge h)
3490
3856
 
3491
3857
  end
3492
-
3858
+
3859
+ def to_s()
3860
+
3861
+ screen = @h[:screen_option] == 0 ? 'Screen On' : 'Screen Off'
3862
+
3863
+ if @h[:enabled] then
3864
+
3865
+ whenx = if @h[:seconds_to_stay_awake_for] == 0 then
3866
+
3867
+ 'Until Disabled'
3868
+
3869
+ else
3870
+ scnds = @h[:seconds_to_stay_awake_for]
3871
+ Subunit.new(units={minutes:60, hours:60}, seconds: scnds).strfunit("%x")
3872
+ end
3873
+
3874
+ 'Keep Device Awake ' + screen + ' ' + whenx
3875
+
3876
+ else
3877
+ 'Disable Keep Awake'
3878
+ end
3879
+
3880
+
3881
+ end
3493
3882
  end
3494
3883
 
3495
3884
  # Category: Screen
@@ -3670,6 +4059,21 @@ class BatteryLevelConstraint < Constraint
3670
4059
  super(options.merge h)
3671
4060
 
3672
4061
  end
4062
+
4063
+ def to_s()
4064
+
4065
+ operator = if @h[:greater_than] then
4066
+ '>'
4067
+ elsif @h[:equals]
4068
+ '='
4069
+ else
4070
+ '<'
4071
+ end
4072
+
4073
+ level = @h[:battery_level]
4074
+
4075
+ "Battery %s %s%%" % [operator, level]
4076
+ end
3673
4077
 
3674
4078
  end
3675
4079
 
@@ -3721,6 +4125,11 @@ class ExternalPowerConstraint < Constraint
3721
4125
  super(options.merge h)
3722
4126
 
3723
4127
  end
4128
+
4129
+ def to_s()
4130
+ connection = @h[:external_power] ? 'Connected' : 'Disconnected'
4131
+ 'Power ' + connection
4132
+ end
3724
4133
 
3725
4134
  end
3726
4135
 
@@ -3739,6 +4148,12 @@ class BluetoothConstraint < Constraint
3739
4148
  super(options.merge h)
3740
4149
 
3741
4150
  end
4151
+
4152
+ def to_s()
4153
+ device = @h[:device_name] #== 'Any Device' ? 'Any' : @h[:device_name]
4154
+ "Device Connected (%s)" % device
4155
+ end
4156
+
3742
4157
 
3743
4158
  end
3744
4159
 
@@ -4063,6 +4478,10 @@ class DeviceLockedConstraint < Constraint
4063
4478
  super(options.merge h)
4064
4479
 
4065
4480
  end
4481
+
4482
+ def to_s()
4483
+ 'Device ' + (@h[:locked] ? 'Locked' : 'Unlocked')
4484
+ end
4066
4485
 
4067
4486
  end
4068
4487
 
@@ -4249,6 +4668,11 @@ class HeadphonesConnectionConstraint < Constraint
4249
4668
  super(options.merge h)
4250
4669
 
4251
4670
  end
4671
+
4672
+ def to_s()
4673
+ connection = @h[:connected] ? 'Connected' : 'Disconnected'
4674
+ 'Headphones ' + connection
4675
+ end
4252
4676
 
4253
4677
  end
4254
4678
 
@@ -4438,6 +4862,10 @@ class ScreenOnOffConstraint < Constraint
4438
4862
  super(options.merge h)
4439
4863
 
4440
4864
  end
4865
+
4866
+ def to_s()
4867
+ 'Screen ' + (@h[:screen_on] ? 'On' : 'Off')
4868
+ end
4441
4869
 
4442
4870
  end
4443
4871
 
@@ -4491,6 +4919,14 @@ class LightLevelConstraint < Constraint
4491
4919
  super(options.merge h)
4492
4920
 
4493
4921
  end
4922
+
4923
+ def to_s()
4924
+
4925
+ operator = @h[:light_level] == -1 ? 'Less than' : 'Greater than'
4926
+ condition = operator + ' ' + @h[:light_level_float].to_s + 'lx'
4927
+ 'Light Sensor ' + condition
4928
+
4929
+ end
4494
4930
 
4495
4931
  end
4496
4932
 
@@ -4523,5 +4959,9 @@ class ProximitySensorConstraint < Constraint
4523
4959
  super(options.merge h)
4524
4960
 
4525
4961
  end
4962
+
4963
+ def to_s()
4964
+ 'Proximity Sensor: ' + (@h[:near] ? 'Near' : 'Far')
4965
+ end
4526
4966
 
4527
4967
  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.7.0
4
+ version: 0.7.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  NZ2kdBIUDnAM24e0/wXdVxg4HnsZbdymxyzMQ4P5pKYcpI6oisBxI37p/Xy+wAg3
36
36
  SBHno3GEuuD8ZWj24IMJpfbp
37
37
  -----END CERTIFICATE-----
38
- date: 2020-09-05 00:00:00.000000000 Z
38
+ date: 2020-09-09 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: glw
@@ -97,6 +97,26 @@ dependencies:
97
97
  - - "~>"
98
98
  - !ruby/object:Gem::Version
99
99
  version: '0.7'
100
+ - !ruby/object:Gem::Dependency
101
+ name: subunit
102
+ requirement: !ruby/object:Gem::Requirement
103
+ requirements:
104
+ - - ">="
105
+ - !ruby/object:Gem::Version
106
+ version: 0.6.0
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '0.6'
110
+ type: :runtime
111
+ prerelease: false
112
+ version_requirements: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: 0.6.0
117
+ - - "~>"
118
+ - !ruby/object:Gem::Version
119
+ version: '0.6'
100
120
  - !ruby/object:Gem::Dependency
101
121
  name: geozone
102
122
  requirement: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file