ruby-macrodroid 0.7.7 → 0.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b2bb7feb730c6e27fa5a975bfdbf07828880549917f2f827444024baab88520d
4
- data.tar.gz: 1c6e78b40874c2ddc5760d052974998071c581ba5cc3c52dcef58c2d1cd288ce
3
+ metadata.gz: 8e58584da95b866b61497cebde9f89bac44a793ebdf23bc58d9cdcdfdb208419
4
+ data.tar.gz: 79d881aee3a91df644efb1733b9664faab5b46e535bfe5ad10681a884b8f19ef
5
5
  SHA512:
6
- metadata.gz: f5f66318dc99e82aa73fb6ce5ba11604f290f57d5757cfcdc46664165095b950cebf30da91b4dd9623200f5b615306f40f7815eefb78fe3f7eb65f5567dfd940
7
- data.tar.gz: '03767919cd1943368facf1c7b66c8ebc6cffeceef99123e9d24957adc6cbedc336fa55468c05b73df691cb8c204d629dfdc085933aaee86370dbecf5f67e6b00'
6
+ metadata.gz: 181c71de158a1bff2a26cd6762c85961e4ae1eaaa7fc813a422ad700de73218d25902948e32161dd8c87d698ba3c833895f902dad9f568e46e384e682f2c9d7a
7
+ data.tar.gz: 805329654e2d074217a0e2dc3a9738efd26fb010d91a7f1e4a0ff8f84f297103609e94f3d386bd8db191937f27a9f0be13502a9dc5f063eb36a6d208556ce49a
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -29,82 +29,6 @@
29
29
  # GeofenceMap
30
30
  #
31
31
  #
32
- # ## Object class
33
- #
34
- # MacroObject
35
- #
36
- #
37
- # ## Trigger classes
38
- #
39
- # Trigger WebHookTrigger WifiConnectionTrigger
40
- # ApplicationInstalledRemovedTrigger ApplicationLaunchedTrigger
41
- # BatteryLevelTrigger BatteryTemperatureTrigger PowerButtonToggleTrigger
42
- # ExternalPowerTrigger CallActiveTrigger IncomingCallTrigger
43
- # OutgoingCallTrigger CallEndedTrigger CallMissedTrigger IncomingSMSTrigger
44
- # WebHookTrigger WifiConnectionTrigger BluetoothTrigger HeadphonesTrigger
45
- # SignalOnOffTrigger UsbDeviceConnectionTrigger WifiSSIDTrigger
46
- # CalendarTrigger TimerTrigger StopwatchTrigger DayTrigger
47
- # RegularIntervalTrigger DeviceEventsTrigger AirplaneModeTrigger
48
- # AutoSyncChangeTrigger DayDreamTrigger DockTrigger FailedLoginTrigger
49
- # GPSEnabledTrigger MusicPlayingTrigger DeviceUnlockedTrigger
50
- # AutoRotateChangeTrigger ClipboardChangeTrigger BootTrigger
51
- # IntentReceivedTrigger NotificationTrigger ScreenOnOffTrigger
52
- # SilentModeTrigger WeatherTrigger GeofenceTrigger SunriseSunsetTrigger
53
- # SensorsTrigger ActivityRecognitionTrigger ProximityTrigger
54
- # ShakeDeviceTrigger FlipDeviceTrigger OrientationTrigger
55
- # FloatingButtonTrigger ShortcutTrigger VolumeButtonTrigger
56
- # MediaButtonPressedTrigger SwipeTrigger
57
- #
58
- #
59
- # ## Action classes
60
- #
61
- # Action LocationAction ShareLocationAction ApplicationAction
62
- # LaunchActivityAction KillBackgroundAppAction OpenWebPageAction CameraAction
63
- # UploadPhotoAction TakePictureAction ConnectivityAction SetWifiAction
64
- # SetBluetoothAction SetBluetoothAction SendIntentAction DateTimeAction
65
- # SetAlarmClockAction StopWatchAction SayTimeAction DeviceAction
66
- # AndroidShortcutsAction ClipboardAction PressBackAction SpeakTextAction
67
- # UIInteractionAction VoiceSearchAction DeviceSettingsAction
68
- # ExpandCollapseStatusBarAction LaunchHomeScreenAction CameraFlashLightAction
69
- # VibrateAction SetAutoRotateAction DayDreamAction SetKeyboardAction
70
- # SetKeyguardAction CarModeAction ChangeKeyboardAction SetWallpaperAction
71
- # FileAction OpenFileAction LocationAction ForceLocationUpdateAction
72
- # ShareLocationAction SetLocationUpdateRateAction LoggingAction
73
- # AddCalendarEntryAction LogAction ClearLogAction MediaAction
74
- # RecordMicrophoneAction PlaySoundAction MessagingAction SendEmailAction
75
- # SendSMSAction UDPCommandAction NotificationsAction ClearNotificationsAction
76
- # MessageDialogAction AllowLEDNotificationLightAction
77
- # SetNotificationSoundAction SetNotificationSoundAction
78
- # SetNotificationSoundAction NotificationAction ToastAction PhoneAction
79
- # AnswerCallAction ClearCallLogAction OpenCallLogAction RejectCallAction
80
- # MakeCallAction SetRingtoneAction ScreenAction SetBrightnessAction
81
- # ForceScreenRotationAction ScreenOnAction DimScreenAction KeepAwakeAction
82
- # SetScreenTimeoutAction VolumeAction SilentModeVibrateOffAction
83
- # SetVibrateAction VolumeIncrementDecrementAction SpeakerPhoneAction
84
- # SetVolumeAction
85
- #
86
- #
87
- # ## Constraint classes
88
- #
89
- # Constraint TimeOfDayConstraint BatteryLevelConstraint
90
- # BatterySaverStateConstraint BatteryTemperatureConstraint
91
- # ExternalPowerConstraint BluetoothConstraint GPSEnabledConstraint
92
- # LocationModeConstraint SignalOnOffConstraint WifiConstraint
93
- # CellTowerConstraint IsRoamingConstraint DataOnOffConstraint
94
- # WifiHotSpotConstraint CalendarConstraint DayOfWeekConstraint
95
- # TimeOfDayConstraint DayOfMonthConstraint MonthOfYearConstraint
96
- # SunsetSunriseConstraint AirplaneModeConstraint AutoRotateConstraint
97
- # DeviceLockedConstraint RoamingOnOffConstraint TimeSinceBootConstraint
98
- # AutoSyncConstraint NFCStateConstraint IsRootedConstraint VpnConstraint
99
- # MacroEnabledConstraint ModeConstraint TriggerThatInvokedConstraint
100
- # LastRunTimeConstraint HeadphonesConnectionConstraint MusicActiveConstraint
101
- # NotificationPresentConstraint PriorityModeConstraint
102
- # NotificationVolumeConstraint InCallConstraint PhoneRingingConstraint
103
- # BrightnessConstraint VolumeConstraint SpeakerPhoneConstraint
104
- # DarkThemeConstraint ScreenOnOffConstraint VolumeLevelConstraint
105
- # FaceUpDownConstraint LightLevelConstraint DeviceOrientationConstraint
106
- # ProximitySensorConstraint
107
-
108
32
 
109
33
 
110
34
  require 'yaml'
@@ -200,6 +124,11 @@ class TriggersNlp
200
124
 
201
125
  alias find_trigger run_route
202
126
 
127
+ def to_s(colour: false)
128
+ 'TriggersNlp ' + @h.inspect
129
+ end
130
+
131
+ alias to_summary to_s
203
132
  end
204
133
 
205
134
  class ActionsNlp
@@ -319,6 +248,11 @@ class ActionsNlp
319
248
 
320
249
  alias find_action run_route
321
250
 
251
+ def to_s(colour: false)
252
+ 'ActionsNlp ' + @h.inspect
253
+ end
254
+
255
+ alias to_summary to_s
322
256
  end
323
257
 
324
258
  class ConstraintsNlp
@@ -344,69 +278,19 @@ class ConstraintsNlp
344
278
 
345
279
  end
346
280
 
347
- module Params
348
-
349
- refine Hash do
350
-
351
- # turns keys from camelCase into snake_case
352
-
353
- def to_snake_case(h=self)
354
-
355
- h.inject({}) do |r, x|
356
-
357
- key, value = x
358
- #puts 'value: ' + value.inspect
359
-
360
- val = if value.is_a?(Hash) then
361
- to_snake_case(value)
362
- elsif value.is_a?(Array) and value.first.is_a? Hash
363
- value.map {|row| to_snake_case(row)}
364
- else
365
- value
366
- end
367
-
368
- r.merge key.to_s.sub(/^m_/,'').gsub(/[A-Z][a-z]/){|x| '_' +
369
- x.downcase}.gsub(/[a-z][A-Z]/){|x| x[0] + '_' + x[1].downcase}\
370
- .downcase.to_sym => val
371
-
372
- end
373
- end
374
-
375
- # turns keys from snake_case to CamelCase
376
- def to_camel_case(h=self)
377
-
378
- h.inject({}) do |r,x|
379
-
380
- key, value = x
381
-
382
- val = if value.is_a?(Hash) then
383
- to_camel_case(value)
384
- elsif value.is_a?(Array) and value.first.is_a? Hash
385
- value.map {|row| to_camel_case(row)}
386
- else
387
- value
388
- end
389
-
390
- r.merge({key.to_s.gsub(/(?<!^m)_[a-z]/){|x| x[-1].upcase} => val})
391
- end
392
-
393
- end
394
-
395
-
396
- end
397
281
 
398
- end
399
282
 
400
283
  class Macro
401
284
  using ColouredText
402
285
  using Params
403
286
 
404
- attr_reader :local_variables, :triggers, :actions, :constraints, :guid
287
+ attr_reader :local_variables, :triggers, :actions, :constraints,
288
+ :guid, :deviceid
405
289
  attr_accessor :title, :description
406
290
 
407
- def initialize(name=nil, geofences: geofences, debug: false)
291
+ def initialize(name=nil, geofences: nil, deviceid: nil, debug: false)
408
292
 
409
- @title, @geofences, @debug = name, geofences, debug
293
+ @title, @geofences, @deviceid, @debug = name, geofences, deviceid, debug
410
294
 
411
295
  puts 'inside Macro#initialize' if @debug
412
296
 
@@ -473,7 +357,8 @@ class Macro
473
357
 
474
358
  # fetch the triggers
475
359
  @triggers = h[:trigger_list].map do |trigger|
476
-
360
+ puts 'trigger: ' + trigger.inspect
361
+ #exit
477
362
  object(trigger.to_snake_case)
478
363
 
479
364
  end
@@ -669,7 +554,11 @@ EOF
669
554
  indent = 0
670
555
  actions = @actions.map do |x|
671
556
 
672
- s = x.to_s
557
+ s = x.to_s(colour: colour)
558
+ if s.lines.length > 1 then
559
+ lines = s.lines
560
+ s = lines[0] + lines[1..-1].map {|x| x.prepend (' ' * indent) }.join
561
+ end
673
562
 
674
563
  r = if indent <= 0 then
675
564
 
@@ -736,15 +625,38 @@ EOF
736
625
 
737
626
  end
738
627
 
739
- def to_summary()
628
+ def to_summary(colour: false)
629
+
630
+ if colour then
631
+
632
+ a = [
633
+ 'm'.bg_cyan.gray.bold + ': ' + @title,
634
+ 't'.bg_red.gray.bold + ': ' + @triggers.map \
635
+ {|x| x.to_summary(colour: false)}.join(", "),
636
+ 'a'.bg_blue.gray.bold + ': ' + @actions.map \
637
+ {|x| x.to_summary(colour: false)}.join(", ")
638
+ ]
639
+
640
+ if @constraints.any? then
641
+ a << 'c'.bg_green.gray.bold + ': ' + @constraints.map \
642
+ {|x| x.to_summary(colour: false)}.join(", ")
643
+ end
644
+
645
+ else
646
+
647
+ a = [
648
+ 'm: ' + @title,
649
+ 't: ' + @triggers.map {|x| x.to_summary(colour: false)}.join(", "),
650
+ 'a: ' + @actions.map {|x| x.to_summary(colour: false)}.join(", ")
651
+ ]
652
+
653
+ if @constraints.any? then
654
+ a << 'c: ' + @constraints.map \
655
+ {|x| x.to_summary(colour: false)}.join(", ")
656
+ end
657
+ end
740
658
 
741
- a = [
742
- 'm: ' + @title,
743
- 't: ' + @triggers.map(&:to_summary).join(", "),
744
- 'a: ' + @actions.map(&:to_summary).join(", "),
745
- ]
746
659
 
747
- a << 'c: ' + @constraints.map(&:to_summary).join(", ") if @constraints.any?
748
660
 
749
661
  a.join("\n") + "\n"
750
662
 
@@ -758,7 +670,7 @@ EOF
758
670
 
759
671
  def object(h={})
760
672
 
761
- puts ('inside object h:' + h.inspect).debug if @debug
673
+ puts ('inside object h:' + h.inspect).debug if @debug
762
674
  klass = Object.const_get h[:class_type]
763
675
  puts klass.inspect.highlight if $debug
764
676
 
@@ -788,10 +700,14 @@ class MacroDroid
788
700
  using Params
789
701
 
790
702
  attr_reader :macros, :geofences, :yaml
703
+ attr_accessor :deviceid
704
+
705
+ # note: The deviceid can only be found from an existing Webhook trigger,
706
+ # generated from MacroDroid itself.
791
707
 
792
- def initialize(obj=nil, debug: false)
708
+ def initialize(obj=nil, deviceid: nil, debug: false)
793
709
 
794
- @debug = debug
710
+ @deviceid, @debug = deviceid, debug
795
711
 
796
712
  @geofences = {}
797
713
 
@@ -930,8 +846,8 @@ class MacroDroid
930
846
 
931
847
  end
932
848
 
933
- def to_summary()
934
- @macros.map(&:to_summary).join("\n")
849
+ def to_summary(colour: false)
850
+ @macros.map {|x| x.to_summary(colour: colour)}.join("\n")
935
851
  end
936
852
 
937
853
  private
@@ -996,7 +912,8 @@ class MacroDroid
996
912
  puts ('macro: ' + macro.inspect).debug if @debug
997
913
  # puts '@geofences: ' + @geofences.inspect if @debug
998
914
 
999
- m = Macro.new(geofences: @geofences.map(&:last), debug: @debug )
915
+ m = Macro.new(geofences: @geofences.map(&:last), deviceid: @deviceid,
916
+ debug: @debug )
1000
917
  m.import_h(macro)
1001
918
  m
1002
919
 
