ruby-macrodroid 0.7.1 → 0.7.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/ruby-macrodroid.rb +586 -36
- metadata +22 -2
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: eb309319c4f87ebf642930e2a926a18292804c87a877724af262bcc1eecd8589
|
4
|
+
data.tar.gz: 697d9e182f7907219c005e5869b88a93d65c01a3bb3a5c1c2a5768d1da0a86cf
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d24dea588d1ddf7106f73ecc9a3593739df4ac6bd23f74601c33f7c183b929d243bbcb473175bccfb728df734a877aa1025676bd3ea972f024093ca310a4e9f
|
7
|
+
data.tar.gz: f7ff237c1a4d962d0579d996b80ce4513f0272430fb4b6cd0f095c24c9260113cfd7cebe117a22bc2c871b48f0c68f881174d2ccbf8f1decc615581dcbd5d5e8
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/ruby-macrodroid.rb
CHANGED
@@ -110,8 +110,10 @@
|
|
110
110
|
require 'yaml'
|
111
111
|
require 'rowx'
|
112
112
|
require 'uuid'
|
113
|
-
|
114
|
-
|
113
|
+
require 'glw'
|
114
|
+
require 'geozone'
|
115
|
+
require 'geocoder'
|
116
|
+
require 'subunit'
|
115
117
|
require 'rxfhelper'
|
116
118
|
require 'chronic_cron'
|
117
119
|
|
@@ -134,6 +136,12 @@ class TriggersNlp
|
|
134
136
|
end
|
135
137
|
|
136
138
|
def triggers(params)
|
139
|
+
|
140
|
+
# e.g. at 7:30pm daily
|
141
|
+
get /^(?:at )?(\d+:\d+(?:[ap]m)?) daily/i do |time, days|
|
142
|
+
[TimerTrigger, {time: time,
|
143
|
+
days: %w(Mon Tue Wed Thu Fri Sat Sun).join(', ')}]
|
144
|
+
end
|
137
145
|
|
138
146
|
get /^(?:at )?(\d+:\d+(?:[ap]m)?) (?:on )?(.*)/i do |time, days|
|
139
147
|
[TimerTrigger, {time: time, days: days}]
|
@@ -142,7 +150,7 @@ class TriggersNlp
|
|
142
150
|
# time.is? 'at 18:30pm on Mon or Tue'
|
143
151
|
get /^time.is\? ['"](?:at )?(\d+:\d+(?:[ap]m)?) (?:on )?(.*)['"]/i do |time, days|
|
144
152
|
[TimerTrigger, {time: time, days: days.gsub(' or ',', ')}]
|
145
|
-
end
|
153
|
+
end
|
146
154
|
|
147
155
|
get /^shake[ _]device\??$/i do
|
148
156
|
[ShakeDeviceTrigger, {}]
|
@@ -177,7 +185,16 @@ class TriggersNlp
|
|
177
185
|
get /^location (entered|exited) \(([^\)]+)/i do |direction, name|
|
178
186
|
enter_area = direction.downcase.to_sym == :entered
|
179
187
|
[GeofenceTrigger, {name: name, enter_area: enter_area}]
|
180
|
-
end
|
188
|
+
end
|
189
|
+
|
190
|
+
# eg. Proximity Sensor (Near)
|
191
|
+
#
|
192
|
+
get /^Proximity Sensor \(([^\)]+)\)/i do |distance|
|
193
|
+
|
194
|
+
[ProximityTrigger, {distance: distance}]
|
195
|
+
end
|
196
|
+
|
197
|
+
|
181
198
|
|
182
199
|
end
|
183
200
|
|
@@ -269,7 +286,33 @@ class ActionsNlp
|
|
269
286
|
#
|
270
287
|
get /webhook|HTTP GET/i do
|
271
288
|
[OpenWebPageAction, {}]
|
272
|
-
end
|
289
|
+
end
|
290
|
+
|
291
|
+
#a: Keep Device Awake Screen On Until Disabled
|
292
|
+
#
|
293
|
+
get /Keep Device Awake Screen On Until Disabled/i do
|
294
|
+
[KeepAwakeAction, {enabled: true, permanent: true, screen_option: 0}]
|
295
|
+
end
|
296
|
+
|
297
|
+
|
298
|
+
#a: Keep Device Awake Screen On 1h 1m 1s
|
299
|
+
#
|
300
|
+
get /Keep Device Awake Screen On ([^$]+)/i do |duration|
|
301
|
+
|
302
|
+
a = duration.split.map(&:to_i)
|
303
|
+
secs = Subunit.new(units={minutes:60, hours:60, seconds: 60}, a).to_i
|
304
|
+
|
305
|
+
h = {
|
306
|
+
permanent: true, screen_option: 0, seconds_to_stay_awake_for: secs
|
307
|
+
}
|
308
|
+
[KeepAwakeAction, h]
|
309
|
+
end
|
310
|
+
|
311
|
+
#a: Disable Keep Awake
|
312
|
+
#
|
313
|
+
get /Disable Keep Awake/i do
|
314
|
+
[KeepAwakeAction, {enabled: false, screen_option: 0}]
|
315
|
+
end
|
273
316
|
|
274
317
|
|
275
318
|
end
|
@@ -623,18 +666,56 @@ EOF
|
|
623
666
|
|
624
667
|
def to_s()
|
625
668
|
|
669
|
+
indent = 0
|
670
|
+
actions = @actions.map do |x|
|
671
|
+
|
672
|
+
s = x.to_s
|
673
|
+
|
674
|
+
r = if indent <= 0 then
|
675
|
+
|
676
|
+
"a: %s" % s
|
677
|
+
|
678
|
+
elsif indent > 0
|
679
|
+
|
680
|
+
if s =~ /^Else/ then
|
681
|
+
(' ' * (indent-1)) + "%s" % s
|
682
|
+
elsif s =~ /^End/
|
683
|
+
indent -= 1
|
684
|
+
(' ' * indent) + "%s" % s
|
685
|
+
else
|
686
|
+
(' ' * indent) + "%s" % s
|
687
|
+
end
|
688
|
+
|
689
|
+
end
|
690
|
+
|
691
|
+
if s =~ /^If/i then
|
692
|
+
if indent < 1 then
|
693
|
+
r = "a:\n %s" % s
|
694
|
+
indent += 1
|
695
|
+
else
|
696
|
+
r = (' ' * indent) + "%s" % s
|
697
|
+
end
|
698
|
+
|
699
|
+
indent += 1
|
700
|
+
end
|
701
|
+
|
702
|
+
r
|
703
|
+
|
704
|
+
end.join("\n")
|
705
|
+
|
626
706
|
a = [
|
627
707
|
'm: ' + @title,
|
628
708
|
@triggers.map {|x| "t: %s" % x}.join("\n"),
|
629
|
-
|
630
|
-
@constraints.map {|x| "a: %s" % x}.join("\n")
|
709
|
+
actions
|
631
710
|
]
|
632
711
|
|
712
|
+
a << @constraints.map {|x| "c: %s" % x}.join("\n") if @constraints.any?
|
713
|
+
|
633
714
|
if @description and @description.length >= 1 then
|
634
|
-
a.insert(1, 'd: ' + @description)
|
715
|
+
a.insert(1, 'd: ' + @description.gsub(/\n/,"\n "))
|
635
716
|
end
|
636
717
|
|
637
|
-
a.join("\n")
|
718
|
+
a.join("\n") + "\n"
|
638
719
|
|
639
720
|
end
|
640
721
|
|
@@ -642,11 +723,11 @@ EOF
|
|
642
723
|
|
643
724
|
a = [
|
644
725
|
'm: ' + @title,
|
645
|
-
't: ' + @triggers.map(&:
|
646
|
-
'a: ' + @actions.map(&:
|
726
|
+
't: ' + @triggers.map(&:to_summary).join(", "),
|
727
|
+
'a: ' + @actions.map(&:to_summary).join(", "),
|
647
728
|
]
|
648
729
|
|
649
|
-
a << 'c: ' + @constraints.map(&:
|
730
|
+
a << 'c: ' + @constraints.map(&:to_summary).join(", ") if @constraints.any?
|
650
731
|
|
651
732
|
a.join("\n") + "\n"
|
652
733
|
|
@@ -668,7 +749,13 @@ EOF
|
|
668
749
|
puts 'GeofenceTrigger found'.highlight if $debug
|
669
750
|
GeofenceTrigger.new(h, geofences: @geofences)
|
670
751
|
else
|
671
|
-
klass
|
752
|
+
puts 'before klass'
|
753
|
+
h2 = h.merge( macro: self)
|
754
|
+
puts 'h2: ' + h2.inspect
|
755
|
+
r = klass.new h2
|
756
|
+
|
757
|
+
r
|
758
|
+
|
672
759
|
end
|
673
760
|
|
674
761
|
end
|
@@ -683,7 +770,7 @@ class MacroDroid
|
|
683
770
|
using ColouredText
|
684
771
|
using Params
|
685
772
|
|
686
|
-
attr_reader :macros, :geofences
|
773
|
+
attr_reader :macros, :geofences, :yaml
|
687
774
|
|
688
775
|
def initialize(obj=nil, debug: false)
|
689
776
|
|
@@ -813,7 +900,16 @@ class MacroDroid
|
|
813
900
|
end
|
814
901
|
|
815
902
|
def to_s()
|
816
|
-
|
903
|
+
|
904
|
+
lines = []
|
905
|
+
|
906
|
+
if @geofences.any? then
|
907
|
+
lines << @geofences.map {|_, value| 'g: ' + value.to_s}.join("\n\n") + "\n"
|
908
|
+
end
|
909
|
+
|
910
|
+
lines << @macros.map(&:to_s).join("\n")
|
911
|
+
lines.join("\n")
|
912
|
+
|
817
913
|
end
|
818
914
|
|
819
915
|
def to_summary()
|
@@ -829,13 +925,23 @@ class MacroDroid
|
|
829
925
|
name = e.text.to_s.strip
|
830
926
|
item = e.element('item')
|
831
927
|
coordinates = item.text('coordinates')
|
832
|
-
|
833
|
-
|
928
|
+
location = item.text('location')
|
929
|
+
|
930
|
+
if not coordinates and location then
|
931
|
+
results = Geocoder.search(location)
|
932
|
+
coordinates = results[0].coordinates.join(', ') if results.any?
|
933
|
+
end
|
934
|
+
|
935
|
+
if coordinates then
|
936
|
+
latitude, longitude = coordinates.split(/, */,2)
|
937
|
+
radius = item.text('radius')
|
938
|
+
end
|
834
939
|
|
835
940
|
id = UUID.new.generate
|
836
941
|
|
837
942
|
h = {
|
838
943
|
name: name,
|
944
|
+
location: location,
|
839
945
|
longitude: longitude,
|
840
946
|
latitude: latitude,
|
841
947
|
radius: radius,
|
@@ -852,6 +958,7 @@ class MacroDroid
|
|
852
958
|
|
853
959
|
h = JSON.parse(s, symbolize_names: true)
|
854
960
|
puts 'json_to_yaml: ' + h.to_yaml if @debug
|
961
|
+
@yaml = h.to_yaml # helpful for debugging and testing
|
855
962
|
|
856
963
|
@h = h.to_snake_case
|
857
964
|
puts ('@h: ' + @h.inspect).debug if @debug
|
@@ -948,10 +1055,11 @@ class GeofenceMap
|
|
948
1055
|
|
949
1056
|
attr_accessor :name, :longitude, :latitude, :radius, :id
|
950
1057
|
|
951
|
-
def initialize(id: '', longitude: '', latitude: '', name: '', radius: ''
|
1058
|
+
def initialize(id: '', longitude: '', latitude: '', name: '', radius: '',
|
1059
|
+
location: nil)
|
952
1060
|
|
953
|
-
@id, @latitude, @longitude, @name, @radius = id, latitude, \
|
954
|
-
longitude, name, radius
|
1061
|
+
@id, @latitude, @longitude, @name, @radius, @location = id, latitude, \
|
1062
|
+
longitude, name, radius, location
|
955
1063
|
|
956
1064
|
end
|
957
1065
|
|
@@ -964,6 +1072,18 @@ class GeofenceMap
|
|
964
1072
|
name: @name,
|
965
1073
|
radius: @radius
|
966
1074
|
}
|
1075
|
+
|
1076
|
+
end
|
1077
|
+
|
1078
|
+
def to_s()
|
1079
|
+
|
1080
|
+
lines = []
|
1081
|
+
coordinates = "%s, %s" % [@latitude, @longitude]
|
1082
|
+
lines << "%s" % @name
|
1083
|
+
lines << " location: %s" % @location if @location
|
1084
|
+
lines << " coordinates: %s" % coordinates
|
1085
|
+
lines << " radius: %s" % @radius
|
1086
|
+
lines.join("\n")
|
967
1087
|
|
968
1088
|
end
|
969
1089
|
|
@@ -972,7 +1092,7 @@ end
|
|
972
1092
|
class MacroObject
|
973
1093
|
using ColouredText
|
974
1094
|
|
975
|
-
attr_reader :type
|
1095
|
+
attr_reader :type, :siguid
|
976
1096
|
attr_accessor :options
|
977
1097
|
|
978
1098
|
def initialize(h={})
|
@@ -1008,9 +1128,15 @@ class MacroObject
|
|
1008
1128
|
|
1009
1129
|
end
|
1010
1130
|
|
1131
|
+
def siguid()
|
1132
|
+
@h[:siguid]
|
1133
|
+
end
|
1134
|
+
|
1011
1135
|
def to_s()
|
1012
1136
|
"#<%s %s>" % [self.class, @h.inspect]
|
1013
1137
|
end
|
1138
|
+
|
1139
|
+
alias to_summary to_s
|
1014
1140
|
|
1015
1141
|
protected
|
1016
1142
|
|
@@ -1025,13 +1151,32 @@ class MacroObject
|
|
1025
1151
|
UUID.new.generate
|
1026
1152
|
end
|
1027
1153
|
|
1154
|
+
def object(h={})
|
1155
|
+
|
1156
|
+
puts ('inside object h:' + h.inspect).debug if @debug
|
1157
|
+
klass = Object.const_get h[:class_type]
|
1158
|
+
puts klass.inspect.highlight if $debug
|
1159
|
+
|
1160
|
+
klass.new h
|
1161
|
+
|
1162
|
+
end
|
1163
|
+
|
1028
1164
|
end
|
1029
1165
|
|
1030
1166
|
class Trigger < MacroObject
|
1031
|
-
|
1167
|
+
using Params
|
1168
|
+
|
1169
|
+
attr_reader :constraints
|
1170
|
+
|
1032
1171
|
def initialize(h={})
|
1033
1172
|
super({fakeIcon: 0}.merge(h))
|
1034
1173
|
@list << 'fakeIcon'
|
1174
|
+
|
1175
|
+
# fetch the constraints
|
1176
|
+
@constraints = @h[:constraint_list].map do |constraint|
|
1177
|
+
object(constraint.to_snake_case)
|
1178
|
+
end
|
1179
|
+
|
1035
1180
|
end
|
1036
1181
|
|
1037
1182
|
def match?(detail={}, model=nil)
|
@@ -1144,6 +1289,11 @@ class BatteryLevelTrigger < Trigger
|
|
1144
1289
|
super(options.merge h)
|
1145
1290
|
|
1146
1291
|
end
|
1292
|
+
|
1293
|
+
def to_s()
|
1294
|
+
operator = @h[:decreases_to] ? '<=' : '>='
|
1295
|
+
"Battery %s %s%%" % [operator, @h[:battery_level]]
|
1296
|
+
end
|
1147
1297
|
|
1148
1298
|
end
|
1149
1299
|
|
@@ -1198,6 +1348,24 @@ class ExternalPowerTrigger < Trigger
|
|
1198
1348
|
super(options.merge h)
|
1199
1349
|
|
1200
1350
|
end
|
1351
|
+
|
1352
|
+
def to_s()
|
1353
|
+
|
1354
|
+
return 'Power Disconnected' unless @h[:power_connected]
|
1355
|
+
|
1356
|
+
status = 'Power Connectd'
|
1357
|
+
options = if @h[:power_connected_options].all? then
|
1358
|
+
'Any'
|
1359
|
+
else
|
1360
|
+
|
1361
|
+
a = ['Wired (Fast Charge)', 'Wireless', 'Wired (Slow Charge)']
|
1362
|
+
@h[:power_connected_options].map.with_index {|x,i| x ? i : nil}\
|
1363
|
+
.compact.map {|i| a[i] }.join(' + ')
|
1364
|
+
|
1365
|
+
end
|
1366
|
+
|
1367
|
+
"%s: %s" % [status, options]
|
1368
|
+
end
|
1201
1369
|
|
1202
1370
|
end
|
1203
1371
|
|
@@ -1547,14 +1715,32 @@ class TimerTrigger < Trigger
|
|
1547
1715
|
|
1548
1716
|
def to_s()
|
1549
1717
|
|
1550
|
-
dow = @h[:days_of_week]
|
1551
|
-
|
1552
|
-
a = Date::ABBR_DAYNAMES
|
1718
|
+
dow = @h[:days_of_week]
|
1553
1719
|
|
1554
|
-
|
1555
|
-
|
1720
|
+
wd = Date::ABBR_DAYNAMES
|
1721
|
+
a = (wd[1..-1] << wd.first)
|
1722
|
+
|
1723
|
+
a2 = dow.map.with_index.to_a
|
1724
|
+
start = a2.find {|x,i| x}.last
|
1725
|
+
r = a2[start..-1].take_while {|x,i| x == true}
|
1726
|
+
r2 = a2[start..-1].select {|x,i| x}
|
1727
|
+
|
1728
|
+
days = if r == r2 then
|
1729
|
+
|
1730
|
+
x1, x2 = a2[start].last, a2[r.length-1].last
|
1731
|
+
|
1732
|
+
if (x2 - x1) >= 2 then
|
1733
|
+
"%s-%s" % [a[x1],a[x2]]
|
1734
|
+
else
|
1735
|
+
a.zip(dow).select {|_,b| b}.map(&:first).join(', ')
|
1736
|
+
end
|
1737
|
+
else
|
1738
|
+
a.zip(dow).select {|_,b| b}.map(&:first).join(', ')
|
1739
|
+
end
|
1740
|
+
|
1741
|
+
time = Time.parse("%s:%s" % [@h[:hour], @h[:minute]]).strftime("%-H:%M%P")
|
1556
1742
|
|
1557
|
-
"
|
1743
|
+
"%s %s" % [time, days]
|
1558
1744
|
end
|
1559
1745
|
|
1560
1746
|
private
|
@@ -1791,6 +1977,10 @@ class DeviceUnlockedTrigger < DeviceEventsTrigger
|
|
1791
1977
|
super(options.merge h)
|
1792
1978
|
|
1793
1979
|
end
|
1980
|
+
|
1981
|
+
def to_s()
|
1982
|
+
'Screen Unlocked'
|
1983
|
+
end
|
1794
1984
|
|
1795
1985
|
end
|
1796
1986
|
|
@@ -1952,7 +2142,7 @@ class GeofenceTrigger < Trigger
|
|
1952
2142
|
def initialize( h={}, geofences: {})
|
1953
2143
|
|
1954
2144
|
if h[:name] then
|
1955
|
-
puts ('geofences2: ' + geofences.inspect)
|
2145
|
+
puts ('geofences2: ' + geofences.inspect) if $debug
|
1956
2146
|
found = geofences.find {|x| x.name.downcase == h[:name].downcase}
|
1957
2147
|
h[:geofence_id] = found.id if found
|
1958
2148
|
|
@@ -1982,7 +2172,7 @@ class GeofenceTrigger < Trigger
|
|
1982
2172
|
direction = @h[:enter_area] ? 'Entry' : 'Exit'
|
1983
2173
|
|
1984
2174
|
found = @geofences.find {|x| x.id == @h[:geofence_id]}
|
1985
|
-
puts 'found: ' + found.inspect
|
2175
|
+
puts 'found: ' + found.inspect if @debug
|
1986
2176
|
label = found ? found.name : 'error: name not found'
|
1987
2177
|
|
1988
2178
|
"Geofence %s (%s)" % [direction, label]
|
@@ -2030,8 +2220,28 @@ class ActivityRecognitionTrigger < SensorsTrigger
|
|
2030
2220
|
}
|
2031
2221
|
|
2032
2222
|
super(options.merge h)
|
2223
|
+
|
2224
|
+
@activity = ['In Vehicle', 'On Bicycle', 'Running', 'Walking', 'Still']
|
2033
2225
|
|
2034
2226
|
end
|
2227
|
+
|
2228
|
+
def to_s()
|
2229
|
+
activity = @activity[@h[:selected_index]]
|
2230
|
+
'Activity - ' + activity
|
2231
|
+
end
|
2232
|
+
|
2233
|
+
def to_summary
|
2234
|
+
|
2235
|
+
activity = @activity[@h[:selected_index]]
|
2236
|
+
s = if activity.length > 10 then
|
2237
|
+
activity[0..7] + '..'
|
2238
|
+
else
|
2239
|
+
activity
|
2240
|
+
end
|
2241
|
+
|
2242
|
+
'Activity - ' + s
|
2243
|
+
|
2244
|
+
end
|
2035
2245
|
|
2036
2246
|
end
|
2037
2247
|
|
@@ -2041,14 +2251,33 @@ class ProximityTrigger < SensorsTrigger
|
|
2041
2251
|
|
2042
2252
|
def initialize(h={})
|
2043
2253
|
|
2254
|
+
if h[:distance] then
|
2255
|
+
|
2256
|
+
case h[:distance].to_sym
|
2257
|
+
when :near
|
2258
|
+
options[:near] = true
|
2259
|
+
end
|
2260
|
+
end
|
2261
|
+
|
2044
2262
|
options = {
|
2045
2263
|
near: true,
|
2046
2264
|
selected_option: 0
|
2047
2265
|
}
|
2048
2266
|
|
2049
|
-
super(options.merge h)
|
2267
|
+
super(options.merge filter(options,h))
|
2050
2268
|
|
2051
2269
|
end
|
2270
|
+
|
2271
|
+
def to_s()
|
2272
|
+
|
2273
|
+
distance = if @h[:near] then
|
2274
|
+
'Near'
|
2275
|
+
else
|
2276
|
+
'Far'
|
2277
|
+
end
|
2278
|
+
|
2279
|
+
"Proximity Sensor (%s)" % distance
|
2280
|
+
end
|
2052
2281
|
|
2053
2282
|
end
|
2054
2283
|
|
@@ -2221,9 +2450,20 @@ end
|
|
2221
2450
|
|
2222
2451
|
|
2223
2452
|
class Action < MacroObject
|
2453
|
+
using Params
|
2454
|
+
|
2455
|
+
attr_reader :constraints
|
2224
2456
|
|
2225
|
-
def initialize(h={})
|
2457
|
+
def initialize(h={})
|
2458
|
+
|
2459
|
+
macro = h[:macro]
|
2460
|
+
h.delete :macro
|
2226
2461
|
super(h)
|
2462
|
+
|
2463
|
+
# fetch the constraints
|
2464
|
+
@constraints = @h[:constraint_list].map do |constraint|
|
2465
|
+
object(constraint.to_snake_case.merge(macro: macro))
|
2466
|
+
end
|
2227
2467
|
end
|
2228
2468
|
|
2229
2469
|
def invoke(s='')
|
@@ -2398,6 +2638,65 @@ class TakePictureAction < CameraAction
|
|
2398
2638
|
|
2399
2639
|
end
|
2400
2640
|
|
2641
|
+
class IfConditionAction < Action
|
2642
|
+
|
2643
|
+
def initialize(h={})
|
2644
|
+
|
2645
|
+
options = {
|
2646
|
+
a: true,
|
2647
|
+
constraint_list: ''
|
2648
|
+
}
|
2649
|
+
|
2650
|
+
macro = h[:macro]
|
2651
|
+
h2 = options.merge(filter(options,h).merge(macro: macro))
|
2652
|
+
|
2653
|
+
super(h2)
|
2654
|
+
|
2655
|
+
end
|
2656
|
+
|
2657
|
+
def to_s()
|
2658
|
+
|
2659
|
+
operator = @h[:is_or_condition] ? 'OR' : 'AND'
|
2660
|
+
'If ' + @constraints.map(&:to_s).join(" %s " % operator)
|
2661
|
+
|
2662
|
+
end
|
2663
|
+
end
|
2664
|
+
|
2665
|
+
class ElseAction < Action
|
2666
|
+
|
2667
|
+
def initialize(h={})
|
2668
|
+
|
2669
|
+
options = {
|
2670
|
+
constraint_list: ''
|
2671
|
+
}
|
2672
|
+
|
2673
|
+
super(options.merge h)
|
2674
|
+
|
2675
|
+
end
|
2676
|
+
|
2677
|
+
def to_s()
|
2678
|
+
'Else'
|
2679
|
+
end
|
2680
|
+
|
2681
|
+
end
|
2682
|
+
|
2683
|
+
class EndIfAction < Action
|
2684
|
+
|
2685
|
+
def initialize(h={})
|
2686
|
+
|
2687
|
+
options = {
|
2688
|
+
constraint_list: ''
|
2689
|
+
}
|
2690
|
+
|
2691
|
+
super(options.merge h)
|
2692
|
+
|
2693
|
+
end
|
2694
|
+
|
2695
|
+
def to_s()
|
2696
|
+
'End If'
|
2697
|
+
end
|
2698
|
+
|
2699
|
+
end
|
2401
2700
|
|
2402
2701
|
class ConnectivityAction < Action
|
2403
2702
|
|
@@ -2465,6 +2764,25 @@ class SetBluetoothAction < ConnectivityAction
|
|
2465
2764
|
|
2466
2765
|
end
|
2467
2766
|
|
2767
|
+
class SetHotspotAction < ConnectivityAction
|
2768
|
+
|
2769
|
+
def initialize(h={})
|
2770
|
+
|
2771
|
+
options = {
|
2772
|
+
device_name: "", state: 0, turn_wifi_on: true, use_legacy_mechanism: false, mechanism: 0
|
2773
|
+
|
2774
|
+
}
|
2775
|
+
|
2776
|
+
super(options.merge h)
|
2777
|
+
|
2778
|
+
end
|
2779
|
+
|
2780
|
+
def to_s()
|
2781
|
+
action = @h[:turn_wifi_on] ? 'Enable' : 'Disable'
|
2782
|
+
action + ' HotSpot'
|
2783
|
+
end
|
2784
|
+
end
|
2785
|
+
|
2468
2786
|
# Category: Connectivity
|
2469
2787
|
#
|
2470
2788
|
class SendIntentAction < ConnectivityAction
|
@@ -2652,6 +2970,10 @@ class SpeakTextAction < DeviceAction
|
|
2652
2970
|
super(options.merge h)
|
2653
2971
|
|
2654
2972
|
end
|
2973
|
+
|
2974
|
+
def to_s()
|
2975
|
+
"Speak Text (%s)" % @h[:text_to_say]
|
2976
|
+
end
|
2655
2977
|
|
2656
2978
|
end
|
2657
2979
|
|
@@ -2766,6 +3088,17 @@ class VibrateAction < DeviceSettingsAction
|
|
2766
3088
|
super(options.merge h)
|
2767
3089
|
|
2768
3090
|
end
|
3091
|
+
|
3092
|
+
def to_s()
|
3093
|
+
|
3094
|
+
pattern = [
|
3095
|
+
'Blip', 'Short Buzz', 'Long Buzz', 'Rapid', 'Slow', 'Increasing',
|
3096
|
+
'Constant', 'Decreasing', 'Final Fantasy', 'Game Over', 'Star Wars',
|
3097
|
+
'Mini Blip', 'Micro Blip'
|
3098
|
+
]
|
3099
|
+
|
3100
|
+
'Vibrate ' + "(%s)" % pattern[@h[:vibrate_pattern].to_i]
|
3101
|
+
end
|
2769
3102
|
|
2770
3103
|
end
|
2771
3104
|
|
@@ -3553,6 +3886,10 @@ end
|
|
3553
3886
|
|
3554
3887
|
# Category: Screen
|
3555
3888
|
#
|
3889
|
+
# options:
|
3890
|
+
# keep awake, screen on => enabled: true
|
3891
|
+
# disable keep awake => enabled: false
|
3892
|
+
#
|
3556
3893
|
class KeepAwakeAction < ScreenAction
|
3557
3894
|
|
3558
3895
|
def initialize(h={})
|
@@ -3567,7 +3904,30 @@ class KeepAwakeAction < ScreenAction
|
|
3567
3904
|
super(options.merge h)
|
3568
3905
|
|
3569
3906
|
end
|
3570
|
-
|
3907
|
+
|
3908
|
+
def to_s()
|
3909
|
+
|
3910
|
+
screen = @h[:screen_option] == 0 ? 'Screen On' : 'Screen Off'
|
3911
|
+
|
3912
|
+
if @h[:enabled] then
|
3913
|
+
|
3914
|
+
whenx = if @h[:seconds_to_stay_awake_for] == 0 then
|
3915
|
+
|
3916
|
+
'Until Disabled'
|
3917
|
+
|
3918
|
+
else
|
3919
|
+
scnds = @h[:seconds_to_stay_awake_for]
|
3920
|
+
Subunit.new(units={minutes:60, hours:60}, seconds: scnds).strfunit("%x")
|
3921
|
+
end
|
3922
|
+
|
3923
|
+
'Keep Device Awake ' + screen + ' ' + whenx
|
3924
|
+
|
3925
|
+
else
|
3926
|
+
'Disable Keep Awake'
|
3927
|
+
end
|
3928
|
+
|
3929
|
+
|
3930
|
+
end
|
3571
3931
|
end
|
3572
3932
|
|
3573
3933
|
# Category: Screen
|
@@ -3681,7 +4041,11 @@ class SetVolumeAction < VolumeAction
|
|
3681
4041
|
super(options.merge h)
|
3682
4042
|
|
3683
4043
|
end
|
3684
|
-
|
4044
|
+
|
4045
|
+
def to_s()
|
4046
|
+
volume = @h[:stream_index_array].zip(@h[:stream_volume_array]).to_h[true]
|
4047
|
+
'Volume Change ' + "Notification = %s%%" % volume
|
4048
|
+
end
|
3685
4049
|
end
|
3686
4050
|
|
3687
4051
|
class Constraint < MacroObject
|
@@ -3748,6 +4112,21 @@ class BatteryLevelConstraint < Constraint
|
|
3748
4112
|
super(options.merge h)
|
3749
4113
|
|
3750
4114
|
end
|
4115
|
+
|
4116
|
+
def to_s()
|
4117
|
+
|
4118
|
+
operator = if @h[:greater_than] then
|
4119
|
+
'>'
|
4120
|
+
elsif @h[:equals]
|
4121
|
+
'='
|
4122
|
+
else
|
4123
|
+
'<'
|
4124
|
+
end
|
4125
|
+
|
4126
|
+
level = @h[:battery_level]
|
4127
|
+
|
4128
|
+
"Battery %s %s%%" % [operator, level]
|
4129
|
+
end
|
3751
4130
|
|
3752
4131
|
end
|
3753
4132
|
|
@@ -3799,6 +4178,11 @@ class ExternalPowerConstraint < Constraint
|
|
3799
4178
|
super(options.merge h)
|
3800
4179
|
|
3801
4180
|
end
|
4181
|
+
|
4182
|
+
def to_s()
|
4183
|
+
connection = @h[:external_power] ? 'Connected' : 'Disconnected'
|
4184
|
+
'Power ' + connection
|
4185
|
+
end
|
3802
4186
|
|
3803
4187
|
end
|
3804
4188
|
|
@@ -3817,6 +4201,12 @@ class BluetoothConstraint < Constraint
|
|
3817
4201
|
super(options.merge h)
|
3818
4202
|
|
3819
4203
|
end
|
4204
|
+
|
4205
|
+
def to_s()
|
4206
|
+
device = @h[:device_name] #== 'Any Device' ? 'Any' : @h[:device_name]
|
4207
|
+
"Device Connected (%s)" % device
|
4208
|
+
end
|
4209
|
+
|
3820
4210
|
|
3821
4211
|
end
|
3822
4212
|
|
@@ -4141,6 +4531,10 @@ class DeviceLockedConstraint < Constraint
|
|
4141
4531
|
super(options.merge h)
|
4142
4532
|
|
4143
4533
|
end
|
4534
|
+
|
4535
|
+
def to_s()
|
4536
|
+
'Device ' + (@h[:locked] ? 'Locked' : 'Unlocked')
|
4537
|
+
end
|
4144
4538
|
|
4145
4539
|
end
|
4146
4540
|
|
@@ -4279,18 +4673,26 @@ end
|
|
4279
4673
|
# Category: MacroDroid Specific
|
4280
4674
|
#
|
4281
4675
|
class TriggerThatInvokedConstraint < Constraint
|
4282
|
-
|
4676
|
+
using ColouredText
|
4677
|
+
|
4283
4678
|
def initialize(h={})
|
4284
4679
|
|
4680
|
+
puts ('h: ' + h.inspect).green
|
4681
|
+
@trigger = h[:macro].triggers.find {|x| x.siguid == h[:si_guid_that_invoked] }
|
4682
|
+
|
4285
4683
|
options = {
|
4286
4684
|
not: false,
|
4287
4685
|
si_guid_that_invoked: -4951291100076165433,
|
4288
4686
|
trigger_name: 'Shake Device'
|
4289
4687
|
}
|
4290
4688
|
|
4291
|
-
super(options.merge h)
|
4689
|
+
super(options.merge filter(options,h))
|
4292
4690
|
|
4293
4691
|
end
|
4692
|
+
|
4693
|
+
def to_s()
|
4694
|
+
'Trigger Fired: ' + @trigger.to_s
|
4695
|
+
end
|
4294
4696
|
|
4295
4697
|
end
|
4296
4698
|
|
@@ -4327,6 +4729,11 @@ class HeadphonesConnectionConstraint < Constraint
|
|
4327
4729
|
super(options.merge h)
|
4328
4730
|
|
4329
4731
|
end
|
4732
|
+
|
4733
|
+
def to_s()
|
4734
|
+
connection = @h[:connected] ? 'Connected' : 'Disconnected'
|
4735
|
+
'Headphones ' + connection
|
4736
|
+
end
|
4330
4737
|
|
4331
4738
|
end
|
4332
4739
|
|
@@ -4516,6 +4923,10 @@ class ScreenOnOffConstraint < Constraint
|
|
4516
4923
|
super(options.merge h)
|
4517
4924
|
|
4518
4925
|
end
|
4926
|
+
|
4927
|
+
def to_s()
|
4928
|
+
'Screen ' + (@h[:screen_on] ? 'On' : 'Off')
|
4929
|
+
end
|
4519
4930
|
|
4520
4931
|
end
|
4521
4932
|
|
@@ -4569,6 +4980,14 @@ class LightLevelConstraint < Constraint
|
|
4569
4980
|
super(options.merge h)
|
4570
4981
|
|
4571
4982
|
end
|
4983
|
+
|
4984
|
+
def to_s()
|
4985
|
+
|
4986
|
+
operator = @h[:light_level] == -1 ? 'Less than' : 'Greater than'
|
4987
|
+
condition = operator + ' ' + @h[:light_level_float].to_s + 'lx'
|
4988
|
+
'Light Sensor ' + condition
|
4989
|
+
|
4990
|
+
end
|
4572
4991
|
|
4573
4992
|
end
|
4574
4993
|
|
@@ -4601,5 +5020,136 @@ class ProximitySensorConstraint < Constraint
|
|
4601
5020
|
super(options.merge h)
|
4602
5021
|
|
4603
5022
|
end
|
5023
|
+
|
5024
|
+
def to_s()
|
5025
|
+
'Proximity Sensor: ' + (@h[:near] ? 'Near' : 'Far')
|
5026
|
+
end
|
5027
|
+
|
5028
|
+
end
|
5029
|
+
|
5030
|
+
|
5031
|
+
# ----------------------------------------------------------------------------
|
5032
|
+
|
5033
|
+
|
5034
|
+
class DroidSim
|
5035
|
+
|
5036
|
+
class Service
|
5037
|
+
def initialize(callback)
|
5038
|
+
@callback = callback
|
5039
|
+
end
|
5040
|
+
end
|
5041
|
+
|
5042
|
+
class Application < Service
|
5043
|
+
|
5044
|
+
def closed()
|
5045
|
+
end
|
5046
|
+
def launched()
|
5047
|
+
end
|
5048
|
+
end
|
5049
|
+
|
5050
|
+
class Battery < Service
|
5051
|
+
|
5052
|
+
def level()
|
5053
|
+
end
|
5054
|
+
|
5055
|
+
def temperature()
|
5056
|
+
end
|
5057
|
+
|
5058
|
+
end
|
5059
|
+
class Bluetooth < Service
|
5060
|
+
|
5061
|
+
def enable()
|
5062
|
+
@callback.on_bluetooth_enabled()
|
5063
|
+
end
|
5064
|
+
|
5065
|
+
#def enabled
|
5066
|
+
# @callback.on_bluetooth_enabled()
|
5067
|
+
#end
|
5068
|
+
|
5069
|
+
def enabled?
|
5070
|
+
end
|
5071
|
+
|
5072
|
+
def disabled
|
5073
|
+
end
|
5074
|
+
|
5075
|
+
def disabled?
|
5076
|
+
end
|
5077
|
+
end
|
5078
|
+
|
5079
|
+
class Calendar < Service
|
5080
|
+
def event(starts, ends)
|
5081
|
+
end
|
5082
|
+
end
|
5083
|
+
|
5084
|
+
class DayTime < Service
|
5085
|
+
|
5086
|
+
def initialie(s)
|
5087
|
+
end
|
5088
|
+
end
|
5089
|
+
|
5090
|
+
class Headphones < Service
|
5091
|
+
def inserted
|
5092
|
+
end
|
5093
|
+
|
5094
|
+
def removed
|
5095
|
+
end
|
5096
|
+
end
|
5097
|
+
|
5098
|
+
class Webhook < Service
|
5099
|
+
|
5100
|
+
def url()
|
5101
|
+
@url
|
5102
|
+
end
|
5103
|
+
|
5104
|
+
def url=(s)
|
5105
|
+
@url = s
|
5106
|
+
end
|
5107
|
+
end
|
5108
|
+
|
5109
|
+
class Wifi < Service
|
5110
|
+
def enabled
|
5111
|
+
end
|
5112
|
+
|
5113
|
+
def disabled
|
5114
|
+
end
|
5115
|
+
|
5116
|
+
def ssid_in_range()
|
5117
|
+
end
|
5118
|
+
|
5119
|
+
def ssid_out_of_range()
|
5120
|
+
end
|
5121
|
+
end
|
5122
|
+
|
5123
|
+
class Power < Service
|
5124
|
+
def connected()
|
5125
|
+
end
|
5126
|
+
|
5127
|
+
def disconnected()
|
5128
|
+
end
|
5129
|
+
|
5130
|
+
def button_toggle()
|
5131
|
+
end
|
5132
|
+
end
|
5133
|
+
|
5134
|
+
class Popup < Service
|
5135
|
+
def message(s)
|
5136
|
+
puts s
|
5137
|
+
end
|
5138
|
+
end
|
5139
|
+
|
5140
|
+
|
5141
|
+
attr_reader :bluetooth, :popup
|
5142
|
+
|
5143
|
+
def initialize()
|
5144
|
+
|
5145
|
+
@bluetooth = Bluetooth.new self
|
5146
|
+
@popup = Popup.new self
|
5147
|
+
|
5148
|
+
end
|
5149
|
+
|
5150
|
+
def on_bluetooth_enabled()
|
5151
|
+
|
5152
|
+
end
|
5153
|
+
|
4604
5154
|
|
4605
5155
|
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.
|
4
|
+
version: 0.7.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- James Robertson
|
@@ -35,7 +35,7 @@ cert_chain:
|
|
35
35
|
NZ2kdBIUDnAM24e0/wXdVxg4HnsZbdymxyzMQ4P5pKYcpI6oisBxI37p/Xy+wAg3
|
36
36
|
SBHno3GEuuD8ZWj24IMJpfbp
|
37
37
|
-----END CERTIFICATE-----
|
38
|
-
date: 2020-09-
|
38
|
+
date: 2020-09-11 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
|