remotedroid 0.4.2 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/lib/remotedroid.rb +214 -648
- data/lib/remotedroid/client.rb +167 -0
- data/lib/remotedroid/control.rb +194 -0
- data/lib/remotedroid/controller.rb +170 -0
- data/lib/remotedroid/model.rb +227 -0
- data/lib/remotedroid/query.rb +60 -0
- metadata +9 -4
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 99592d4ac1baaef0d04b87d8bb9dd6cfcbdfc5572dacc39c6fabbd5a960f85f3
|
4
|
+
data.tar.gz: a5fbd36d797423dd183dccbb2351736ac58f706acf3b88932ae737d43e55a8e9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 893732ed1fb124c982bdcd6b55d4d2f54acd9a32256d707cde13a13d86fb9547a9b126ab6200b98ed211ae739cf42e95136c5fe444fbd435646607b6e8fda9a7
|
7
|
+
data.tar.gz: a651dd655ab1dcb59549d7abd5d32a948f4fbf04ec134f9c35ff104ff7f9def9308a8f8acf9751e7cefa27e7ca4517af7e310a5603de6ab6a196271a1ca54b5c
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data.tar.gz.sig
CHANGED
Binary file
|
data/lib/remotedroid.rb
CHANGED
@@ -8,21 +8,45 @@ require 'app-routes'
|
|
8
8
|
require 'sps-sub'
|
9
9
|
require 'ruby-macrodroid'
|
10
10
|
|
11
|
+
# PASTE_START
|
11
12
|
|
12
13
|
# Here's what's available so far:
|
13
14
|
#
|
14
15
|
# # Triggers
|
15
16
|
#
|
17
|
+
# ## Battery/Power
|
18
|
+
#
|
19
|
+
# * Power button toggle
|
20
|
+
#
|
21
|
+
# ## Connectivity
|
22
|
+
#
|
23
|
+
# ### Wifi State Change
|
24
|
+
#
|
25
|
+
# * Connected to Network
|
26
|
+
#
|
27
|
+
# ## Device Events
|
28
|
+
#
|
29
|
+
# * screen on
|
30
|
+
#
|
16
31
|
# ## Sensors
|
17
|
-
#
|
32
|
+
#
|
33
|
+
# * Activity Recognition
|
18
34
|
# * proximity (near)
|
19
35
|
# * shake device
|
20
36
|
#
|
37
|
+
# ## User Input
|
38
|
+
#
|
39
|
+
# * Swipe Screen
|
40
|
+
#
|
21
41
|
# ------------------------------------
|
22
42
|
#
|
23
43
|
# # Actions
|
24
44
|
#
|
25
|
-
##
|
45
|
+
# ## Camera/Photo
|
46
|
+
#
|
47
|
+
# * Take Picture
|
48
|
+
#
|
49
|
+
# ## Connectivity
|
26
50
|
#
|
27
51
|
# * Enable HotSpot
|
28
52
|
#
|
@@ -40,6 +64,10 @@ require 'ruby-macrodroid'
|
|
40
64
|
#
|
41
65
|
# * Share Location
|
42
66
|
#
|
67
|
+
# ## MacroDroid specific
|
68
|
+
#
|
69
|
+
# * Disable Macro
|
70
|
+
#
|
43
71
|
# ## Media
|
44
72
|
#
|
45
73
|
# * Play sound (Doda)
|
@@ -50,6 +78,7 @@ require 'ruby-macrodroid'
|
|
50
78
|
#
|
51
79
|
# ## Screen
|
52
80
|
#
|
81
|
+
# * Keep Device Awake
|
53
82
|
# * Screen On
|
54
83
|
#
|
55
84
|
|
@@ -152,7 +181,22 @@ a:
|
|
152
181
|
Disable Hotspot
|
153
182
|
End If
|
154
183
|
|
155
|
-
|
184
|
+
m: Take Picture
|
185
|
+
t: webhook
|
186
|
+
a:
|
187
|
+
Take Picture
|
188
|
+
Rear Facing
|
189
|
+
a: wait 2 seconds
|
190
|
+
a: webhook
|
191
|
+
|
192
|
+
m: stay awake
|
193
|
+
t: webhook
|
194
|
+
a: stay awake
|
195
|
+
|
196
|
+
m: stay awake off
|
197
|
+
t: webhook
|
198
|
+
a: stay awake off
|
199
|
+
|
156
200
|
m: Share location
|
157
201
|
t:
|
158
202
|
WebHook
|
@@ -165,7 +209,16 @@ a:
|
|
165
209
|
HTTP GET
|
166
210
|
identifier: location
|
167
211
|
coords: [lv=coords]
|
212
|
+
cell: [cell_id]
|
213
|
+
ssid: [ssid]
|
214
|
+
alt: [last_loc_alt]
|
215
|
+
time: [last_loc_age_timestamp]
|
216
|
+
mph: [last_loc_speed_mph]
|
217
|
+
kph: [last_loc_speed_kmh]
|
218
|
+
device: [device_model]
|
219
|
+
battery: [battery]
|
168
220
|
type: query
|
221
|
+
|
169
222
|
|
170
223
|
m: query
|
171
224
|
t: WebHook
|
@@ -222,586 +275,162 @@ a:
|
|
222
275
|
m: Power connected
|
223
276
|
t: Power Connected: Any
|
224
277
|
a: webhook
|
225
|
-
|
226
|
-
|
227
|
-
EOF
|
228
|
-
|
229
|
-
=begin
|
230
|
-
m: Screen
|
231
|
-
v: on: true
|
232
|
-
t: WebHook
|
233
|
-
a:
|
234
|
-
If on = true
|
235
|
-
Screen On
|
236
|
-
Else
|
237
|
-
Screen Off
|
238
|
-
End If
|
239
|
-
|
240
|
-
=end
|
241
|
-
|
242
|
-
module RemoteDroid
|
243
|
-
|
244
|
-
class Model
|
245
|
-
include AppRoutes
|
246
|
-
|
247
|
-
def initialize(obj=nil, root: 'device1', debug: false)
|
248
|
-
|
249
|
-
super()
|
250
|
-
@root, @debug = root, debug
|
251
|
-
@location = nil
|
252
|
-
|
253
|
-
if obj then
|
254
|
-
|
255
|
-
s = obj.strip
|
256
|
-
|
257
|
-
puts 's: ' + s.inspect if @debug
|
258
|
-
|
259
|
-
if s[0] == '<' or s.lines[1][0..1] == ' ' then
|
260
|
-
|
261
|
-
puts 'before easydom' if @debug
|
262
|
-
|
263
|
-
s2 = if s.lines[1][0..1] == ' ' then
|
264
|
-
|
265
|
-
lines = s.lines.map do |line|
|
266
|
-
line.sub(/(\w+) +is +(\w+)$/) {|x| "#{$1} {switch: #{$2}}" }
|
267
|
-
end
|
268
|
-
|
269
|
-
lines.join
|
270
|
-
|
271
|
-
else
|
272
|
-
s
|
273
|
-
end
|
274
|
-
|
275
|
-
@ed = EasyDom.new(s2)
|
276
|
-
else
|
277
|
-
build(s, root: root)
|
278
|
-
end
|
279
|
-
|
280
|
-
end
|
281
|
-
|
282
|
-
end
|
283
|
-
|
284
|
-
def build(raw_requests, root: @root)
|
285
|
-
|
286
|
-
@ed = EasyDom.new(debug: false, root: root)
|
287
|
-
raw_requests.lines.each {|line| request(line) }
|
288
|
-
|
289
|
-
end
|
290
|
-
|
291
|
-
|
292
|
-
def get_thing(h)
|
293
|
-
|
294
|
-
h[:thing].gsub!(/ /,'_')
|
295
|
-
|
296
|
-
if not h.has_key? :location then
|
297
|
-
location = false
|
298
|
-
h[:location] = find_path(h[:thing])
|
299
|
-
else
|
300
|
-
location = true
|
301
|
-
end
|
302
|
-
|
303
|
-
puts 'h: ' + h.inspect if @debug
|
304
|
-
|
305
|
-
a = []
|
306
|
-
a += h[:location].split(/ /)
|
307
|
-
a << h[:thing]
|
308
|
-
status = a.inject(@ed) {|r,x| r.send(x)}.send(h[:action])
|
309
|
-
|
310
|
-
if location then
|
311
|
-
"The %s %s is %s." % [h[:location], h[:thing], status]
|
312
|
-
else
|
313
|
-
"%s is %s." % [h[:thing].capitalize, status]
|
314
|
-
end
|
315
|
-
|
316
|
-
end
|
317
|
-
|
318
|
-
# Object Property (op)
|
319
|
-
# Helpful for accessing properites in dot notation
|
320
|
-
# e.g. op.livingroom.light.switch = 'off'
|
321
|
-
#
|
322
|
-
def op()
|
323
|
-
@ed
|
324
|
-
end
|
325
|
-
|
326
|
-
def query(s)
|
327
|
-
@ed.e.element(s)
|
328
|
-
end
|
329
|
-
|
330
|
-
# request accepts a string in plain english
|
331
|
-
# e.g. request 'switch the livingroom light on'
|
332
|
-
#
|
333
|
-
def request(s)
|
334
|
-
|
335
|
-
params = {request: s}
|
336
|
-
requests(params)
|
337
|
-
h = find_request(s)
|
338
|
-
|
339
|
-
method(h.first[-1]).call(h).gsub(/_/,' ')
|
340
|
-
|
341
|
-
end
|
342
|
-
|
343
|
-
def set_thing(h)
|
344
|
-
|
345
|
-
h[:thing].gsub!(/ /,'_')
|
346
|
-
h[:location] = find_path(h[:thing]) unless h.has_key? :location
|
347
|
-
|
348
|
-
a = []
|
349
|
-
a += h[:location].split(/ /)
|
350
|
-
a << h[:thing]
|
351
|
-
|
352
|
-
a.inject(@ed) {|r,x| r.send(x)}.send(h[:action], h[:value])
|
353
|
-
|
354
|
-
end
|
355
|
-
|
356
|
-
def to_sliml(level: 0)
|
357
|
-
|
358
|
-
s = @ed.to_sliml
|
359
|
-
|
360
|
-
return s if level.to_i > 0
|
361
|
-
|
362
|
-
lines = s.lines.map do |line|
|
363
|
-
|
364
|
-
line.sub(/\{[^\}]+\}/) do |x|
|
365
|
-
|
366
|
-
a = x.scan(/\w+: +[^ ]+/)
|
367
|
-
if a.length == 1 and x[/switch:/] then
|
368
278
|
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
x
|
373
|
-
end
|
374
|
-
|
375
|
-
end
|
376
|
-
end
|
377
|
-
|
378
|
-
lines.join
|
379
|
-
|
380
|
-
end
|
381
|
-
|
382
|
-
def to_xml(options=nil)
|
383
|
-
@ed.xml(pretty: true).gsub(' style=\'\'','')
|
384
|
-
end
|
385
|
-
|
386
|
-
alias xml to_xml
|
387
|
-
|
388
|
-
# to_xml() is the preferred method
|
389
|
-
|
390
|
-
protected
|
391
|
-
|
392
|
-
def requests(params)
|
393
|
-
|
394
|
-
# e.g. switch the livingroom gas_fire off
|
395
|
-
#
|
396
|
-
get /(?:switch|turn) the ([^ ]+) +([^ ]+) +(on|off)$/ do |location, device, onoff|
|
397
|
-
{type: :set_thing, action: 'switch=', location: location, thing: device, value: onoff}
|
398
|
-
end
|
399
|
-
|
400
|
-
# e.g. switch the gas _fire off
|
401
|
-
#
|
402
|
-
get /(?:switch|turn) the ([^ ]+) +(on|off)$/ do |device, onoff|
|
403
|
-
{type: :set_thing, action: 'switch=', thing: device, value: onoff}
|
404
|
-
end
|
405
|
-
|
406
|
-
# e.g. is the livingroom gas_fire on?
|
407
|
-
#
|
408
|
-
get /is the ([^ ]+) +([^ ]+) +(?:on|off)\??$/ do |location, device|
|
409
|
-
{type: :get_thing, action: 'switch', location: location, thing: device}
|
410
|
-
end
|
411
|
-
|
412
|
-
# e.g. enable airplane mode
|
413
|
-
#
|
414
|
-
get /((?:dis|en)able) ([^$]+)$/ do |state, service|
|
415
|
-
{type: :set_thing, action: 'switch=', thing: service, value: state + 'd'}
|
416
|
-
end
|
417
|
-
|
418
|
-
# e.g. switch airplane mode off
|
419
|
-
#
|
420
|
-
get /switch (.*) (on|off)/ do |service, rawstate|
|
421
|
-
|
422
|
-
state = rawstate == 'on' ? 'enabled' : 'disabled'
|
423
|
-
{type: :set_thing, action: 'switch=', thing: service, value: state}
|
424
|
-
|
425
|
-
end
|
426
|
-
|
427
|
-
# e.g. is airplane mode enabed?
|
428
|
-
#
|
429
|
-
get /is (.*) +(?:(?:dis|en)abled)\??$/ do |service|
|
430
|
-
{type: :get_thing, action: 'switch', thing: service.gsub(/ /,'_')}
|
431
|
-
end
|
432
|
-
|
433
|
-
# e.g. is the gas_fire on?
|
434
|
-
#
|
435
|
-
get /is the ([^ ]+) +(?:on|off)\??$/ do |device|
|
436
|
-
location = find_path(device)
|
437
|
-
{type: :get_thing, action: 'switch', location: location, thing: device}
|
438
|
-
end
|
439
|
-
|
440
|
-
# e.g. fetch the livingroom temperature reading
|
441
|
-
#
|
442
|
-
get /fetch the ([^ ]+) +([^ ]+) +(?:reading)$/ do |location, device|
|
443
|
-
{type: :get_thing, action: 'reading', location: location, thing: device}
|
444
|
-
end
|
445
|
-
|
446
|
-
# e.g. fetch the temperature reading
|
447
|
-
#
|
448
|
-
get /fetch the ([^ ]+) +(?:reading)$/ do |device|
|
449
|
-
location = find_path(device)
|
450
|
-
{type: :get_thing, action: 'reading', location: location, thing: device}
|
451
|
-
end
|
279
|
+
m: screen on off
|
280
|
+
t: screen on
|
281
|
+
a: webhook
|
452
282
|
|
453
|
-
|
454
|
-
|
455
|
-
|
456
|
-
|
457
|
-
def find_path(s)
|
458
|
-
puts 'find_path s: ' + s.inspect if @debug
|
459
|
-
found = query('//'+ s)
|
460
|
-
return unless found
|
461
|
-
a = found.backtrack.to_xpath.split('/')
|
462
|
-
a[1..-2].join(' ')
|
463
|
-
end
|
464
|
-
|
465
|
-
alias find_request run_route
|
283
|
+
m: Power Button Toggle3
|
284
|
+
t: Power Button Toggle (3)
|
285
|
+
a: webhook
|
466
286
|
|
467
|
-
|
287
|
+
m: Power Button Toggle4
|
288
|
+
t: Power Button Toggle (4)
|
289
|
+
a: webhook
|
468
290
|
|
469
|
-
|
470
|
-
|
471
|
-
|
472
|
-
attr_accessor :title, :macros, :store
|
291
|
+
m: Power Button Toggle5
|
292
|
+
t: Power Button Toggle (5)
|
293
|
+
a: webhook
|
473
294
|
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
if model then
|
483
|
-
@model = Model.new(model)
|
484
|
-
end
|
485
|
-
|
486
|
-
@store = {}
|
487
|
-
@query = Query.new(self)
|
295
|
+
m: Connected to network
|
296
|
+
t:
|
297
|
+
Connected to network
|
298
|
+
Any Network
|
299
|
+
a: wait 2 seconds
|
300
|
+
a:
|
301
|
+
webhook
|
302
|
+
ssid: [ssid]
|
488
303
|
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
if @control.respond_to? name.to_sym then
|
498
|
-
@control.method(name.to_sym).call(options)
|
499
|
-
else
|
500
|
-
@control.http_exec name.to_sym, options
|
501
|
-
end
|
502
|
-
end
|
304
|
+
m: In Vehicle
|
305
|
+
t:
|
306
|
+
Activity - In Vehicle
|
307
|
+
Confidence >= 50%
|
308
|
+
a:
|
309
|
+
webhook
|
310
|
+
identifier: activity
|
311
|
+
index: 0
|
503
312
|
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
313
|
+
m: On Bicycle
|
314
|
+
t:
|
315
|
+
Activity - On Bicycle
|
316
|
+
Confidence >= 50%
|
317
|
+
a:
|
318
|
+
webhook
|
319
|
+
identifier: activity
|
320
|
+
index: 1
|
511
321
|
|
512
|
-
|
513
|
-
|
514
|
-
|
515
|
-
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
global = [:airplane_mode_on, :bluetooth_on, :cell_on, :device_name, \
|
521
|
-
:usb_mass_storage_enabled, :wifi_on]
|
522
|
-
|
523
|
-
secure = %i(bluetooth_name flashlight_enabled)
|
524
|
-
|
525
|
-
|
526
|
-
# send http request via macrodroid.com API
|
527
|
-
|
528
|
-
if id.downcase.to_sym == :location then
|
529
|
-
@control.http_exec id
|
530
|
-
elsif sys.include? id
|
531
|
-
@control.http_exec :'query-setting-system', {qvar: id}
|
532
|
-
elsif global.include? id
|
533
|
-
@control.http_exec :'query-setting-global', {qvar: id}
|
534
|
-
elsif secure.include? id
|
535
|
-
@control.http_exec :'query-setting-secure', {qvar: id}
|
536
|
-
else
|
537
|
-
@control.http_exec :query, {qvar: id}
|
538
|
-
end
|
539
|
-
|
540
|
-
# wait for the local variable to be updated
|
541
|
-
# timeout after 5 seoncds
|
542
|
-
t = Time.now
|
543
|
-
|
544
|
-
begin
|
545
|
-
sleep 1
|
546
|
-
end until @store[id] or Time.now > t + 5
|
547
|
-
|
548
|
-
return {warning: 'HTTP response timeout'} if Time.now > t+5
|
549
|
-
|
550
|
-
return @store[id]
|
322
|
+
m: Running
|
323
|
+
t:
|
324
|
+
Activity - Running
|
325
|
+
Confidence >= 50%
|
326
|
+
a:
|
327
|
+
webhook
|
328
|
+
identifier: activity
|
329
|
+
index: 2
|
551
330
|
|
552
|
-
|
553
|
-
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
559
|
-
|
560
|
-
def trigger(name, detail={time: Time.now})
|
561
|
-
|
562
|
-
macros = @macros.select do |macro|
|
563
|
-
|
564
|
-
puts 'macro: ' + macro.inspect if @debug
|
331
|
+
m: Walking
|
332
|
+
t:
|
333
|
+
Activity - Walking
|
334
|
+
Confidence >= 50%
|
335
|
+
a:
|
336
|
+
webhook
|
337
|
+
identifier: activity
|
338
|
+
index: 3
|
565
339
|
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
572
|
-
|
573
|
-
|
574
|
-
@syslog << [Time.now, :trigger, name]
|
575
|
-
@syslog << [Time.now, :macro, macro.title]
|
576
|
-
end
|
577
|
-
|
578
|
-
valid_trigger
|
579
|
-
|
580
|
-
end
|
581
|
-
|
582
|
-
puts 'macros: ' + macros.inspect if @debug
|
583
|
-
|
584
|
-
macros.flat_map(&:run)
|
585
|
-
end
|
340
|
+
m: Still
|
341
|
+
t:
|
342
|
+
Activity - Still
|
343
|
+
Confidence >= 83%
|
344
|
+
a:
|
345
|
+
webhook
|
346
|
+
identifier: activity
|
347
|
+
index: 4
|
586
348
|
|
587
|
-
|
349
|
+
m: Swipe top left across
|
350
|
+
t:
|
351
|
+
Swipe Screen
|
352
|
+
Top Left - Across
|
353
|
+
a:
|
354
|
+
webhook
|
355
|
+
identifier: swipe
|
356
|
+
start: 0
|
357
|
+
motion: 0
|
358
|
+
|
359
|
+
m: Swipe top left diagonal
|
360
|
+
t:
|
361
|
+
Swipe Screen
|
362
|
+
Top Left - Diagonal
|
363
|
+
a:
|
364
|
+
webhook
|
365
|
+
identifier: swipe
|
366
|
+
start: 0
|
367
|
+
motion: 1
|
368
|
+
|
369
|
+
m: Swipe top left down
|
370
|
+
t:
|
371
|
+
Swipe Screen
|
372
|
+
Top Left - Down
|
373
|
+
a:
|
374
|
+
webhook
|
375
|
+
identifier: swipe
|
376
|
+
start: 0
|
377
|
+
motion: 2
|
378
|
+
|
379
|
+
m: Swipe top right across
|
380
|
+
t:
|
381
|
+
Swipe Screen
|
382
|
+
Top Right - Across
|
383
|
+
a:
|
384
|
+
webhook
|
385
|
+
identifier: swipe
|
386
|
+
start: 1
|
387
|
+
motion: 0
|
588
388
|
|
589
|
-
def update(id, val)
|
590
|
-
key = id == :location ? id : val.keys.first.to_sym
|
591
|
-
@store[key] = val
|
592
|
-
end
|
593
|
-
|
594
389
|
|
595
|
-
|
390
|
+
m: Swipe top right diagonal
|
391
|
+
t:
|
392
|
+
Swipe Screen
|
393
|
+
Top Right - Diagonal
|
394
|
+
a:
|
395
|
+
webhook
|
396
|
+
identifier: swipe
|
397
|
+
start: 1
|
398
|
+
motion: 1
|
399
|
+
|
400
|
+
m: Swipe top right down
|
401
|
+
t:
|
402
|
+
Swipe Screen
|
403
|
+
Top Right - Down
|
404
|
+
a:
|
405
|
+
webhook
|
406
|
+
identifier: swipe
|
407
|
+
start: 1
|
408
|
+
motion: 2
|
596
409
|
|
597
|
-
|
598
|
-
|
599
|
-
|
600
|
-
|
601
|
-
|
602
|
-
|
603
|
-
class Bluetooth
|
604
|
-
def enable()
|
605
|
-
end
|
606
|
-
end
|
607
|
-
|
608
|
-
class Toast < Service
|
609
|
-
|
610
|
-
def invoke()
|
611
|
-
@callback.call :toast
|
612
|
-
end
|
613
|
-
|
614
|
-
end
|
615
|
-
|
616
|
-
class Torch < Service
|
617
|
-
|
618
|
-
def toggle()
|
619
|
-
@callback.http_exec :torch
|
620
|
-
end
|
621
|
-
|
622
|
-
end
|
623
|
-
|
624
|
-
class ControlHelper
|
625
|
-
|
626
|
-
def initialize(callback)
|
627
|
-
@callback
|
628
|
-
end
|
629
|
-
end
|
410
|
+
m: flip from up to down
|
411
|
+
t: Flip Device Face Up -> Face Down
|
412
|
+
a:
|
413
|
+
webhook
|
414
|
+
identifier: flip_device
|
415
|
+
facedown: true
|
630
416
|
|
631
|
-
|
632
|
-
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
|
637
|
-
|
638
|
-
|
639
|
-
def bluetooth()
|
640
|
-
@bluetooth
|
641
|
-
end
|
642
|
-
|
643
|
-
def camera_flash_light(options={})
|
644
|
-
http_exec 'camera-flash-light', options
|
645
|
-
end
|
417
|
+
m: flip from down to up
|
418
|
+
t: Flip Device Face Down -> Face Up
|
419
|
+
a:
|
420
|
+
webhook
|
421
|
+
identifier: flip_device
|
422
|
+
facedown: false
|
423
|
+
EOF
|
424
|
+
s="
|
646
425
|
|
647
|
-
def hotspot(state=nil)
|
648
|
-
|
649
|
-
if state then
|
650
|
-
http_exec 'hotspot', {enable: state == :enable}
|
651
|
-
else
|
652
426
|
|
653
|
-
def self.enable()
|
654
|
-
http_exec 'hotspot', {enable: true}
|
655
|
-
end
|
656
|
-
|
657
|
-
def self.on()
|
658
|
-
self.enable
|
659
|
-
end
|
660
|
-
|
661
|
-
def self.disable()
|
662
|
-
http_exec 'hotspot', {enable: false}
|
663
|
-
end
|
664
|
-
|
665
|
-
def self.off()
|
666
|
-
self.disable
|
667
|
-
end
|
668
|
-
|
669
|
-
self
|
670
|
-
|
671
|
-
end
|
672
|
-
end
|
673
|
-
|
674
|
-
def http_exec(command, options={})
|
675
|
-
|
676
|
-
url = "https://trigger.macrodroid.com/%s/%s" % [@deviceid, command]
|
677
|
-
|
678
|
-
if options and options.any? then
|
679
|
-
h = options
|
680
|
-
url += '?' + \
|
681
|
-
URI.escape(h.map {|key,value| "%s=%s" % [key, value]}.join('&'))
|
682
|
-
end
|
683
|
-
|
684
|
-
s = open(url).read
|
685
|
-
|
686
|
-
end
|
687
|
-
|
688
|
-
def location(options={})
|
689
|
-
http_exec 'location'
|
690
|
-
end
|
691
|
-
|
692
|
-
def say_current_time(options={})
|
693
|
-
http_exec 'say-current-time'
|
694
|
-
end
|
695
|
-
|
696
|
-
alias say_time say_current_time
|
697
|
-
|
698
|
-
def screen(state=nil)
|
699
|
-
|
700
|
-
if state then
|
701
|
-
http_exec 'screen', {on: state == :on}
|
702
|
-
else
|
703
|
-
|
704
|
-
def self.on()
|
705
|
-
http_exec 'screen', {on: true}
|
706
|
-
end
|
707
|
-
|
708
|
-
def self.off()
|
709
|
-
http_exec 'screen', {on: false}
|
710
|
-
end
|
711
|
-
|
712
|
-
self
|
713
|
-
|
714
|
-
end
|
715
|
-
end
|
716
|
-
|
717
|
-
def share_location(options={})
|
718
|
-
http_exec 'share-location'
|
719
|
-
end
|
720
|
-
|
721
|
-
def speak_text(obj)
|
722
|
-
|
723
|
-
options = case obj
|
724
|
-
when String
|
725
|
-
{text: obj}
|
726
|
-
when Hash
|
727
|
-
obj
|
728
|
-
end
|
729
|
-
|
730
|
-
http_exec 'speak-text', options
|
731
|
-
end
|
732
|
-
|
733
|
-
alias say speak_text
|
734
|
-
|
735
|
-
def toast(options={})
|
736
|
-
http_exec :toast, options
|
737
|
-
end
|
738
|
-
|
739
|
-
def torch(options={})
|
740
|
-
http_exec :torch
|
741
|
-
end
|
742
|
-
|
743
|
-
def vibrate(options={})
|
744
|
-
http_exec :vibrate
|
745
|
-
end
|
746
427
|
|
747
428
|
|
748
|
-
|
749
|
-
|
750
|
-
MacroDroid.new(RD_MACROS, deviceid: @deviceid,
|
751
|
-
remote_url: @remote_url, debug: @debug).export s
|
752
|
-
|
753
|
-
end
|
754
|
-
|
755
|
-
alias export write
|
756
|
-
|
757
|
-
def method_missing2(method_name, *args)
|
758
|
-
http_exec(method_name, args.first)
|
759
|
-
end
|
760
|
-
|
761
|
-
end
|
762
|
-
|
763
|
-
class Query
|
764
|
-
|
765
|
-
def initialize(callback)
|
766
|
-
@callback = callback
|
767
|
-
end
|
768
|
-
|
769
|
-
def airplane_mode_enabled?()
|
770
|
-
q(:airplane_mode_on).to_i > 0
|
771
|
-
end
|
772
|
-
|
773
|
-
def battery()
|
774
|
-
q(:battery).to_i
|
775
|
-
end
|
776
|
-
|
777
|
-
def current_brightness()
|
778
|
-
q(:current_brightness).to_i
|
779
|
-
end
|
429
|
+
|
780
430
|
|
781
|
-
|
782
|
-
|
783
|
-
def cell_id()
|
784
|
-
q(:cell_id)
|
785
|
-
end
|
786
|
-
|
787
|
-
alias cell_tower cell_id
|
788
|
-
|
789
|
-
def ip()
|
790
|
-
q(:ip)
|
791
|
-
end
|
792
|
-
|
793
|
-
def location()
|
794
|
-
@callback.query(:location)[:coords]
|
795
|
-
end
|
431
|
+
"
|
796
432
|
|
797
|
-
|
798
|
-
private
|
799
|
-
|
800
|
-
def q(id)
|
801
|
-
@callback.query(id)[id]
|
802
|
-
end
|
803
|
-
|
804
|
-
end
|
433
|
+
module RemoteDroid
|
805
434
|
|
806
435
|
class Server
|
807
436
|
|
@@ -818,92 +447,7 @@ module RemoteDroid
|
|
818
447
|
end
|
819
448
|
|
820
449
|
end
|
821
|
-
|
822
|
-
class Client
|
823
|
-
|
824
|
-
def initialize(host='127.0.0.1')
|
825
|
-
@drb = OneDrb::Client.new host: host, port: '5777'
|
826
|
-
end
|
827
|
-
|
828
|
-
def control
|
829
|
-
@drb.control
|
830
|
-
end
|
831
|
-
|
832
|
-
def export(s)
|
833
|
-
@drb.export(s)
|
834
|
-
end
|
835
|
-
|
836
|
-
def invoke(s, *args)
|
837
|
-
@drb.invoke(s, *args)
|
838
|
-
end
|
839
|
-
|
840
|
-
def query(id=nil)
|
841
|
-
|
842
|
-
return @drb.query unless id
|
843
|
-
t = Time.now
|
844
|
-
h = @drb.query(id)
|
845
|
-
h.merge({latency: (Time.now - t).round(3)})
|
846
|
-
|
847
|
-
end
|
848
|
-
|
849
|
-
def update(key, val)
|
850
|
-
@drb.update key.to_sym, val
|
851
|
-
end
|
852
|
-
|
853
|
-
def store()
|
854
|
-
@drb.store
|
855
|
-
end
|
856
|
-
|
857
|
-
# -- helpful methods -----------------
|
858
|
-
|
859
|
-
def battery()
|
860
|
-
query.battery
|
861
|
-
end
|
862
|
-
|
863
|
-
def cell_tower()
|
864
|
-
query.cell_tower
|
865
|
-
end
|
866
|
-
|
867
|
-
def hotspot(state=nil)
|
868
|
-
control.hotspot state
|
869
|
-
end
|
870
|
-
|
871
|
-
def location()
|
872
|
-
query.location
|
873
|
-
end
|
874
|
-
|
875
|
-
def say(text)
|
876
|
-
control.speak_text text
|
877
|
-
end
|
878
|
-
|
879
|
-
def say_time()
|
880
|
-
control.say_time
|
881
|
-
end
|
882
|
-
|
883
|
-
alias saytime say_time
|
884
|
-
|
885
|
-
def screen(state=nil)
|
886
|
-
control.screen state
|
887
|
-
end
|
888
|
-
|
889
|
-
def screen_on()
|
890
|
-
screen :on
|
891
|
-
end
|
892
450
|
|
893
|
-
def screen_off()
|
894
|
-
screen :off
|
895
|
-
end
|
896
|
-
|
897
|
-
def torch()
|
898
|
-
control.torch
|
899
|
-
end
|
900
|
-
|
901
|
-
def vibrate
|
902
|
-
control.vibrate
|
903
|
-
end
|
904
|
-
|
905
|
-
end
|
906
|
-
|
907
451
|
class TriggerSubscriber < SPSSub
|
908
452
|
|
909
453
|
def initialize(host: 'sps.home', drb_host: '127.0.0.1')
|
@@ -938,8 +482,20 @@ module RemoteDroid
|
|
938
482
|
|
939
483
|
context, json = msg.split(/:\s+/,2)
|
940
484
|
category, action = context.split('/',2)
|
941
|
-
|
485
|
+
|
486
|
+
if action == 'force_macro_run' then
|
487
|
+
|
488
|
+
self.notice 'macrodroid2: fmr'
|
489
|
+
a = @remote.run_macro(JSON.parse(json, symbolize_names: true))
|
490
|
+
|
491
|
+
a.each do |msg|
|
492
|
+
self.notice 'macrodroid/action: ' + msg
|
493
|
+
end
|
494
|
+
|
495
|
+
else
|
496
|
+
@remote.control.method(action.to_sym)\
|
942
497
|
.call(JSON.parse(json, symbolize_names: true))
|
498
|
+
end
|
943
499
|
|
944
500
|
end
|
945
501
|
|
@@ -959,6 +515,7 @@ module RemoteDroid
|
|
959
515
|
super(topic: topic) do |msg|
|
960
516
|
|
961
517
|
json, id = msg.split(/:\s+/,2).reverse
|
518
|
+
|
962
519
|
h = JSON.parse(json, symbolize_names: true)
|
963
520
|
id ||= h.keys.first
|
964
521
|
@remote.update id.to_sym, h
|
@@ -969,3 +526,12 @@ module RemoteDroid
|
|
969
526
|
|
970
527
|
end
|
971
528
|
end
|
529
|
+
|
530
|
+
# PASTE_END
|
531
|
+
|
532
|
+
|
533
|
+
require 'remotedroid/model'
|
534
|
+
require 'remotedroid/query'
|
535
|
+
require 'remotedroid/control'
|
536
|
+
require 'remotedroid/controller'
|
537
|
+
require 'remotedroid/client'
|