@@ -1017,7 +934,8 @@ class MacroDroid
1017
934
 
1018
935
  @macros = doc.root.xpath('item').map do |node|
1019
936
  puts ('geofences: ' + geofences.inspect).highlight if @debug
1020
- Macro.new(geofences: geofences.map(&:last), debug: @debug).import_xml(node)
937
+ Macro.new(geofences: geofences.map(&:last), deviceid: @deviceid,
938
+ debug: @debug).import_xml(node)
1021
939
 
1022
940
  end
1023
941
 
@@ -1040,7 +958,8 @@ class MacroDroid
1040
958
 
1041
959
  @macros = doc.root.xpath('macro').map do |node|
1042
960
 
1043
- Macro.new(geofences: @geofences.map(&:last), debug: @debug).import_xml(node)
961
+ Macro.new(geofences: @geofences.map(&:last), deviceid: @deviceid,
962
+ debug: @debug).import_xml(node)
1044
963
 
1045
964
  end
1046
965
  end
@@ -1093,7 +1012,7 @@ class GeofenceMap
1093
1012
 
1094
1013
  end
1095
1014
 
1096
- def to_s()
1015
+ def to_s(colour: false)
1097
1016
 
1098
1017
  lines = []
1099
1018
  coordinates = "%s, %s" % [@latitude, @longitude]
@@ -1107,4102 +1026,139 @@ class GeofenceMap
1107
1026
 
1108
1027
  end
1109
1028
 
1110
- class MacroObject
1111
- using ColouredText
1112
-
1113
- attr_reader :type, :siguid
1114
- attr_accessor :options
1115
-
1116
- def initialize(h={})
1117
-
1118
- $env ||= {}
1119
-
1120
- @h = {constraint_list: [], is_or_condition: false,
1121
- is_disabled: false}.merge(h)
1122
- @list = []
1123
-
1124
- # fetch the class name and convert from camelCase to snake_eyes
1125
- @type = self.class.to_s.sub(/Trigger|Action$/,'')\
1126
- .gsub(/\B[A-Z][a-z]/){|x| '_' + x.downcase}\
1127
- .gsub(/[a-z][A-Z]/){|x| x[0] + '_' + x[1].downcase}\
1128
- .downcase.to_sym
1129
- end
1130
1029
 
1131
- def to_h()
1132
1030
 
1133
- h = @h
1134
1031
 
1135
- h2 = h.inject({}) do |r,x|
1136
- puts 'x: ' + x.inspect if @debug
1137
- key, value = x
1138
- puts 'key: ' + key.inspect if @debug
1139
- new_key = key.to_s.gsub(/\w_\w/){|x| x[0] + x[-1].upcase}
1140
- new_key = new_key.prepend 'm_' unless @list.include? new_key
1141
- new_key = 'm_SIGUID' if new_key == 'm_siguid'
1142
- r.merge(new_key => value)
1143
- end
1144
-
1145
- h2.merge('m_classType' => self.class.to_s)
1146
1032
 
1147
- end
1148
-
1149
- def siguid()
1150
- @h[:siguid]
1151
- end
1152
-
1153
- def to_s()
1154
- "#<%s %s>" % [self.class, @h.inspect]
1155
- end
1156
-
1157
- alias to_summary to_s
1158
1033
 
1159
- protected
1160
-
1161
- def filter(options, h)
1162
-
1163
- (h.keys - options.keys).each {|key| h.delete key }
1164
- return h
1165
-
1166
- end
1167
-
1168
- def uuid()
1169
- UUID.new.generate
1170
- end
1171
-
1172
- def object(h={})
1173
1034
 
1174
- puts ('inside object h:' + h.inspect).debug if @debug
1175
- klass = Object.const_get h[:class_type]
1176
- puts klass.inspect.highlight if $debug
1177
-
1178
- klass.new h
1179
-
1180
- end
1181
-
1182
- end
1035
+ # ----------------------------------------------------------------------------
1183
1036
 
1184
- class Trigger < MacroObject
1185
- using Params
1186
-
1187
- attr_reader :constraints
1188
-
1189
- def initialize(h={})
1190
- super({fakeIcon: 0}.merge(h))
1191
- @list << 'fakeIcon'
1192
-
1193
- # fetch the constraints
1194
- @constraints = @h[:constraint_list].map do |constraint|
1195
- object(constraint.to_snake_case)
1196
- end
1197
-
1198
- end
1199
-
1200
- def match?(detail={}, model=nil)
1201
1037
 
1202
- # only match where the key exists in the trigger object
1203
- detail.select {|k,v| @h.include? k }.all? {|key,value| @h[key] == value}
1038
+ class DroidSim
1204
1039
 
1040
+ class Service
1041
+ def initialize(callback)
1042
+ @callback = callback
1043
+ end
1205
1044
  end
1206
1045
 
1207
- end
1208
-
1209
-
1210
- # Category: Applications
1211
- #
1212
- class WebHookTrigger < Trigger
1213
-
1214
- def initialize(h={})
1215
-
1216
- options = {
1217
- identifier: ''
1218
- }
1219
-
1220
- super(options.merge h)
1046
+ class Application < Service
1221
1047
 
1048
+ def closed()
1049
+ end
1050
+ def launched()
1051
+ end
1222
1052
  end
1223
1053
 
1224
- end
1054
+ class Battery < Service
1225
1055
 
1226
- # Category: Applications
1227
- #
1228
- # Also known as Wifi State Change
1229
- #
1230
- # wifi_state options:
1231
- # 0 - Wifi Enabled
1232
- # 1 - Wifi Disabled
1233
- # 2 - Connected to network
1234
- # ssid_list options:
1235
- # ["Any Network"]
1236
- # ["some Wifi SSID"] - 1 or more SSID can be supplied
1237
- # 3 - Disconnected from network
1238
- # ssid_list options:
1239
- # ["Any Network"]
1240
- # ["some Wifi SSID"] - 1 or more SSID can be supplied
1241
-
1242
- class WifiConnectionTrigger < Trigger
1243
-
1244
- def initialize(h={})
1245
-
1246
- options = {
1247
- ssid_list: [""],
1248
- wifi_state: 2
1249
- }
1056
+ def level()
1057
+ end
1250
1058
 
1251
- super(options.merge h)
1059
+ def temperature()
1060
+ end
1252
1061
 
1253
1062
  end
1063
+ class Bluetooth < Service
1254
1064
 
1255
- end
1256
-
1257
- # Category: Applications
1258
- #
1259
- class ApplicationInstalledRemovedTrigger < Trigger
1065
+ def enable()
1066
+ @callback.on_bluetooth_enabled()
1067
+ end
1260
1068
 
1261
- def initialize(h={})
1069
+ #def enabled
1070
+ # @callback.on_bluetooth_enabled()
1071
+ #end
1262
1072
 
1263
- options = {
1264
- application_name_list: [],
1265
- package_name_list: [],
1266
- installed: true,
1267
- application_option: 0,
1268
- updated: false
1269
- }
1073
+ def enabled?
1074
+ end
1270
1075
 
1271
- super(options.merge h)
1076
+ def disabled
1077
+ end
1272
1078
 
1079
+ def disabled?
1080
+ end
1273
1081
  end
1274
1082
 
1275
- end
1276
-
1277
- # Category: Applications
1278
- #
1279
- class ApplicationLaunchedTrigger < Trigger
1280
-
1281
- def initialize(h={})
1282
-
1283
- options = {
1284
- application_name_list: ["Chrome"],
1285
- package_name_list: ["com.android.chrome"],
1286
- launched: true
1287
- }
1288
-
1289
- super(options.merge h)
1290
-
1083
+ class Calendar < Service
1084
+ def event(starts, ends)
1085
+ end
1291
1086
  end
1292
1087
 
1293
- end
1294
-
1295
- # Category: Battery/Power
1296
- #
1297
- class BatteryLevelTrigger < Trigger
1298
-
1299
- def initialize(h={})
1300
-
1301
- options = {
1302
- battery_level: 50,
1303
- decreases_to: true,
1304
- option: 0
1305
- }
1306
-
1307
- super(options.merge h)
1088
+ class DayTime < Service
1308
1089
 
1090
+ def initialie(s)
1091
+ end
1309
1092
  end
1310
-
1311
- def to_s()
1312
- operator = @h[:decreases_to] ? '<=' : '>='
1313
- "Battery %s %s%%" % [operator, @h[:battery_level]]
1314
- end
1315
-
1316
- end
1317
-
1318
- # Category: Battery/Power
1319
- #
1320
- class BatteryTemperatureTrigger < Trigger
1321
-
1322
- def initialize(h={})
1323
-
1324
- options = {
1325
- decreases_to: true,
1326
- option: 0,
1327
- temperature: 30
1328
- }
1329
1093
 
1330
- super(options.merge h)
1094
+ class Headphones < Service
1095
+ def inserted
1096
+ end
1331
1097
 
1098
+ def removed
1099
+ end
1332
1100
  end
1333
1101
 
1334
- end
1335
-
1336
- # Category: Battery/Power
1337
- #
1338
- class PowerButtonToggleTrigger < Trigger
1339
-
1340
- def initialize(h={})
1341
-
1342
- options = {
1343
- num_toggles: 3
1344
- }
1102
+ class Webhook < Service
1345
1103
 
1346
- super(options.merge h)
1104
+ def url()
1105
+ @url
1106
+ end
1347
1107
 
1108
+ def url=(s)
1109
+ @url = s
1110
+ end
1348
1111
  end
1349
1112
 
1350
- end
1351
-
1352
-
1353
- # Category: Battery/Power
1354
- #
1355
- class ExternalPowerTrigger < Trigger
1356
-
1357
- def initialize(h={})
1113
+ class Wifi < Service
1114
+ def enabled
1115
+ end
1358
1116
 
1359
- options = {
1360
- power_connected_options: [true, true, true],
1361
- has_set_usb_option: true,
1362
- power_connected: true,
1363
- has_set_new_power_connected_options: true
1364
- }
1117
+ def disabled
1118
+ end
1365
1119
 
1366
- super(options.merge h)
1120
+ def ssid_in_range()
1121
+ end
1367
1122
 
1368
- end
1369
-
1370
- def to_s()
1371
-
1372
- return 'Power Disconnected' unless @h[:power_connected]
1373
-
1374
- status = 'Power Connectd'
1375
- options = if @h[:power_connected_options].all? then
1376
- 'Any'
1377
- else
1378
-
1379
- a = ['Wired (Fast Charge)', 'Wireless', 'Wired (Slow Charge)']
1380
- @h[:power_connected_options].map.with_index {|x,i| x ? i : nil}\
1381
- .compact.map {|i| a[i] }.join(' + ')
1382
-
1123
+ def ssid_out_of_range()
1383
1124
  end
1384
-
1385
- "%s: %s" % [status, options]
1386
1125
  end
1387
1126
 
1388
- end
1389
-
1390
- # Category: Call/SMS
1391
- #
1392
- class CallActiveTrigger < Trigger
1393
-
1394
- def initialize(h={})
1395
-
1396
- options = {
1397
- contact_list: [{:m_id=>"-2", :m_lookupKey=>"-2", :m_name=>"[Any Number]"}],
1398
- secondary_class_type: 'CallActiveTrigger',
1399
- signal_on: true
1400
- }
1127
+ class Power < Service
1128
+ def connected()
1129
+ end
1401
1130
 
1402
- super(options.merge h)
1131
+ def disconnected()
1132
+ end
1403
1133
 
1134
+ def button_toggle()
1135
+ end
1404
1136
  end
1405
1137
 
1406
- end
1407
-
1408
- # Category: Call/SMS
1409
- #
1410
- class IncomingCallTrigger < Trigger
1411
-
1412
- def initialize(h={})
1413
-
1414
- options = {
1415
- incoming_call_from_list: [{:m_id=>"-2", :m_lookupKey=>"-2", :m_name=>"[Any Number]"}],
1416
- group_id_list: [],
1417
- group_name_list: [],
1418
- option: 0,
1419
- phone_number_exclude: false
1420
- }
1421
-
1422
- super(options.merge h)
1423
-
1138
+ class Popup < Service
1139
+ def message(s)
1140
+ puts s
1141
+ end
1424
1142
  end
1425
1143
 
1426
- end
1427
-
1428
- # Category: Call/SMS
1429
- #
1430
- class OutgoingCallTrigger < Trigger
1431
1144
 
1432
- def initialize(h={})
1145
+ attr_reader :bluetooth, :popup
1433
1146
 
1434
- options = {
1435
- outgoing_call_to_list: [{:m_id=>"-2", :m_lookupKey=>"-2", :m_name=>"[Any Number]"}],
1436
- group_id_list: [],
1437
- group_name_list: [],
1438
- option: 0,
1439
- phone_number_exclude: false
1440
- }
1147
+ def initialize()
1441
1148
 
1442
- super(options.merge h)
1149
+ @bluetooth = Bluetooth.new self
1150
+ @popup = Popup.new self
1443
1151
 
1444
1152
  end
1445
1153
 
1446
- end
1154
+ def on_bluetooth_enabled()
1155
+
1156
+ end
1447
1157
 
1448
- # Category: Call/SMS
1449
- #
1450
- class CallEndedTrigger < Trigger
1451
1158
 
1452
- def initialize(h={})
1159
+ end
1453
1160
 
1454
- options = {
1455
- contact_list: [{:m_id=>"-2", :m_lookupKey=>"-2", :m_name=>"[Any Number]"}],
1456
- group_id_list: [],
1457
- group_name_list: [],
1458
- option: 0,
1459
- phone_number_exclude: false
1460
- }
1461
-
1462
- super(options.merge h)
1463
-
1464
- end
1465
-
1466
- end
1467
-
1468
- # Category: Call/SMS
1469
- #
1470
- class CallMissedTrigger < Trigger
1471
-
1472
- def initialize(h={})
1473
-
1474
- options = {
1475
- contact_list: [{:m_id=>"-2", :m_lookupKey=>"-2", :m_name=>"[Any Number]"}]
1476
- }
1477
-
1478
- super(options.merge h)
1479
-
1480
- end
1481
-
1482
- end
1483
-
1484
- # Category: Call/SMS
1485
- #
1486
- class IncomingSMSTrigger < Trigger
1487
-
1488
- def initialize(h={})
1489
-
1490
- options = {
1491
- sms_from_list: [{:m_id=>"-2", :m_lookupKey=>"-2", :m_name=>"[Any Number]"}],
1492
- group_id_list: [],
1493
- group_name_list: [],
1494
- sms_content: '',
1495
- option: 0,
1496
- excludes: false,
1497
- exact_match: false,
1498
- enable_regex: false,
1499
- sms_number_exclude: false
1500
- }
1501
-
1502
- super(options.merge h)
1503
-
1504
- end
1505
-
1506
- end
1507
-
1508
- # Category: Connectivity
1509
- #
1510
- class WebHookTrigger < Trigger
1511
-
1512
- def initialize(h={})
1513
-
1514
- options = {
1515
- identifier: ''
1516
- }
1517
-
1518
- super(options.merge h)
1519
-
1520
- end
1521
-
1522
- end
1523
-
1524
- # Category: Connectivity
1525
- #
1526
- class WifiConnectionTrigger < Trigger
1527
-
1528
- def initialize(h={})
1529
-
1530
- options = {
1531
- ssid_list: [],
1532
- wifi_state: 0
1533
- }
1534
-
1535
- super(options.merge h)
1536
-
1537
- end
1538
-
1539
- end
1540
-
1541
- # Category: Connectivity
1542
- #
1543
- class BluetoothTrigger < Trigger
1544
-
1545
- def initialize(h={})
1546
-
1547
- options = {
1548
- device_name: 'Any Device',
1549
- bt_state: 0,
1550
- any_device: false
1551
- }
1552
-
1553
- super(options.merge h)
1554
-
1555
- end
1556
-
1557
- end
1558
-
1559
- # Category: Connectivity
1560
- #
1561
- class HeadphonesTrigger < Trigger
1562
-
1563
- def initialize(h={})
1564
-
1565
- options = {
1566
- headphones_connected: true,
1567
- mic_option: 0
1568
- }
1569
-
1570
- super(options.merge h)
1571
-
1572
- end
1573
-
1574
- end
1575
-
1576
- # Category: Connectivity
1577
- #
1578
- class SignalOnOffTrigger < Trigger
1579
-
1580
- def initialize(h={})
1581
-
1582
- options = {
1583
- signal_on: true
1584
- }
1585
-
1586
- super(options.merge h)
1587
-
1588
- end
1589
-
1590
- end
1591
-
1592
- # Category: Connectivity
1593
- #
1594
- class UsbDeviceConnectionTrigger < Trigger
1595
-
1596
- def initialize(h={})
1597
-
1598
- options = {
1599
- option: 0
1600
- }
1601
-
1602
- super(options.merge h)
1603
-
1604
- end
1605
-
1606
- end
1607
-
1608
- # Category: Connectivity
1609
- #
1610
- # Also known as Wifi SSID Transition
1611
- #
1612
- # options:
1613
- # in_range: true | false
1614
- # wifi_cell_info: {display_name: "some Wifi SSID",
1615
- # ssid: "some Wifi SSID"} - 1 or more allowed
1616
- #
1617
- class WifiSSIDTrigger < Trigger
1618
-
1619
- def initialize(h={})
1620
-
1621
- options = {
1622
- wifi_cell_info_list: [{:display_name=>"", :ssid=>""}],
1623
- ssid_list: [],
1624
- in_range: true
1625
- }
1626
-
1627
- super(options.merge h)
1628
-
1629
- end
1630
-
1631
- def to_h()
1632
-
1633
- h = super()
1634
- val = h[:m_inRange]
1635
-
1636
- h[:m_InRange] = val
1637
- h.delete :m_inRange
1638
-
1639
- return h
1640
-
1641
- end
1642
-
1643
- end
1644
-
1645
- # Category: Date/Time
1646
- #
1647
- class CalendarTrigger < Trigger
1648
-
1649
- def initialize(h={})
1650
-
1651
- options = {
1652
- title_text: '',
1653
- detail_text: '',
1654
- calendar_name: 'Contacts',
1655
- calendar_id: '3',
1656
- availability: 0,
1657
- check_in_advance: false,
1658
- advance_time_seconds: 0,
1659
- event_start: true,
1660
- ignore_all_day: false,
1661
- negative_advance_check: false,
1662
- enable_regex: false
1663
- }
1664
-
1665
- super(options.merge h)
1666
-
1667
- end
1668
-
1669
- end
1670
-
1671
- # Category: Date/Time
1672
- #
1673
- class TimerTrigger < Trigger
1674
- using ColouredText
1675
-
1676
-
1677
- def initialize(h={})
1678
-
1679
- puts 'TimerTrigger h: ' + h.inspect if $debug
1680
-
1681
- if h[:days] then
1682
-
1683
- days = [false] * 7
1684
-
1685
- h[:days].split(/, */).each do |x|
1686
-
1687
- r = Date::DAYNAMES.grep /#{x}/i
1688
- i = Date::DAYNAMES.index(r.first)
1689
- days[i-1] = true
1690
-
1691
- end
1692
-
1693
- h[:days_of_week] = days
1694
-
1695
- end
1696
-
1697
- if h[:time] then
1698
-
1699
- t = Time.parse(h[:time])
1700
- h[:hour], h[:minute] = t.hour, t.min
1701
-
1702
- end
1703
-
1704
- #puts ('h: ' + h.inspect).debug
1705
-
1706
- options = {
1707
- alarm_id: uuid(),
1708
- days_of_week: [false, false, false, false, false, false, false],
1709
- minute: 10,
1710
- hour: 7,
1711
- use_alarm: false
1712
- }
1713
-
1714
- super(options.merge filter(options, h))
1715
-
1716
- end
1717
-
1718
- def match?(detail={time: $env[:time]}, model=nil)
1719
-
1720
- time() == detail[:time]
1721
-
1722
- end
1723
-
1724
- # sets the environmental conditions for this trigger to fire
1725
- #
1726
- def set_env()
1727
- $env[:time] = time()
1728
- end
1729
-
1730
- def to_pc()
1731
- "time.is? '%s'" % self.to_s.gsub(',', ' or')
1732
- end
1733
-
1734
- def to_s()
1735
-
1736
- dow = @h[:days_of_week]
1737
-
1738
- wd = Date::ABBR_DAYNAMES
1739
- a = (wd[1..-1] << wd.first)
1740
-
1741
- a2 = dow.map.with_index.to_a
1742
- start = a2.find {|x,i| x}.last
1743
- r = a2[start..-1].take_while {|x,i| x == true}
1744
- r2 = a2[start..-1].select {|x,i| x}
1745
-
1746
- days = if r == r2 then
1747
-
1748
- x1, x2 = a2[start].last, a2[r.length-1].last
1749
-
1750
- if (x2 - x1) >= 2 then
1751
- "%s-%s" % [a[x1],a[x2]]
1752
- else
1753
- a.zip(dow).select {|_,b| b}.map(&:first).join(', ')
1754
- end
1755
- else
1756
- a.zip(dow).select {|_,b| b}.map(&:first).join(', ')
1757
- end
1758
-
1759
- time = Time.parse("%s:%s" % [@h[:hour], @h[:minute]]).strftime("%-H:%M%P")
1760
-
1761
- "%s %s" % [time, days]
1762
- end
1763
-
1764
- private
1765
-
1766
- def time()
1767
-
1768
- a = @h[:days_of_week].clone
1769
- a.unshift a.pop
1770
-
1771
- dow = a.map.with_index {|x, i| x ? i : nil }.compact.join(',')
1772
- s = "%s %s * * %s" % [@h[:minute], @h[:hour], dow]
1773
- recent_time = ($env && $env[:time]) ? $env[:time] : Time.now
1774
- ChronicCron.new(s, recent_time).to_time
1775
-
1776
- end
1777
-
1778
- end
1779
-
1780
- # Category: Date/Time
1781
- #
1782
- class StopwatchTrigger < Trigger
1783
-
1784
- def initialize(h={})
1785
-
1786
- options = {
1787
- stopwatch_name: 'timer1',
1788
- seconds: 240
1789
- }
1790
-
1791
- super(options.merge h)
1792
-
1793
- end
1794
-
1795
- end
1796
-
1797
- # Category: Date/Time
1798
- #
1799
- # Also known as Day of Week/Month
1800
- #
1801
- # month_of_year equal to 0 means it occurs every month
1802
- # day_of_week starts with a Monday (value is 0)
1803
- #
1804
- class DayTrigger < Trigger
1805
-
1806
- def initialize(h={})
1807
-
1808
- options = {
1809
- alarm_id: uuid(),
1810
- hour: 9,
1811
- minute: 0,
1812
- month_of_year: 0,
1813
- option: 0,
1814
- day_of_week: 2,
1815
- day_of_month: 0,
1816
- use_alarm: false
1817
- }
1818
-
1819
- super(options.merge h)
1820
-
1821
- end
1822
-
1823
- end
1824
-
1825
- # Category: Date/Time
1826
- #
1827
- # Regular Interval
1828
- #
1829
- class RegularIntervalTrigger < Trigger
1830
-
1831
- def initialize(h={})
1832
-
1833
- options = {
1834
- ignore_reference_start_time: false,
1835
- minutes: 0,
1836
- seconds: 7200,
1837
- start_hour: 9,
1838
- start_minute: 10,
1839
- use_alarm: false
1840
- }
1841
-
1842
- super(options.merge h)
1843
-
1844
- end
1845
-
1846
- end
1847
-
1848
- class DeviceEventsTrigger < Trigger
1849
-
1850
- def initialize(h={})
1851
- super(h)
1852
- @group = 'device_events'
1853
- end
1854
-
1855
- end
1856
-
1857
- # Category: Device Events
1858
- #
1859
- # Airplane Mode Changed
1860
- #
1861
- # options:
1862
- # Airplane Mode Enabled
1863
- # Airplane Mode Disabled
1864
- #
1865
- # shorthand example:
1866
- # airplanemode: enabled
1867
- #
1868
- class AirplaneModeTrigger < DeviceEventsTrigger
1869
-
1870
- def initialize(h={})
1871
-
1872
- options = {
1873
- airplane_mode_enabled: true
1874
- }
1875
-
1876
- super(options.merge h)
1877
-
1878
- end
1879
-
1880
- end
1881
-
1882
- # Category: Device Events
1883
- #
1884
- class AutoSyncChangeTrigger < DeviceEventsTrigger
1885
-
1886
- def initialize(h={})
1887
-
1888
- options = {
1889
- option: 0
1890
- }
1891
-
1892
- super(options.merge h)
1893
-
1894
- end
1895
-
1896
- end
1897
-
1898
- # Category: Device Events
1899
- #
1900
- class DayDreamTrigger < DeviceEventsTrigger
1901
-
1902
- def initialize(h={})
1903
-
1904
- options = {
1905
- day_dream_enabled: true
1906
- }
1907
-
1908
- super(options.merge h)
1909
-
1910
- end
1911
-
1912
- end
1913
-
1914
- # Category: Device Events
1915
- #
1916
- class DockTrigger < DeviceEventsTrigger
1917
-
1918
- def initialize(h={})
1919
-
1920
- options = {
1921
- dock_type: 0
1922
- }
1923
-
1924
- super(options.merge h)
1925
-
1926
- end
1927
-
1928
- end
1929
-
1930
- # Category: Device Events
1931
- #
1932
- class FailedLoginTrigger < DeviceEventsTrigger
1933
-
1934
- def initialize(h={})
1935
-
1936
- options = {
1937
- num_failures: 1
1938
- }
1939
-
1940
- super(options.merge h)
1941
-
1942
- end
1943
-
1944
- def to_pc()
1945
- 'failed_login?'
1946
- end
1947
-
1948
- def to_s()
1949
- 'Failed Login Attempt'
1950
- end
1951
- end
1952
-
1953
- # Category: Device Events
1954
- #
1955
- class GPSEnabledTrigger < DeviceEventsTrigger
1956
-
1957
- def initialize(h={})
1958
-
1959
- options = {
1960
- gps_mode_enabled: true
1961
- }
1962
-
1963
- super(options.merge h)
1964
-
1965
- end
1966
-
1967
- end
1968
-
1969
- # Category: Device Events
1970
- #
1971
- class MusicPlayingTrigger < DeviceEventsTrigger
1972
-
1973
- def initialize(h={})
1974
-
1975
- options = {
1976
- option: 0
1977
- }
1978
-
1979
- super(options.merge h)
1980
-
1981
- end
1982
-
1983
- end
1984
-
1985
-
1986
- # Category: Device Events
1987
- #
1988
- class DeviceUnlockedTrigger < DeviceEventsTrigger
1989
-
1990
- def initialize(h={})
1991
-
1992
- options = {
1993
- }
1994
-
1995
- super(options.merge h)
1996
-
1997
- end
1998
-
1999
- def to_s()
2000
- 'Screen Unlocked'
2001
- end
2002
-
2003
- end
2004
-
2005
- # Category: Device Events
2006
- #
2007
- class AutoRotateChangeTrigger < DeviceEventsTrigger
2008
-
2009
- def initialize(h={})
2010
-
2011
- options = {
2012
- option: 0
2013
- }
2014
-
2015
- super(options.merge h)
2016
-
2017
- end
2018
-
2019
- end
2020
-
2021
- # Category: Device Events
2022
- #
2023
- class ClipboardChangeTrigger < DeviceEventsTrigger
2024
-
2025
- def initialize(h={})
2026
-
2027
- options = {
2028
- text: '',
2029
- enable_regex: false
2030
- }
2031
-
2032
- super(options.merge h)
2033
-
2034
- end
2035
-
2036
- end
2037
-
2038
- # Category: Device Events
2039
- #
2040
- class BootTrigger < DeviceEventsTrigger
2041
-
2042
- def initialize(h={})
2043
-
2044
- options = {
2045
- }
2046
-
2047
- super(options.merge h)
2048
-
2049
- end
2050
-
2051
- end
2052
-
2053
- # Category: Device Events
2054
- #
2055
- class IntentReceivedTrigger < DeviceEventsTrigger
2056
-
2057
- def initialize(h={})
2058
-
2059
- options = {
2060
- action: '',
2061
- extra_params: [],
2062
- extra_value_patterns: [],
2063
- extra_variables: [],
2064
- enable_regex: false
2065
- }
2066
-
2067
- super(options.merge h)
2068
-
2069
- end
2070
-
2071
- end
2072
-
2073
- # Category: Device Events
2074
- #
2075
- class NotificationTrigger < DeviceEventsTrigger
2076
-
2077
- def initialize(h={})
2078
-
2079
- options = {
2080
- text_content: '',
2081
- package_name_list: ["Any Application"],
2082
- application_name_list: ["Any Application"],
2083
- exclude_apps: false,
2084
- ignore_ongoing: true,
2085
- option: 0,
2086
- exact_match: false,
2087
- excludes: false,
2088
- sound_option: 0,
2089
- supress_multiples: true,
2090
- enable_regex: false
2091
- }
2092
-
2093
- super(options.merge h)
2094
-
2095
- end
2096
-
2097
- end
2098
-
2099
- # Category: Device Events
2100
- #
2101
- class ScreenOnOffTrigger < DeviceEventsTrigger
2102
-
2103
- def initialize(h={})
2104
-
2105
- options = {
2106
- screen_on: true
2107
- }
2108
-
2109
- super(options.merge h)
2110
-
2111
- end
2112
-
2113
- end
2114
-
2115
- # Category: Device Events
2116
- #
2117
- class SilentModeTrigger < DeviceEventsTrigger
2118
-
2119
- def initialize(h={})
2120
-
2121
- options = {
2122
- silent_enabled: true
2123
- }
2124
-
2125
- super(options.merge h)
2126
-
2127
- end
2128
-
2129
- end
2130
-
2131
- # Category: Location
2132
- #
2133
- class WeatherTrigger < Trigger
2134
-
2135
- def initialize(h={})
2136
-
2137
- options = {
2138
- humidity_above: true,
2139
- humidity_value: 50,
2140
- option: 4,
2141
- temp_below: true,
2142
- temp_celcius: true,
2143
- temperature: 0,
2144
- weather_condition: 0,
2145
- wind_speed_above: true,
2146
- wind_speed_value: 0,
2147
- wind_speed_value_mph: 0
2148
- }
2149
-
2150
- super(options.merge h)
2151
-
2152
- end
2153
-
2154
- end
2155
-
2156
- # Category: Location
2157
- #
2158
- class GeofenceTrigger < Trigger
2159
-
2160
- def initialize( h={}, geofences: {})
2161
-
2162
- if h[:name] then
2163
- puts ('geofences2: ' + geofences.inspect) if $debug
2164
- found = geofences.find {|x| x.name.downcase == h[:name].downcase}
2165
- h[:geofence_id] = found.id if found
2166
-
2167
- end
2168
-
2169
- options = {
2170
- update_rate_text: '5 Minutes',
2171
- geofence_id: '',
2172
- geofence_update_rate_minutes: 5,
2173
- trigger_from_unknown: false,
2174
- enter_area: true
2175
- }
2176
-
2177
- super(options.merge filter(options, h))
2178
- @geofences = geofences
2179
-
2180
- end
2181
-
2182
- def to_s()
2183
-
2184
- if $debug then
2185
- puts ' @geofences: ' + @geofences.inspect
2186
- puts '@h: ' + @h.inspect
2187
- puts '@h[:geofence_id]: ' + @h[:geofence_id].inspect
2188
- end
2189
-
2190
- direction = @h[:enter_area] ? 'Entry' : 'Exit'
2191
-
2192
- found = @geofences.find {|x| x.id == @h[:geofence_id]}
2193
- puts 'found: ' + found.inspect if @debug
2194
- label = found ? found.name : 'error: name not found'
2195
-
2196
- "Geofence %s (%s)" % [direction, label]
2197
-
2198
- end
2199
-
2200
- end
2201
-
2202
- # Category: Location
2203
- #
2204
- class SunriseSunsetTrigger < Trigger
2205
-
2206
- def initialize(h={})
2207
-
2208
- options = {
2209
- option: 0,
2210
- time_adjust_seconds: 0
2211
- }
2212
-
2213
- super(options.merge h)
2214
-
2215
- end
2216
-
2217
- end
2218
-
2219
-
2220
- class SensorsTrigger < Trigger
2221
-
2222
- def initialize(h={})
2223
- super(h)
2224
- @group = 'sensors'
2225
- end
2226
-
2227
- end
2228
-
2229
- # Category: Sensors
2230
- #
2231
- class ActivityRecognitionTrigger < SensorsTrigger
2232
-
2233
- def initialize(h={})
2234
-
2235
- options = {
2236
- confidence_level: 50,
2237
- selected_index: 1
2238
- }
2239
-
2240
- super(options.merge h)
2241
-
2242
- @activity = ['In Vehicle', 'On Bicycle', 'Running', 'Walking', 'Still']
2243
-
2244
- end
2245
-
2246
- def to_s()
2247
- activity = @activity[@h[:selected_index]]
2248
- 'Activity - ' + activity
2249
- end
2250
-
2251
- def to_summary
2252
-
2253
- activity = @activity[@h[:selected_index]]
2254
- s = if activity.length > 10 then
2255
- activity[0..7] + '..'
2256
- else
2257
- activity
2258
- end
2259
-
2260
- 'Activity - ' + s
2261
-
2262
- end
2263
-
2264
- end
2265
-
2266
- # Category: Sensors
2267
- #
2268
- class ProximityTrigger < SensorsTrigger
2269
-
2270
- def initialize(h={})
2271
-
2272
- if h[:distance] then
2273
-
2274
- case h[:distance].to_sym
2275
- when :near
2276
- options[:near] = true
2277
- end
2278
- end
2279
-
2280
- options = {
2281
- near: true,
2282
- selected_option: 0
2283
- }
2284
-
2285
- super(options.merge filter(options,h))
2286
-
2287
- end
2288
-
2289
- def to_s()
2290
-
2291
- distance = if @h[:near] then
2292
- 'Near'
2293
- else
2294
- 'Far'
2295
- end
2296
-
2297
- "Proximity Sensor (%s)" % distance
2298
- end
2299
-
2300
- end
2301
-
2302
- # Category: Sensors
2303
- #
2304
- class ShakeDeviceTrigger < SensorsTrigger
2305
-
2306
- def initialize(h={})
2307
-
2308
- options = {
2309
- }
2310
-
2311
- super(options.merge h)
2312
-
2313
- end
2314
-
2315
- def to_pc()
2316
- 'shake_device?'
2317
- end
2318
-
2319
- def to_s()
2320
- 'Shake Device'
2321
- end
2322
-
2323
- end
2324
-
2325
- # Category: Sensors
2326
- #
2327
- # options:
2328
- # Face Up -> Face Down
2329
- # Face Down -> Face Up
2330
- # Any -> Face Down
2331
- #
2332
- class FlipDeviceTrigger < SensorsTrigger
2333
-
2334
- def initialize(h={})
2335
-
2336
- options = {
2337
- any_start: false,
2338
- face_down: true,
2339
- work_with_screen_off: false
2340
- }
2341
-
2342
- super(options.merge h)
2343
-
2344
- end
2345
-
2346
- def to_pc()
2347
- @h[:face_down] ? 'flip_device_down?' : 'flip_device_up?'
2348
- end
2349
-
2350
- def to_s()
2351
-
2352
- action = @h[:face_down] ? 'Face Up -> Face Down' : 'Face Down -> Face Up'
2353
- 'Flip Device ' + action
2354
- end
2355
-
2356
- end
2357
-
2358
- # Category: Sensors
2359
- #
2360
- class OrientationTrigger < SensorsTrigger
2361
-
2362
- def initialize(h={})
2363
-
2364
- options = {
2365
- check_orientation_alive: true,
2366
- option: 0
2367
- }
2368
-
2369
- super(options.merge h)
2370
-
2371
- end
2372
-
2373
- end
2374
-
2375
- # Category: User Input
2376
- #
2377
- class FloatingButtonTrigger < Trigger
2378
-
2379
- def initialize(h={})
2380
-
2381
- options = {
2382
- image_resource_id: 0,
2383
- icon_bg_color: -9079435,
2384
- alpha: 100,
2385
- padding: 20,
2386
- force_location: false,
2387
- show_on_lock_screen: false,
2388
- size: 0,
2389
- transparent_background: false,
2390
- x_location: 0,
2391
- y_location: 0
2392
- }
2393
-
2394
- super(options.merge h)
2395
-
2396
- end
2397
-
2398
- end
2399
-
2400
- # Category: User Input
2401
- #
2402
- class ShortcutTrigger < Trigger
2403
-
2404
- def initialize(h={})
2405
-
2406
- options = {
2407
- }
2408
-
2409
- super(options.merge h)
2410
-
2411
- end
2412
-
2413
- end
2414
-
2415
- # Category: User Input
2416
- #
2417
- class VolumeButtonTrigger < Trigger
2418
-
2419
- def initialize(h={})
2420
-
2421
- options = {
2422
- dont_change_volume: true,
2423
- monitor_option: 1,
2424
- not_configured: false,
2425
- option: 0
2426
- }
2427
-
2428
- super(options.merge h)
2429
-
2430
- end
2431
-
2432
- end
2433
-
2434
- # Category: User Input
2435
- #
2436
- class MediaButtonPressedTrigger < Trigger
2437
-
2438
- def initialize(h={})
2439
-
2440
- options = {
2441
- option: 'Single Press',
2442
- cancel_press: false
2443
- }
2444
-
2445
- super(options.merge h)
2446
-
2447
- end
2448
-
2449
- end
2450
-
2451
- # Category: User Input
2452
- #
2453
- class SwipeTrigger < Trigger
2454
-
2455
- def initialize(h={})
2456
-
2457
- options = {
2458
- swipe_start_area: 0,
2459
- swipe_motion: 0,
2460
- cleared: true
2461
- }
2462
-
2463
- super(options.merge h)
2464
-
2465
- end
2466
-
2467
- end
2468
-
2469
-
2470
- class Action < MacroObject
2471
- using Params
2472
-
2473
- attr_reader :constraints
2474
-
2475
- def initialize(h={})
2476
-
2477
- macro = h[:macro]
2478
- h.delete :macro
2479
- super(h)
2480
-
2481
- # fetch the constraints
2482
- @constraints = @h[:constraint_list].map do |constraint|
2483
- object(constraint.to_snake_case.merge(macro: macro))
2484
- end
2485
- end
2486
-
2487
- def invoke(s='')
2488
- "%s/%s: %s" % [@group, @type, s]
2489
- end
2490
-
2491
- end
2492
-
2493
-
2494
- class LocationAction < Action
2495
-
2496
- def initialize(h={})
2497
- super(h)
2498
- @group = 'location'
2499
- end
2500
-
2501
- end
2502
-
2503
- # Category: Location
2504
- #
2505
- class ShareLocationAction < LocationAction
2506
-
2507
- def initialize(h={})
2508
-
2509
- super()
2510
-
2511
- options = {
2512
- email: '',
2513
- variable: {:m_stringValue=>"", :m_name=>"",
2514
- :m_decimalValue=>0.0, :isLocal=>true, :m_booleanValue=>false,
2515
- :excludeFromLog=>false, :m_intValue=>0, :m_type=>2},
2516
- sim_id: 0,
2517
- output_channel: 5,
2518
- old_variable_format: true
2519
- }
2520
-
2521
- super(options.merge h)
2522
-
2523
- end
2524
-
2525
- end
2526
-
2527
-
2528
- class ApplicationAction < Action
2529
-
2530
- def initialize(h={})
2531
- super(h)
2532
- @group = 'application'
2533
- end
2534
-
2535
- end
2536
-
2537
- # Category: Applications
2538
- #
2539
- class LaunchActivityAction < ApplicationAction
2540
-
2541
- def initialize(h={})
2542
-
2543
- options = {
2544
- application_name: 'Chrome',
2545
- package_to_launch: 'com.android.chrome',
2546
- exclude_from_recents: false,
2547
- start_new: false
2548
- }
2549
-
2550
- super(options.merge h)
2551
-
2552
- end
2553
-
2554
- def to_s()
2555
- 'Launch ' + @h[:application_name]
2556
- end
2557
-
2558
- end
2559
-
2560
- # Category: Applications
2561
- #
2562
- class KillBackgroundAppAction < ApplicationAction
2563
-
2564
- def initialize(h={})
2565
-
2566
- options = {
2567
- application_name_list: [""],
2568
- package_name_list: [""]
2569
- }
2570
-
2571
- super(options.merge h)
2572
-
2573
- end
2574
-
2575
- end
2576
-
2577
- # Category: Applications
2578
- #
2579
- class OpenWebPageAction < ApplicationAction
2580
-
2581
- def initialize(h={})
2582
-
2583
- h[:url_to_open] = h[:url] if h[:url]
2584
-
2585
- options = {
2586
- variable_to_save_response: {:m_stringValue=>"", :m_name=>"", :m_decimalValue=>0.0, :isLocal=>true, :m_booleanValue=>false, :excludeFromLog=>false, :m_intValue=>0, :m_type=>2},
2587
- url_to_open: '',
2588
- http_get: true,
2589
- disable_url_encode: false,
2590
- block_next_action: false
2591
- }
2592
-
2593
- super(options.merge filter(options,h))
2594
-
2595
- end
2596
-
2597
- def to_s()
2598
- "HTTP GET\n url: " + @h[:url_to_open]
2599
- end
2600
-
2601
- end
2602
-
2603
-
2604
- class CameraAction < Action
2605
-
2606
- def initialize(h={})
2607
- super(h)
2608
- @group = 'camera'
2609
- end
2610
-
2611
- end
2612
-
2613
- # Category: Camera/Photo
2614
- #
2615
- class UploadPhotoAction < CameraAction
2616
-
2617
- def initialize(h={})
2618
-
2619
- options = {
2620
- option: 'Via Intent',
2621
- use_smtp_email: false
2622
- }
2623
-
2624
- super(options.merge h)
2625
-
2626
- end
2627
-
2628
- end
2629
-
2630
- # Category: Camera/Photo
2631
- #
2632
- class TakePictureAction < CameraAction
2633
-
2634
- def initialize(h={})
2635
-
2636
- options = {
2637
- new_path: '/storage/sdcard1/DCIM/Camera',
2638
- path: '/storage/sdcard1/DCIM/Camera',
2639
- show_icon: true,
2640
- use_front_camera: true,
2641
- flash_option: 0
2642
- }
2643
-
2644
- super(options.merge h)
2645
-
2646
- end
2647
-
2648
- def to_pc()
2649
- camera = @h[:use_front_camera] ? :front : :back
2650
- 'take_photo :' + camera.to_s
2651
- end
2652
-
2653
- def to_s()
2654
- 'Take Picture'
2655
- end
2656
-
2657
- end
2658
-
2659
- class IfConditionAction < Action
2660
-
2661
- def initialize(h={})
2662
-
2663
- options = {
2664
- a: true,
2665
- constraint_list: ''
2666
- }
2667
-
2668
- macro = h[:macro]
2669
- h2 = options.merge(filter(options,h).merge(macro: macro))
2670
-
2671
- super(h2)
2672
-
2673
- end
2674
-
2675
- def to_s()
2676
-
2677
- operator = @h[:is_or_condition] ? 'OR' : 'AND'
2678
- 'If ' + @constraints.map(&:to_s).join(" %s " % operator)
2679
-
2680
- end
2681
- end
2682
-
2683
- class ElseAction < 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
- 'Else'
2697
- end
2698
-
2699
- end
2700
-
2701
- class EndIfAction < Action
2702
-
2703
- def initialize(h={})
2704
-
2705
- options = {
2706
- constraint_list: ''
2707
- }
2708
-
2709
- super(options.merge h)
2710
-
2711
- end
2712
-
2713
- def to_s()
2714
- 'End If'
2715
- end
2716
-
2717
- end
2718
-
2719
- class ConnectivityAction < Action
2720
-
2721
- def initialize(h={})
2722
- super(h)
2723
- @group = 'connectivity'
2724
- end
2725
-
2726
- end
2727
-
2728
- # Category: Connectivity
2729
- #
2730
- class SetWifiAction < ConnectivityAction
2731
-
2732
- def initialize(h={})
2733
-
2734
- options = {
2735
- ssid: '[Select Wifi]',
2736
- network_id: 0,
2737
- state: 0
2738
- }
2739
-
2740
- super(options.merge h)
2741
-
2742
- end
2743
-
2744
- def to_s()
2745
- action = @h[:state] == 0 ? 'Enable' : 'Disable'
2746
- action + ' Wifi'
2747
- end
2748
-
2749
- end
2750
-
2751
- # Category: Connectivity
2752
- #
2753
- class SetBluetoothAction < ConnectivityAction
2754
-
2755
- def initialize(h={})
2756
-
2757
- options = {
2758
- device_name: '',
2759
- state: 0
2760
- }
2761
-
2762
- super(options.merge h)
2763
-
2764
- end
2765
-
2766
- end
2767
-
2768
- # Category: Connectivity
2769
- #
2770
- class SetBluetoothAction < ConnectivityAction
2771
-
2772
- def initialize(h={})
2773
-
2774
- options = {
2775
- device_name: '',
2776
- state: 1
2777
- }
2778
-
2779
- super(options.merge h)
2780
-
2781
- end
2782
-
2783
- end
2784
-
2785
- class SetHotspotAction < ConnectivityAction
2786
-
2787
- def initialize(h={})
2788
-
2789
- options = {
2790
- device_name: "", state: 0, turn_wifi_on: true, use_legacy_mechanism: false, mechanism: 0
2791
-
2792
- }
2793
-
2794
- super(options.merge h)
2795
-
2796
- end
2797
-
2798
- def to_s()
2799
- action = @h[:turn_wifi_on] ? 'Enable' : 'Disable'
2800
- action + ' HotSpot'
2801
- end
2802
- end
2803
-
2804
- # Category: Connectivity
2805
- #
2806
- class SendIntentAction < ConnectivityAction
2807
-
2808
- def initialize(h={})
2809
-
2810
- options = {
2811
- action: '',
2812
- class_name: '',
2813
- data: '',
2814
- extra1_name: '',
2815
- extra1_value: '',
2816
- extra2_name: '',
2817
- extra2_value: '',
2818
- extra3_name: '',
2819
- extra3_value: '',
2820
- extra4_name: '',
2821
- extra4_value: '',
2822
- package_name: '',
2823
- target: 'Activity'
2824
- }
2825
-
2826
- super(options.merge h)
2827
-
2828
- end
2829
-
2830
- end
2831
-
2832
-
2833
- class DateTimeAction < Action
2834
-
2835
- def initialize(h={})
2836
- super(h)
2837
- @group = 'datetime'
2838
- end
2839
-
2840
- end
2841
-
2842
- # Category: Date/Time
2843
- #
2844
- class SetAlarmClockAction < DateTimeAction
2845
-
2846
- def initialize(h={})
2847
-
2848
- options = {
2849
- days_of_week: [false, false, false, false, false, false, false],
2850
- label: 'wakeup mum',
2851
- delay_in_minutes: 1,
2852
- hour: 8,
2853
- delay_in_hours: 0,
2854
- minute: 15,
2855
- one_off: true,
2856
- option: 0,
2857
- relative: true,
2858
- day_option: 0
2859
- }
2860
-
2861
- super(options.merge h)
2862
-
2863
- end
2864
-
2865
- end
2866
-
2867
- # Category: Date/Time
2868
- #
2869
- class StopWatchAction < DateTimeAction
2870
-
2871
- def initialize(h={})
2872
-
2873
- options = {
2874
- stopwatch_name: 'timer1',
2875
- option: 0
2876
- }
2877
-
2878
- super(options.merge h)
2879
-
2880
- end
2881
-
2882
- end
2883
-
2884
- # Category: Date/Time
2885
- #
2886
- class SayTimeAction < DateTimeAction
2887
-
2888
- def initialize(h={})
2889
-
2890
- options = {
2891
- :'12_hour' => true
2892
- }
2893
-
2894
- super(options.merge h)
2895
-
2896
- end
2897
-
2898
- def invoke()
2899
- time = ($env and $env[:time]) ? $env[:time] : Time.now
2900
- tformat = @h['12_hour'] ? "%-I:%M%P" : "%H:%M"
2901
- super(time.strftime(tformat))
2902
- end
2903
-
2904
- def to_pc()
2905
- 'say current_time()'
2906
- end
2907
-
2908
- def to_s()
2909
- 'Say Current Time'
2910
- end
2911
-
2912
- end
2913
-
2914
-
2915
- class DeviceAction < Action
2916
-
2917
- def initialize(h={})
2918
- super(h)
2919
- @group = 'device'
2920
- end
2921
-
2922
- end
2923
-
2924
- # Category: Device Actions
2925
- #
2926
- class AndroidShortcutsAction < DeviceAction
2927
-
2928
- def initialize(h={})
2929
-
2930
- options = {
2931
- option: 1
2932
- }
2933
-
2934
- super(options.merge h)
2935
-
2936
- end
2937
-
2938
- end
2939
-
2940
- # Category: Device Actions
2941
- #
2942
- class ClipboardAction < DeviceAction
2943
-
2944
- def initialize(h={})
2945
-
2946
- options = {
2947
- clipboard_text: ''
2948
- }
2949
-
2950
- super(options.merge h)
2951
-
2952
- end
2953
-
2954
- end
2955
-
2956
- # Category: Device Actions
2957
- #
2958
- class PressBackAction < DeviceAction
2959
-
2960
- def initialize(h={})
2961
-
2962
- options = {
2963
- }
2964
-
2965
- super(options.merge h)
2966
-
2967
- end
2968
-
2969
- end
2970
-
2971
- # Category: Device Actions
2972
- #
2973
- class SpeakTextAction < DeviceAction
2974
-
2975
- def initialize(h={})
2976
-
2977
- options = {
2978
- text_to_say: '',
2979
- queue: false,
2980
- read_numbers_individually: false,
2981
- specify_audio_stream: false,
2982
- speed: 0.99,
2983
- pitch: 0.99,
2984
- wait_to_finish: false,
2985
- audio_stream: 0
2986
- }
2987
-
2988
- super(options.merge h)
2989
-
2990
- end
2991
-
2992
- def to_s()
2993
- "Speak Text (%s)" % @h[:text_to_say]
2994
- end
2995
-
2996
- end
2997
-
2998
- # Category: Device Actions
2999
- #
3000
- class UIInteractionAction < DeviceAction
3001
-
3002
- def initialize(h={})
3003
-
3004
- options = {
3005
- ui_interaction_configuration: {:type=>"Copy"},
3006
- action: 2
3007
- }
3008
-
3009
- super(options.merge h)
3010
-
3011
- end
3012
-
3013
- end
3014
-
3015
- # Category: Device Actions
3016
- #
3017
- class VoiceSearchAction < DeviceAction
3018
-
3019
- def initialize(h={})
3020
-
3021
- options = {
3022
- }
3023
-
3024
- super(options.merge h)
3025
-
3026
- end
3027
-
3028
- end
3029
-
3030
-
3031
- class DeviceSettingsAction < Action
3032
-
3033
- def initialize(h={})
3034
- super(h)
3035
- @group = 'devicesettings'
3036
- end
3037
-
3038
- end
3039
-
3040
- # Category: Device Settings
3041
- #
3042
- class ExpandCollapseStatusBarAction < DeviceSettingsAction
3043
-
3044
- def initialize(h={})
3045
-
3046
- options = {
3047
- option: 0
3048
- }
3049
-
3050
- super(options.merge h)
3051
-
3052
- end
3053
-
3054
- end
3055
-
3056
- # Category: Device Settings
3057
- #
3058
- class LaunchHomeScreenAction < DeviceSettingsAction
3059
-
3060
- def initialize(h={})
3061
-
3062
- options = {
3063
- }
3064
-
3065
- super(options.merge h)
3066
-
3067
- end
3068
-
3069
- end
3070
-
3071
- # Category: Device Settings
3072
- #
3073
- class CameraFlashLightAction < DeviceSettingsAction
3074
-
3075
- def initialize(h={})
3076
-
3077
- options = {
3078
- launch_foreground: false,
3079
- state: 0
3080
- }
3081
-
3082
- super(options.merge h)
3083
-
3084
- end
3085
-
3086
- def to_pc()
3087
- 'torch :on'
3088
- end
3089
-
3090
- def to_s()
3091
- 'Torch On'
3092
- end
3093
-
3094
- end
3095
-
3096
- # Category: Device Settings
3097
- #
3098
- class VibrateAction < DeviceSettingsAction
3099
-
3100
- def initialize(h={})
3101
-
3102
- options = {
3103
- vibrate_pattern: 1
3104
- }
3105
-
3106
- super(options.merge h)
3107
-
3108
- end
3109
-
3110
- def to_s()
3111
-
3112
- pattern = [
3113
- 'Blip', 'Short Buzz', 'Long Buzz', 'Rapid', 'Slow', 'Increasing',
3114
- 'Constant', 'Decreasing', 'Final Fantasy', 'Game Over', 'Star Wars',
3115
- 'Mini Blip', 'Micro Blip'
3116
- ]
3117
-
3118
- 'Vibrate ' + "(%s)" % pattern[@h[:vibrate_pattern].to_i]
3119
- end
3120
-
3121
- end
3122
-
3123
- # Category: Device Settings
3124
- #
3125
- class SetAutoRotateAction < DeviceSettingsAction
3126
-
3127
- def initialize(h={})
3128
-
3129
- options = {
3130
- state: 0
3131
- }
3132
-
3133
- super(options.merge h)
3134
-
3135
- end
3136
-
3137
- end
3138
-
3139
- # Category: Device Settings
3140
- #
3141
- class DayDreamAction < DeviceSettingsAction
3142
-
3143
- def initialize(h={})
3144
-
3145
- options = {
3146
- }
3147
-
3148
- super(options.merge h)
3149
-
3150
- end
3151
-
3152
- end
3153
-
3154
- # Category: Device Settings
3155
- #
3156
- class SetKeyboardAction < DeviceSettingsAction
3157
-
3158
- def initialize(h={})
3159
-
3160
- options = {
3161
- }
3162
-
3163
- super(options.merge h)
3164
-
3165
- end
3166
-
3167
- end
3168
-
3169
- # Category: Device Settings
3170
- #
3171
- class SetKeyguardAction < DeviceSettingsAction
3172
-
3173
- def initialize(h={})
3174
-
3175
- options = {
3176
- keyguard_on: true
3177
- }
3178
-
3179
- super(options.merge h)
3180
-
3181
- end
3182
-
3183
- end
3184
-
3185
- # Category: Device Settings
3186
- #
3187
- class CarModeAction < DeviceSettingsAction
3188
-
3189
- def initialize(h={})
3190
-
3191
- options = {
3192
- option: 0
3193
- }
3194
-
3195
- super(options.merge h)
3196
-
3197
- end
3198
-
3199
- end
3200
-
3201
- # Category: Device Settings
3202
- #
3203
- class ChangeKeyboardAction < DeviceSettingsAction
3204
-
3205
- def initialize(h={})
3206
-
3207
- options = {
3208
- keyboard_id: 'com.android.inputmethod.latin/.LatinIME',
3209
- keyboard_name: 'Android Keyboard (AOSP)'
3210
- }
3211
-
3212
- super(options.merge h)
3213
-
3214
- end
3215
-
3216
- end
3217
-
3218
- # Category: Device Settings
3219
- #
3220
- class SetWallpaperAction < DeviceSettingsAction
3221
-
3222
- def initialize(h={})
3223
-
3224
- options = {
3225
- image_name: '6051449505275476553',
3226
- s_screen_options: ["Home Screen", "Lock Screen", "Home + Lock Screen"],
3227
- s_options: ["Image", "Live Wallpaper (Preview Screen)"],
3228
- wallpaper_uri_string: 'content://media/external/images/media/928',
3229
- screen_option: 0,
3230
- option: 0
3231
- }
3232
-
3233
- super(options.merge h)
3234
-
3235
- end
3236
-
3237
- end
3238
-
3239
- class FileAction < Action
3240
-
3241
- def initialize(h={})
3242
- super(h)
3243
- @group = 'file'
3244
- end
3245
-
3246
- end
3247
-
3248
- # Category: Files
3249
- #
3250
- class OpenFileAction < FileAction
3251
-
3252
- def initialize(h={})
3253
-
3254
- options = {
3255
- app_name: '',
3256
- class_name: '',
3257
- package_name: '',
3258
- file_path: ''
3259
- }
3260
-
3261
- super(options.merge h)
3262
-
3263
- end
3264
-
3265
- end
3266
-
3267
-
3268
- class LocationAction < Action
3269
-
3270
- def initialize(h={})
3271
- super(h)
3272
- @group = 'location'
3273
- end
3274
-
3275
- end
3276
-
3277
- # Category: Location
3278
- #
3279
- class ForceLocationUpdateAction < LocationAction
3280
-
3281
- def initialize(h={})
3282
-
3283
- options = {
3284
- }
3285
-
3286
- super(options.merge h)
3287
-
3288
- end
3289
-
3290
- end
3291
-
3292
- # Category: Location
3293
- #
3294
- class ShareLocationAction < LocationAction
3295
-
3296
- def initialize(h={})
3297
-
3298
- options = {
3299
- email: '',
3300
- variable: {:m_stringValue=>"", :m_name=>"", :m_decimalValue=>0.0, :isLocal=>true, :m_booleanValue=>false, :excludeFromLog=>false, :m_intValue=>0, :m_type=>2},
3301
- sim_id: 0,
3302
- output_channel: 5,
3303
- old_variable_format: true
3304
- }
3305
-
3306
- super(options.merge h)
3307
-
3308
- end
3309
-
3310
- end
3311
-
3312
- # Category: Location
3313
- #
3314
- class SetLocationUpdateRateAction < LocationAction
3315
-
3316
- def initialize(h={})
3317
-
3318
- options = {
3319
- update_rate: 0,
3320
- update_rate_seconds: 600
3321
- }
3322
-
3323
- super(options.merge h)
3324
-
3325
- end
3326
-
3327
- end
3328
-
3329
- class LoggingAction < Action
3330
-
3331
- def initialize(h={})
3332
- super(h)
3333
- @group = 'logging'
3334
- end
3335
-
3336
- end
3337
-
3338
- # Category: Logging
3339
- #
3340
- class AddCalendarEntryAction < LoggingAction
3341
-
3342
- def initialize(h={})
3343
-
3344
- options = {
3345
- title: '',
3346
- duration_value: '0',
3347
- calendar_id: '3',
3348
- detail: '',
3349
- availability: 0,
3350
- fixed_days: 16,
3351
- fixed_hour: 0,
3352
- fixed_minute: 0,
3353
- fixed_months: 8,
3354
- fixed_time: true,
3355
- relative_days: 0,
3356
- relative_hours: 0,
3357
- relative_minutes: 0,
3358
- all_day_event: true
3359
- }
3360
-
3361
- super(options.merge h)
3362
-
3363
- end
3364
-
3365
- end
3366
-
3367
- # Category: Logging
3368
- #
3369
- class LogAction < LoggingAction
3370
-
3371
- def initialize(h={})
3372
-
3373
- options = {
3374
- log_text: '',
3375
- log_date_and_time: true
3376
- }
3377
-
3378
- super(options.merge h)
3379
-
3380
- end
3381
-
3382
- end
3383
-
3384
- # Category: Logging
3385
- #
3386
- class ClearLogAction < LoggingAction
3387
-
3388
- def initialize(h={})
3389
-
3390
- options = {
3391
- user_log: true
3392
- }
3393
-
3394
- super(options.merge h)
3395
-
3396
- end
3397
-
3398
- end
3399
-
3400
- class PauseAction < Action
3401
-
3402
- def initialize(h={})
3403
-
3404
- options = {
3405
- delay_in_milli_seconds: 0, delay_in_seconds: 1, use_alarm: false
3406
- }
3407
- super(h)
3408
-
3409
- end
3410
-
3411
- def to_s()
3412
-
3413
- su = Subunit.new(units={minutes:60, hours:60},
3414
- seconds: @h[:delay_in_seconds])
3415
-
3416
- ms = @h[:delay_in_milli_seconds]
3417
-
3418
- duration = if su.to_h.has_key?(:minutes) or (ms < 1) then
3419
- su.strfunit("%X")
3420
- else
3421
- "%s %s ms" % [su.strfunit("%X"), ms]
3422
- end
3423
-
3424
- "Wait " + duration
3425
- end
3426
-
3427
- end
3428
-
3429
- class MediaAction < Action
3430
-
3431
- def initialize(h={})
3432
- super(h)
3433
- @group = 'media'
3434
- end
3435
-
3436
- end
3437
-
3438
- # Category: Media
3439
- #
3440
- class RecordMicrophoneAction < MediaAction
3441
-
3442
- def initialize(h={})
3443
-
3444
- options = {
3445
- path: '/storage/emulated/0/MacroDroid/Recordings',
3446
- record_time_string: 'Cancel Recording',
3447
- recording_format: 0,
3448
- seconds_to_record_for: -2
3449
- }
3450
-
3451
- super(options.merge h)
3452
-
3453
- end
3454
-
3455
- end
3456
-
3457
- # Category: Media
3458
- #
3459
- class PlaySoundAction < MediaAction
3460
-
3461
- def initialize(h={})
3462
-
3463
- options = {
3464
- selected_index: 0,
3465
- file_path: ''
3466
- }
3467
-
3468
- super(options.merge h)
3469
-
3470
- end
3471
-
3472
- def to_s()
3473
- 'Play: ' + @h[:file_path]
3474
- end
3475
-
3476
- end
3477
-
3478
-
3479
- class MessagingAction < Action
3480
-
3481
- def initialize(h={})
3482
- super(h)
3483
- @group = 'messaging'
3484
- end
3485
-
3486
- end
3487
-
3488
- # Category: Messaging
3489
- #
3490
- class SendEmailAction < MessagingAction
3491
-
3492
- def initialize(h={})
3493
-
3494
- options = {
3495
- subject: '',
3496
- body: '',
3497
- email_address: '',
3498
- from_email_address: '',
3499
- attach_user_log: false,
3500
- attach_log: false,
3501
- send_option: 0
3502
- }
3503
-
3504
- super(options.merge h)
3505
-
3506
- end
3507
-
3508
- end
3509
-
3510
- # Category: Messaging
3511
- #
3512
- class SendSMSAction < MessagingAction
3513
-
3514
- def initialize(h={})
3515
-
3516
- options = {
3517
- number: '',
3518
- contact: {:m_id=>"Hardwired_Number", :m_lookupKey=>"Hardwired_Number", :m_name=>"[Select Number]"},
3519
- message_content: '',
3520
- add_to_message_log: false,
3521
- pre_populate: false,
3522
- sim_id: 0
3523
- }
3524
-
3525
- super(options.merge h)
3526
-
3527
- end
3528
-
3529
- end
3530
-
3531
- # Category: Messaging
3532
- #
3533
- class UDPCommandAction < MessagingAction
3534
-
3535
- def initialize(h={})
3536
-
3537
- options = {
3538
- destination: '',
3539
- message: '',
3540
- port: 1024
3541
- }
3542
-
3543
- super(options.merge h)
3544
-
3545
- end
3546
-
3547
- end
3548
-
3549
-
3550
- class NotificationsAction < Action
3551
-
3552
- def initialize(h={})
3553
- super(h)
3554
- @group = 'notifications'
3555
- end
3556
-
3557
- end
3558
-
3559
- # Category: Notifications
3560
- #
3561
- class ClearNotificationsAction < NotificationsAction
3562
-
3563
- def initialize(h={})
3564
-
3565
- options = {
3566
- package_name_list: [],
3567
- match_text: '',
3568
- application_name_list: [],
3569
- clear_persistent: false,
3570
- excludes: false,
3571
- match_option: 0,
3572
- age_in_seconds: 0,
3573
- option: 0,
3574
- enable_regex: false
3575
- }
3576
-
3577
- super(options.merge h)
3578
-
3579
- end
3580
-
3581
- end
3582
-
3583
- # Category: Notifications
3584
- #
3585
- class MessageDialogAction < NotificationsAction
3586
-
3587
- def initialize(h={})
3588
-
3589
- options = {
3590
- secondary_class_type: 'MessageDialogAction',
3591
- ringtone_name: 'Default',
3592
- notification_text: '',
3593
- notification_subject: '',
3594
- macro_guid_to_run: -0,
3595
- notification_channel_type: 0,
3596
- image_resource_id: 0,
3597
- overwrite_existing: false,
3598
- priority: 0,
3599
- ringtone_index: 0,
3600
- icon_bg_color: -1762269,
3601
- run_macro_when_pressed: false
3602
- }
3603
-
3604
- super(options.merge h)
3605
-
3606
- end
3607
-
3608
- end
3609
-
3610
- # Category: Notifications
3611
- #
3612
- class AllowLEDNotificationLightAction < NotificationsAction
3613
-
3614
- def initialize(h={})
3615
-
3616
- options = {
3617
- enabled: true
3618
- }
3619
-
3620
- super(options.merge h)
3621
-
3622
- end
3623
-
3624
- end
3625
-
3626
- # Category: Notifications
3627
- #
3628
- class SetNotificationSoundAction < NotificationsAction
3629
-
3630
- def initialize(h={})
3631
-
3632
- options = {
3633
- ringtone_uri: 'content://media/internal/audio/media/27'
3634
- }
3635
-
3636
- super(options.merge h)
3637
-
3638
- end
3639
-
3640
- end
3641
-
3642
- # Category: Notifications
3643
- #
3644
- class SetNotificationSoundAction < NotificationsAction
3645
-
3646
- def initialize(h={})
3647
-
3648
- options = {
3649
- ringtone_uri: 'content://media/internal/audio/media/51'
3650
- }
3651
-
3652
- super(options.merge h)
3653
-
3654
- end
3655
-
3656
- end
3657
-
3658
- # Category: Notifications
3659
- #
3660
- class SetNotificationSoundAction < NotificationsAction
3661
-
3662
- def initialize(h={})
3663
-
3664
- options = {
3665
- ringtone_name: 'None'
3666
- }
3667
-
3668
- super(options.merge h)
3669
-
3670
- end
3671
-
3672
- end
3673
-
3674
- # Category: Notifications
3675
- #
3676
- class NotificationAction < NotificationsAction
3677
-
3678
- def initialize(h={})
3679
-
3680
- h[:notification_subject] = h[:subject] if h[:subject]
3681
- h[:notification_text] = h[:text] if h[:text]
3682
-
3683
- options = {
3684
- ringtone_name: 'Default',
3685
- notification_text: '',
3686
- notification_subject: '',
3687
- macro_guid_to_run: 0,
3688
- notification_channel_type: 0,
3689
- image_resource_id: 0,
3690
- overwrite_existing: false,
3691
- priority: 0,
3692
- ringtone_index: 0,
3693
- icon_bg_color: -1762269,
3694
- run_macro_when_pressed: false
3695
- }
3696
-
3697
- super(options.merge filter(options, h))
3698
-
3699
- end
3700
-
3701
- def to_s()
3702
- 'Display Notification: ' + "%s: %s" % [@h[:notification_subject], @h[:notification_text]]
3703
- end
3704
-
3705
- end
3706
-
3707
- # Category: Notifications
3708
- #
3709
- class ToastAction < NotificationsAction
3710
-
3711
- def initialize(h={})
3712
-
3713
- if h[:msg] then
3714
- h[:message_text] = h[:msg]
3715
- h.delete :msg
3716
- end
3717
-
3718
- options = {
3719
- message_text: '',
3720
- image_resource_name: 'launcher_no_border',
3721
- image_package_name: 'com.arlosoft.macrodroid',
3722
- image_name: 'launcher_no_border',
3723
- duration: 0,
3724
- display_icon: true,
3725
- background_color: -12434878,
3726
- position: 0
3727
- }
3728
-
3729
- super(options.merge h)
3730
-
3731
- end
3732
-
3733
- def invoke()
3734
- super(@h[:message_text])
3735
- end
3736
-
3737
- def to_pc()
3738
- "popup_message '%s'" % @h[:message_text]
3739
- end
3740
-
3741
- def to_s()
3742
- "Popup Message '%s'" % @h[:message_text]
3743
- end
3744
-
3745
- end
3746
-
3747
-
3748
- class PhoneAction < Action
3749
-
3750
- def initialize(h={})
3751
- super(h)
3752
- @group = 'phone'
3753
- end
3754
-
3755
- end
3756
-
3757
- # Category: Phone
3758
- #
3759
- class AnswerCallAction < PhoneAction
3760
-
3761
- def initialize(h={})
3762
-
3763
- options = {
3764
- selected_index: 0
3765
- }
3766
-
3767
- super(options.merge h)
3768
-
3769
- end
3770
-
3771
- end
3772
-
3773
- # Category: Phone
3774
- #
3775
- class ClearCallLogAction < PhoneAction
3776
-
3777
- def initialize(h={})
3778
-
3779
- options = {
3780
- non_contact: false,
3781
- specific_contact: false,
3782
- type: 0
3783
- }
3784
-
3785
- super(options.merge h)
3786
-
3787
- end
3788
-
3789
- end
3790
-
3791
- # Category: Phone
3792
- #
3793
- class OpenCallLogAction < PhoneAction
3794
-
3795
- def initialize(h={})
3796
-
3797
- options = {
3798
- }
3799
-
3800
- super(options.merge h)
3801
-
3802
- end
3803
-
3804
- end
3805
-
3806
- # Category: Phone
3807
- #
3808
- class RejectCallAction < PhoneAction
3809
-
3810
- def initialize(h={})
3811
-
3812
- options = {
3813
- }
3814
-
3815
- super(options.merge h)
3816
-
3817
- end
3818
-
3819
- end
3820
-
3821
- # Category: Phone
3822
- #
3823
- class MakeCallAction < PhoneAction
3824
-
3825
- def initialize(h={})
3826
-
3827
- options = {
3828
- contact: {:m_id=>"Hardwired_Number", :m_lookupKey=>"Hardwired_Number", :m_name=>"[Select Number]"},
3829
- number: ''
3830
- }
3831
-
3832
- super(options.merge h)
3833
-
3834
- end
3835
-
3836
- end
3837
-
3838
-
3839
- # Category: Phone
3840
- #
3841
- class SetRingtoneAction < PhoneAction
3842
-
3843
- def initialize(h={})
3844
-
3845
- options = {
3846
- ringtone_uri: 'content://media/internal/audio/media/174'
3847
- }
3848
-
3849
- super(options.merge h)
3850
-
3851
- end
3852
-
3853
- end
3854
-
3855
- class ScreenAction < Action
3856
-
3857
- def initialize(h={})
3858
- super(h)
3859
- @group = 'screen'
3860
- end
3861
-
3862
- end
3863
-
3864
- # Category: Screen
3865
- #
3866
- class SetBrightnessAction < ScreenAction
3867
-
3868
- def initialize(h={})
3869
-
3870
- options = {
3871
- brightness_percent: 81,
3872
- force_pie_mode: false,
3873
- brightness: 0
3874
- }
3875
-
3876
- super(options.merge h)
3877
-
3878
- end
3879
-
3880
- end
3881
-
3882
- # Category: Screen
3883
- #
3884
- class ForceScreenRotationAction < ScreenAction
3885
-
3886
- def initialize(h={})
3887
-
3888
- options = {
3889
- option: 0
3890
- }
3891
-
3892
- super(options.merge h)
3893
-
3894
- end
3895
-
3896
- end
3897
-
3898
- # Category: Screen
3899
- #
3900
- class ScreenOnAction < ScreenAction
3901
-
3902
- def initialize(h={})
3903
-
3904
- options = {
3905
- pie_lock_screen: false,
3906
- screen_off: true,
3907
- screen_off_no_lock: false,
3908
- screen_on_alternative: false
3909
- }
3910
-
3911
- super(options.merge h)
3912
-
3913
- end
3914
-
3915
- end
3916
-
3917
- # Category: Screen
3918
- #
3919
- class DimScreenAction < ScreenAction
3920
-
3921
- def initialize(h={})
3922
-
3923
- options = {
3924
- percent: 50,
3925
- dim_screen_on: true
3926
- }
3927
-
3928
- super(options.merge h)
3929
-
3930
- end
3931
-
3932
- end
3933
-
3934
- # Category: Screen
3935
- #
3936
- # options:
3937
- # keep awake, screen on => enabled: true
3938
- # disable keep awake => enabled: false
3939
- #
3940
- class KeepAwakeAction < ScreenAction
3941
-
3942
- def initialize(h={})
3943
-
3944
- options = {
3945
- enabled: true,
3946
- permanent: true,
3947
- screen_option: 0,
3948
- seconds_to_stay_awake_for: 0
3949
- }
3950
-
3951
- super(options.merge h)
3952
-
3953
- end
3954
-
3955
- def to_s()
3956
-
3957
- screen = @h[:screen_option] == 0 ? 'Screen On' : 'Screen Off'
3958
-
3959
- if @h[:enabled] then
3960
-
3961
- whenx = if @h[:seconds_to_stay_awake_for] == 0 then
3962
-
3963
- 'Until Disabled'
3964
-
3965
- else
3966
- scnds = @h[:seconds_to_stay_awake_for]
3967
- Subunit.new(units={minutes:60, hours:60}, seconds: scnds).strfunit("%x")
3968
- end
3969
-
3970
- 'Keep Device Awake ' + screen + ' ' + whenx
3971
-
3972
- else
3973
- 'Disable Keep Awake'
3974
- end
3975
-
3976
-
3977
- end
3978
- end
3979
-
3980
- # Category: Screen
3981
- #
3982
- class SetScreenTimeoutAction < ScreenAction
3983
-
3984
- def initialize(h={})
3985
-
3986
- options = {
3987
- timeout_delay_string: '1 Minute',
3988
- timeout_delay: 60,
3989
- custom_value_delay: 0
3990
- }
3991
-
3992
- super(options.merge h)
3993
-
3994
- end
3995
-
3996
- end
3997
-
3998
-
3999
- class VolumeAction < Action
4000
-
4001
- def initialize(h={})
4002
- super(h)
4003
- @group = 'volume'
4004
- end
4005
-
4006
- end
4007
-
4008
- # Category: Volume
4009
- #
4010
- class SilentModeVibrateOffAction < VolumeAction
4011
-
4012
- def initialize(h={})
4013
-
4014
- options = {
4015
- option: 1
4016
- }
4017
-
4018
- super(options.merge h)
4019
-
4020
- end
4021
-
4022
- end
4023
-
4024
- # Category: Volume
4025
- #
4026
- class SetVibrateAction < VolumeAction
4027
-
4028
- def initialize(h={})
4029
-
4030
- options = {
4031
- option: 'Silent (Vibrate On)',
4032
- option_int: -1
4033
- }
4034
-
4035
- super(options.merge h)
4036
-
4037
- end
4038
-
4039
- end
4040
-
4041
- # Category: Volume
4042
- #
4043
- class VolumeIncrementDecrementAction < VolumeAction
4044
-
4045
- def initialize(h={})
4046
-
4047
- options = {
4048
- volume_up: true
4049
- }
4050
-
4051
- super(options.merge h)
4052
-
4053
- end
4054
-
4055
- end
4056
-
4057
- # Category: Volume
4058
- #
4059
- class SpeakerPhoneAction < VolumeAction
4060
-
4061
- def initialize(h={})
4062
-
4063
- options = {
4064
- secondary_class_type: 'SpeakerPhoneAction',
4065
- state: 0
4066
- }
4067
-
4068
- super(options.merge h)
4069
-
4070
- end
4071
-
4072
- end
4073
-
4074
- # Category: Volume
4075
- #
4076
- class SetVolumeAction < VolumeAction
4077
-
4078
- def initialize(h={})
4079
-
4080
- options = {
4081
- variables: [nil, nil, nil, nil, nil, nil, nil],
4082
- stream_index_array: [false, false, false, false, false, false, true],
4083
- stream_volume_array: [0, 0, 0, 0, 0, 0, 66],
4084
- force_vibrate_off: false,
4085
- volume: -1
4086
- }
4087
-
4088
- super(options.merge h)
4089
-
4090
- end
4091
-
4092
- def to_s()
4093
- volume = @h[:stream_index_array].zip(@h[:stream_volume_array]).to_h[true]
4094
- 'Volume Change ' + "Notification = %s%%" % volume
4095
- end
4096
- end
4097
-
4098
- class Constraint < MacroObject
4099
-
4100
- def initialize(h={})
4101
- super(h)
4102
- end
4103
-
4104
- def match?(detail={}, model=nil)
4105
-
4106
- detail.select {|k,v| @h.include? k }.all? {|key,value| @h[key] == value}
4107
-
4108
- end
4109
-
4110
- #def to_s()
4111
- # ''
4112
- #end
4113
-
4114
- protected
4115
-
4116
- def toggle_match?(key, val)
4117
-
4118
- if @h[key] == true and val == key.to_s then
4119
- true
4120
- elsif @h[key] == false and val != key.to_s
4121
- true
4122
- else
4123
- false
4124
- end
4125
-
4126
- end
4127
-
4128
- end
4129
-
4130
- class TimeOfDayConstraint < Constraint
4131
-
4132
- def initialize(h={})
4133
-
4134
- options = {
4135
- end_hour: 8,
4136
- end_minute: 0,
4137
- start_hour: 22,
4138
- start_minute: 0
4139
- }
4140
-
4141
- super(options.merge h)
4142
-
4143
- end
4144
-
4145
- end
4146
-
4147
- # Category: Battery/Power
4148
- #
4149
- class BatteryLevelConstraint < Constraint
4150
-
4151
- def initialize(h={})
4152
-
4153
- options = {
4154
- battery_level: 23,
4155
- equals: false,
4156
- greater_than: false
4157
- }
4158
-
4159
- super(options.merge h)
4160
-
4161
- end
4162
-
4163
- def to_s()
4164
-
4165
- operator = if @h[:greater_than] then
4166
- '>'
4167
- elsif @h[:equals]
4168
- '='
4169
- else
4170
- '<'
4171
- end
4172
-
4173
- level = @h[:battery_level]
4174
-
4175
- "Battery %s %s%%" % [operator, level]
4176
- end
4177
-
4178
- end
4179
-
4180
- # Category: Battery/Power
4181
- #
4182
- class BatterySaverStateConstraint < Constraint
4183
-
4184
- def initialize(h={})
4185
-
4186
- options = {
4187
- option: 0
4188
- }
4189
-
4190
- super(options.merge h)
4191
-
4192
- end
4193
-
4194
- end
4195
-
4196
- # Category: Battery/Power
4197
- #
4198
- class BatteryTemperatureConstraint < Constraint
4199
-
4200
- def initialize(h={})
4201
-
4202
- options = {
4203
- equals: false,
4204
- greater_than: false,
4205
- temperature: 30
4206
- }
4207
-
4208
- super(options.merge h)
4209
-
4210
- end
4211
-
4212
- end
4213
-
4214
- # Category: Battery/Power
4215
- #
4216
- class ExternalPowerConstraint < Constraint
4217
-
4218
- def initialize(h={})
4219
-
4220
- options = {
4221
- external_power: true,
4222
- power_connected_options: [false, true, false]
4223
- }
4224
-
4225
- super(options.merge h)
4226
-
4227
- end
4228
-
4229
- def to_s()
4230
- connection = @h[:external_power] ? 'Connected' : 'Disconnected'
4231
- 'Power ' + connection
4232
- end
4233
-
4234
- end
4235
-
4236
- # Category: Connectivity
4237
- #
4238
- class BluetoothConstraint < Constraint
4239
-
4240
- def initialize(h={})
4241
-
4242
- options = {
4243
- any_device: false,
4244
- bt_state: 0,
4245
- device_name: 'Any Device'
4246
- }
4247
-
4248
- super(options.merge h)
4249
-
4250
- end
4251
-
4252
- def to_s()
4253
- device = @h[:device_name] #== 'Any Device' ? 'Any' : @h[:device_name]
4254
- "Device Connected (%s)" % device
4255
- end
4256
-
4257
-
4258
- end
4259
-
4260
- # Category: Connectivity
4261
- #
4262
- class GPSEnabledConstraint < Constraint
4263
-
4264
- def initialize(h={})
4265
-
4266
- options = {
4267
- enabled: true
4268
- }
4269
-
4270
- super(options.merge h)
4271
-
4272
- end
4273
-
4274
- end
4275
-
4276
- # Category: Connectivity
4277
- #
4278
- class LocationModeConstraint < Constraint
4279
-
4280
- def initialize(h={})
4281
-
4282
- options = {
4283
- options: [false, false, false, true]
4284
- }
4285
-
4286
- super(options.merge h)
4287
-
4288
- end
4289
-
4290
- end
4291
-
4292
- # Category: Connectivity
4293
- #
4294
- class SignalOnOffConstraint < Constraint
4295
-
4296
- def initialize(h={})
4297
-
4298
- options = {
4299
- option: 0
4300
- }
4301
-
4302
- super(options.merge h)
4303
-
4304
- end
4305
-
4306
- end
4307
-
4308
- # Category: Connectivity
4309
- #
4310
- class WifiConstraint < Constraint
4311
-
4312
- def initialize(h={})
4313
-
4314
- options = {
4315
- ssid_list: [],
4316
- wifi_state: 0
4317
- }
4318
-
4319
- super(options.merge h)
4320
-
4321
- end
4322
-
4323
- end
4324
-
4325
- # Category: Connectivity
4326
- #
4327
- class CellTowerConstraint < Constraint
4328
-
4329
- def initialize(h={})
4330
-
4331
- options = {
4332
- cell_group_name: 'test group',
4333
- cell_ids: ["524,14,41070731"],
4334
- in_range: true
4335
- }
4336
-
4337
- super(options.merge h)
4338
-
4339
- end
4340
-
4341
- end
4342
-
4343
- # Category: Connectivity
4344
- #
4345
- class IsRoamingConstraint < Constraint
4346
-
4347
- def initialize(h={})
4348
-
4349
- options = {
4350
- is_roaming: true
4351
- }
4352
-
4353
- super(options.merge h)
4354
-
4355
- end
4356
-
4357
- end
4358
-
4359
- # Category: Connectivity
4360
- #
4361
- class DataOnOffConstraint < Constraint
4362
-
4363
- def initialize(h={})
4364
-
4365
- options = {
4366
- data_on: true
4367
- }
4368
-
4369
- super(options.merge h)
4370
-
4371
- end
4372
-
4373
- end
4374
-
4375
- # Category: Connectivity
4376
- #
4377
- class WifiHotSpotConstraint < Constraint
4378
-
4379
- def initialize(h={})
4380
-
4381
- options = {
4382
- check_connections: false,
4383
- comparison_value: 0,
4384
- connected_count: 0,
4385
- enabled: true
4386
- }
4387
-
4388
- super(options.merge h)
4389
-
4390
- end
4391
-
4392
- end
4393
-
4394
- # Category: Date/Time
4395
- #
4396
- class CalendarConstraint < Constraint
4397
-
4398
- def initialize(h={})
4399
-
4400
- options = {
4401
- enable_regex: false,
4402
- availability: 0,
4403
- calendar_id: '1',
4404
- calendar_name: 'PC Sync',
4405
- detail_text: '',
4406
- entry_set: true,
4407
- ignore_all_day: false,
4408
- title_text: ''
4409
- }
4410
-
4411
- super(options.merge h)
4412
-
4413
- end
4414
-
4415
- end
4416
-
4417
- # Category: Date/Time
4418
- #
4419
- class DayOfWeekConstraint < Constraint
4420
-
4421
- def initialize(h={})
4422
-
4423
- options = {
4424
- days_of_week: [false, false, true, false, false, false, false]
4425
- }
4426
-
4427
- super(options.merge h)
4428
-
4429
- end
4430
-
4431
- end
4432
-
4433
- # Category: Date/Time
4434
- #
4435
- class TimeOfDayConstraint < Constraint
4436
-
4437
- def initialize(h={})
4438
-
4439
- options = {
4440
- end_hour: 1,
4441
- end_minute: 1,
4442
- start_hour: 21,
4443
- start_minute: 58
4444
- }
4445
-
4446
- super(options.merge h)
4447
-
4448
- end
4449
-
4450
- end
4451
-
4452
- # Category: Date/Time
4453
- #
4454
- class DayOfMonthConstraint < Constraint
4455
-
4456
- def initialize(h={})
4457
-
4458
- options = {
4459
- 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"],
4460
- 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]
4461
- }
4462
-
4463
- super(options.merge h)
4464
-
4465
- end
4466
-
4467
- end
4468
-
4469
- # Category: Date/Time
4470
- #
4471
- class MonthOfYearConstraint < Constraint
4472
-
4473
- def initialize(h={})
4474
-
4475
- options = {
4476
- months: [false, false, false, false, false, false, false, true, false, false, false, false]
4477
- }
4478
-
4479
- super(options.merge h)
4480
-
4481
- end
4482
-
4483
- end
4484
-
4485
- # Category: Date/Time
4486
- #
4487
- class SunsetSunriseConstraint < Constraint
4488
-
4489
- def initialize(h={})
4490
-
4491
- options = {
4492
- option: 0
4493
- }
4494
-
4495
- super(options.merge h)
4496
-
4497
- end
4498
-
4499
- end
4500
-
4501
- # Category: Device State
4502
- #
4503
- class AirplaneModeConstraint < Constraint
4504
-
4505
- def initialize(h={})
4506
-
4507
- options = {
4508
- enabled: true
4509
- }
4510
-
4511
- super(options.merge h)
4512
-
4513
- end
4514
-
4515
- def match?(detail={}, model=nil)
4516
-
4517
- puts 'inside airplaneModeConstraint#match?' if $debug
4518
-
4519
- if detail.has_key? :enabled then
4520
-
4521
- puts 'detail has the key' if $debug
4522
- super(detail)
4523
-
4524
- elsif model
4525
-
4526
- if $debug then
4527
- puts 'checking the model'
4528
- switch = model.connectivity.airplane_mode.switch
4529
- puts 'switch: ' + switch.inspect
4530
- end
4531
-
4532
- toggle_match?(:enabled, switch)
4533
-
4534
- end
4535
-
4536
- end
4537
-
4538
- def to_pc()
4539
- status = @h[:enabled] ? 'enabled?' : 'disabled?'
4540
- 'airplane_mode.' + status
4541
- end
4542
-
4543
- def to_s()
4544
-
4545
- status = @h[:enabled] ? 'Enabled' : 'Disabled'
4546
- 'Airplane Mode ' + status
4547
-
4548
- end
4549
-
4550
- end
4551
-
4552
- # Category: Device State
4553
- #
4554
- class AutoRotateConstraint < Constraint
4555
-
4556
- def initialize(h={})
4557
-
4558
- options = {
4559
- enabled: true
4560
- }
4561
-
4562
- super(options.merge h)
4563
-
4564
- end
4565
-
4566
- end
4567
-
4568
- # Category: Device State
4569
- #
4570
- class DeviceLockedConstraint < Constraint
4571
-
4572
- def initialize(h={})
4573
-
4574
- options = {
4575
- locked: true
4576
- }
4577
-
4578
- super(options.merge h)
4579
-
4580
- end
4581
-
4582
- def to_s()
4583
- 'Device ' + (@h[:locked] ? 'Locked' : 'Unlocked')
4584
- end
4585
-
4586
- end
4587
-
4588
- # Category: Device State
4589
- #
4590
- class RoamingOnOffConstraint < Constraint
4591
-
4592
- def initialize(h={})
4593
-
4594
- options = {
4595
- roaming_on: true
4596
- }
4597
-
4598
- super(options.merge h)
4599
-
4600
- end
4601
-
4602
- end
4603
-
4604
- # Category: Device State
4605
- #
4606
- class TimeSinceBootConstraint < Constraint
4607
-
4608
- def initialize(h={})
4609
-
4610
- options = {
4611
- less_than: true,
4612
- time_period_seconds: 10921
4613
- }
4614
-
4615
- super(options.merge h)
4616
-
4617
- end
4618
-
4619
- end
4620
-
4621
- # Category: Device State
4622
- #
4623
- class AutoSyncConstraint < Constraint
4624
-
4625
- def initialize(h={})
4626
-
4627
- options = {
4628
- enabled: false
4629
- }
4630
-
4631
- super(options.merge h)
4632
-
4633
- end
4634
-
4635
- end
4636
-
4637
- # Category: Device State
4638
- #
4639
- class NFCStateConstraint < Constraint
4640
-
4641
- def initialize(h={})
4642
-
4643
- options = {
4644
- enabled: true
4645
- }
4646
-
4647
- super(options.merge h)
4648
-
4649
- end
4650
-
4651
- end
4652
-
4653
- # Category: Device State
4654
- #
4655
- class IsRootedConstraint < Constraint
4656
-
4657
- def initialize(h={})
4658
-
4659
- options = {
4660
- rooted: true
4661
- }
4662
-
4663
- super(options.merge h)
4664
-
4665
- end
4666
-
4667
- end
4668
-
4669
- # Category: Device State
4670
- #
4671
- class VpnConstraint < Constraint
4672
-
4673
- def initialize(h={})
4674
-
4675
- options = {
4676
- option: 0
4677
- }
4678
-
4679
- super(options.merge h)
4680
-
4681
- end
4682
-
4683
- end
4684
-
4685
- # Category: MacroDroid Specific
4686
- #
4687
- class MacroEnabledConstraint < Constraint
4688
-
4689
- def initialize(h={})
4690
-
4691
- options = {
4692
- enabled: true,
4693
- macro_ids: [-8016812002629322290],
4694
- macro_names: ["Intruder photo "]
4695
- }
4696
-
4697
- super(options.merge h)
4698
-
4699
- end
4700
-
4701
- end
4702
-
4703
- # Category: MacroDroid Specific
4704
- #
4705
- class ModeConstraint < Constraint
4706
-
4707
- def initialize(h={})
4708
-
4709
- options = {
4710
- mode: 'Away',
4711
- mode_selected: true
4712
- }
4713
-
4714
- super(options.merge h)
4715
-
4716
- end
4717
-
4718
- end
4719
-
4720
- # Category: MacroDroid Specific
4721
- #
4722
- class TriggerThatInvokedConstraint < Constraint
4723
- using ColouredText
4724
-
4725
- def initialize(h={})
4726
-
4727
- puts ('h: ' + h.inspect).green
4728
- @trigger = h[:macro].triggers.find {|x| x.siguid == h[:si_guid_that_invoked] }
4729
-
4730
- options = {
4731
- not: false,
4732
- si_guid_that_invoked: -4951291100076165433,
4733
- trigger_name: 'Shake Device'
4734
- }
4735
-
4736
- super(options.merge filter(options,h))
4737
-
4738
- end
4739
-
4740
- def to_s()
4741
- 'Trigger Fired: ' + @trigger.to_s
4742
- end
4743
-
4744
- end
4745
-
4746
- # Category: MacroDroid Specific
4747
- #
4748
- class LastRunTimeConstraint < Constraint
4749
-
4750
- def initialize(h={})
4751
-
4752
- options = {
4753
- check_this_macro: false,
4754
- invoked: true,
4755
- macro_ids: [-6922688338672048267],
4756
- macro_names: ["Opendoor"],
4757
- time_period_seconds: 7260
4758
- }
4759
-
4760
- super(options.merge h)
4761
-
4762
- end
4763
-
4764
- end
4765
-
4766
- # Category: Media
4767
- #
4768
- class HeadphonesConnectionConstraint < Constraint
4769
-
4770
- def initialize(h={})
4771
-
4772
- options = {
4773
- connected: true
4774
- }
4775
-
4776
- super(options.merge h)
4777
-
4778
- end
4779
-
4780
- def to_s()
4781
- connection = @h[:connected] ? 'Connected' : 'Disconnected'
4782
- 'Headphones ' + connection
4783
- end
4784
-
4785
- end
4786
-
4787
- # Category: Media
4788
- #
4789
- class MusicActiveConstraint < Constraint
4790
-
4791
- def initialize(h={})
4792
-
4793
- options = {
4794
- music_active: true
4795
- }
4796
-
4797
- super(options.merge h)
4798
-
4799
- end
4800
-
4801
- end
4802
-
4803
- # Category: Notification
4804
- #
4805
- class NotificationPresentConstraint < Constraint
4806
-
4807
- def initialize(h={})
4808
-
4809
- options = {
4810
- enable_regex: false,
4811
- application_name_list: ["All applications"],
4812
- exact_match: false,
4813
- excludes: false,
4814
- excludes_apps: -1,
4815
- option: 0,
4816
- package_name_list: ["allApplications"],
4817
- text_content: ''
4818
- }
4819
-
4820
- super(options.merge h)
4821
-
4822
- end
4823
-
4824
- end
4825
-
4826
- # Category: Notification
4827
- #
4828
- class PriorityModeConstraint < Constraint
4829
-
4830
- def initialize(h={})
4831
-
4832
- options = {
4833
- in_mode: true,
4834
- selected_index: 0
4835
- }
4836
-
4837
- super(options.merge h)
4838
-
4839
- end
4840
-
4841
- end
4842
-
4843
- # Category: Notification
4844
- #
4845
- class NotificationVolumeConstraint < Constraint
4846
-
4847
- def initialize(h={})
4848
-
4849
- options = {
4850
- option: 1
4851
- }
4852
-
4853
- super(options.merge h)
4854
-
4855
- end
4856
-
4857
- end
4858
-
4859
- # Category: Phone
4860
- #
4861
- class InCallConstraint < Constraint
4862
-
4863
- def initialize(h={})
4864
-
4865
- options = {
4866
- in_call: true
4867
- }
4868
-
4869
- super(options.merge h)
4870
-
4871
- end
4872
-
4873
- end
4874
-
4875
- # Category: Phone
4876
- #
4877
- class PhoneRingingConstraint < Constraint
4878
-
4879
- def initialize(h={})
4880
-
4881
- options = {
4882
- ringing: true
4883
- }
4884
-
4885
- super(options.merge h)
4886
-
4887
- end
4888
-
4889
- end
4890
-
4891
- # Category: Screen and Speaker
4892
- #
4893
- class BrightnessConstraint < Constraint
4894
-
4895
- def initialize(h={})
4896
-
4897
- options = {
4898
- brightness: 35,
4899
- equals: false,
4900
- force_pie_mode: false,
4901
- greater_than: false,
4902
- is_auto_brightness: false
4903
- }
4904
-
4905
- super(options.merge h)
4906
-
4907
- end
4908
-
4909
- end
4910
-
4911
- # Category: Screen and Speaker
4912
- #
4913
- class VolumeConstraint < Constraint
4914
-
4915
- def initialize(h={})
4916
-
4917
- options = {
4918
- option: 0
4919
- }
4920
-
4921
- super(options.merge filter(options, h))
4922
-
4923
- end
4924
-
4925
- def to_s()
4926
- a = ['Volume On', 'Vibrate Only' 'Silent', 'Vibrate or Silent']
4927
-
4928
- "Ringer Volume\n " + a[@h[:option]]
4929
- end
4930
-
4931
- end
4932
-
4933
- # Category: Screen and Speaker
4934
- #
4935
- class SpeakerPhoneConstraint < Constraint
4936
-
4937
- def initialize(h={})
4938
-
4939
- options = {
4940
- enabled: true
4941
- }
4942
-
4943
- super(options.merge h)
4944
-
4945
- end
4946
-
4947
- end
4948
-
4949
- # Category: Screen and Speaker
4950
- #
4951
- class DarkThemeConstraint < Constraint
4952
-
4953
- def initialize(h={})
4954
-
4955
- options = {
4956
- option: 0
4957
- }
4958
-
4959
- super(options.merge h)
4960
-
4961
- end
4962
-
4963
- end
4964
-
4965
- # Category: Screen and Speaker
4966
- #
4967
- class ScreenOnOffConstraint < Constraint
4968
-
4969
- def initialize(h={})
4970
-
4971
- options = {
4972
- a: true,
4973
- screen_on: true
4974
- }
4975
-
4976
- super(options.merge h)
4977
-
4978
- end
4979
-
4980
- def to_s()
4981
- 'Screen ' + (@h[:screen_on] ? 'On' : 'Off')
4982
- end
4983
-
4984
- end
4985
-
4986
- # Category: Screen and Speaker
4987
- #
4988
- class VolumeLevelConstraint < Constraint
4989
-
4990
- def initialize(h={})
4991
-
4992
- options = {
4993
- comparison: 0,
4994
- stream_index_array: [false, true, false, false, false, false, false],
4995
- volume: 42
4996
- }
4997
-
4998
- super(options.merge h)
4999
-
5000
- end
5001
-
5002
- end
5003
-
5004
- # Category: Sensors
5005
- #
5006
- class FaceUpDownConstraint < Constraint
5007
-
5008
- def initialize(h={})
5009
-
5010
- options = {
5011
- option: -1,
5012
- selected_options: [true, false, true, false, false, false]
5013
- }
5014
-
5015
- super(options.merge h)
5016
-
5017
- end
5018
-
5019
- end
5020
-
5021
- # Category: Sensors
5022
- #
5023
- class LightLevelConstraint < Constraint
5024
-
5025
- def initialize(h={})
5026
-
5027
- options = {
5028
- light_level: -1,
5029
- light_level_float: 5000.0,
5030
- option: 1
5031
- }
5032
-
5033
- super(options.merge h)
5034
-
5035
- end
5036
-
5037
- def to_s()
5038
-
5039
- operator = @h[:light_level] == -1 ? 'Less than' : 'Greater than'
5040
- condition = operator + ' ' + @h[:light_level_float].to_s + 'lx'
5041
- 'Light Sensor ' + condition
5042
-
5043
- end
5044
-
5045
- end
5046
-
5047
- # Category: Sensors
5048
- #
5049
- class DeviceOrientationConstraint < Constraint
5050
-
5051
- def initialize(h={})
5052
-
5053
- options = {
5054
- portrait: true
5055
- }
5056
-
5057
- super(options.merge h)
5058
-
5059
- end
5060
-
5061
- end
5062
-
5063
- # Category: Sensors
5064
- #
5065
- class ProximitySensorConstraint < Constraint
5066
-
5067
- def initialize(h={})
5068
-
5069
- options = {
5070
- near: true
5071
- }
5072
-
5073
- super(options.merge h)
5074
-
5075
- end
5076
-
5077
- def to_s()
5078
- 'Proximity Sensor: ' + (@h[:near] ? 'Near' : 'Far')
5079
- end
5080
-
5081
- end
5082
-
5083
-
5084
- # ----------------------------------------------------------------------------
5085
-
5086
-
5087
- class DroidSim
5088
-
5089
- class Service
5090
- def initialize(callback)
5091
- @callback = callback
5092
- end
5093
- end
5094
-
5095
- class Application < Service
5096
-
5097
- def closed()
5098
- end
5099
- def launched()
5100
- end
5101
- end
5102
-
5103
- class Battery < Service
5104
-
5105
- def level()
5106
- end
5107
-
5108
- def temperature()
5109
- end
5110
-
5111
- end
5112
- class Bluetooth < Service
5113
-
5114
- def enable()
5115
- @callback.on_bluetooth_enabled()
5116
- end
5117
-
5118
- #def enabled
5119
- # @callback.on_bluetooth_enabled()
5120
- #end
5121
-
5122
- def enabled?
5123
- end
5124
-
5125
- def disabled
5126
- end
5127
-
5128
- def disabled?
5129
- end
5130
- end
5131
-
5132
- class Calendar < Service
5133
- def event(starts, ends)
5134
- end
5135
- end
5136
-
5137
- class DayTime < Service
5138
-
5139
- def initialie(s)
5140
- end
5141
- end
5142
-
5143
- class Headphones < Service
5144
- def inserted
5145
- end
5146
-
5147
- def removed
5148
- end
5149
- end
5150
-
5151
- class Webhook < Service
5152
-
5153
- def url()
5154
- @url
5155
- end
5156
-
5157
- def url=(s)
5158
- @url = s
5159
- end
5160
- end
5161
-
5162
- class Wifi < Service
5163
- def enabled
5164
- end
5165
-
5166
- def disabled
5167
- end
5168
-
5169
- def ssid_in_range()
5170
- end
5171
-
5172
- def ssid_out_of_range()
5173
- end
5174
- end
5175
-
5176
- class Power < Service
5177
- def connected()
5178
- end
5179
-
5180
- def disconnected()
5181
- end
5182
-
5183
- def button_toggle()
5184
- end
5185
- end
5186
-
5187
- class Popup < Service
5188
- def message(s)
5189
- puts s
5190
- end
5191
- end
5192
-
5193
-
5194
- attr_reader :bluetooth, :popup
5195
-
5196
- def initialize()
5197
-
5198
- @bluetooth = Bluetooth.new self
5199
- @popup = Popup.new self
5200
-
5201
- end
5202
-
5203
- def on_bluetooth_enabled()
5204
-
5205
- end
5206
-
5207
-
5208
- end
1161
+ require 'ruby-macrodroid/base'
1162
+ require 'ruby-macrodroid/triggers'
1163
+ require 'ruby-macrodroid/actions'
1164
+ require 'ruby-macrodroid/constraints'