remotedroid 0.3.0 → 0.4.4

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: 71e486b66042dfefbfff3717043ded61f7847043a4afc37f1bd7b215076e280b
4
- data.tar.gz: e7dee07206e7351a472fd9fb5c767979f7350f65630c7e1161dd7a14d1349347
3
+ metadata.gz: 4599f668ded4ccead69bcab55ac94e081027b1054b4053ee2cb2f142303a7b01
4
+ data.tar.gz: cdbcb98bab0dd3df0d8252892ce5c44c7ed26332803a89292357b04f2f26a9e4
5
5
  SHA512:
6
- metadata.gz: '08933909445d0ec11a57c9f3006ac9874db4a48d21602a56993505f6c5350acc566a4fb4171e9e2423bd41c2957f6ae5be8294c51f4551808d71f277b1aab2b1'
7
- data.tar.gz: 1b48179921c54abd6ad3d112c277133352a3496be7f092709f15463e5ced3418307d93b1aec0edc18167b16677541bea563c2116e8d0068a0becd2a365edc5dd
6
+ metadata.gz: 636856536a64d87445c01d3e2b320ccf0fbfed713a6ba4384a19947b182f33bee281a6ae1e191237ed5f74e0995c6460f21108cb4a578b6ea406ecab0921b0c9
7
+ data.tar.gz: a650ca4d116ccba5251cd1e9f489587d8ebd5f33c7e8c106a8e59c0817187511d26d2d01aac92d88b27ee0efb07b9cad9eb4a6d7da0abace184f174550a3762e
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -13,6 +13,10 @@ require 'ruby-macrodroid'
13
13
  #
14
14
  # # Triggers
15
15
  #
16
+ # ## Device Events
17
+ #
18
+ # * screen on
19
+ #
16
20
  # ## Sensors
17
21
  #
18
22
  # * proximity (near)
@@ -22,6 +26,14 @@ require 'ruby-macrodroid'
22
26
  #
23
27
  # # Actions
24
28
  #
29
+ # ## Camera/Photo
30
+ #
31
+ # * Take Picture
32
+ #
33
+ # ## Connectivity
34
+ #
35
+ # * Enable HotSpot
36
+ #
25
37
  # ## Date/Time
26
38
  #
27
39
  # * Say Current Time
@@ -30,17 +42,72 @@ require 'ruby-macrodroid'
30
42
  #
31
43
  # * Speak text
32
44
  # * Torch toggle
45
+ # * vibrate
33
46
  #
34
47
  # ## Location
35
48
  #
36
49
  # * Share Location
37
50
  #
51
+ # ## Media
52
+ #
53
+ # * Play sound (Doda)
54
+ #
38
55
  # ## Notification
39
56
  #
40
57
  # * Popup Message
41
58
  #
59
+ # ## Screen
60
+ #
61
+ # * Keep Device Awake
62
+ # * Screen On
63
+ #
64
+
65
+ # Variables which can be queried
66
+ #
67
+ # Description Variable
68
+ # ------------------- ----------------
69
+ # Foreground app name :fg_app_name
70
+ # Foreground app package :fg_app_package
71
+ # Current Brightness :current_brightness
72
+ # Screen timeout (seconds) :screen_timeout
73
+ # Current battery % :battery
74
+ # Battery temp °C :battery_temp
75
+ # Power (On/Off) :power
76
+ # Clipboard text :clipboard
77
+ # Current IP address :ip
78
+ # Wifi SSID :ssid
79
+ # Wifi signal strength :wifi_strength
80
+ # System time :system_time
81
+ # IMEI :imei
82
+ # Cell Id :cell_id
83
+ # Last known location (lat,lon) :last_loc_latlong
84
+ # Last known location (altitude) :last_loc_alt
85
+ # Last known location (link) :last_loc_link
86
+ # Last known location (time) :last_loc_age_timestamp
87
+ # Last known location (kmh) :last_loc_speed_kmh
88
+ # Last known location (mph) :last_loc_speed_mph
89
+ # Current Volume (Alarm) :vol_alarm
90
+ # Current Volume (Media / Music) :vol_music
91
+ # Current Volume (Ringer) :vol_ring
92
+ # Current Volume (Notification) :vol_notif
93
+ # Current Volume (System Sounds) :vol_system
94
+ # Current Volume (Voice Call) :vol_call
95
+ # Current Volume (Bluetooth Voice) :vol_bt_voice
96
+ # Device name :device_name
97
+ # Device uptime :uptime_secs
98
+ # Device manufacturer :device_manufacturer
99
+ # Device model :device_model
100
+ # Android version :android_version
101
+ # Android version (SDK Level) :android_version_sdk
102
+ # Storage total (external) :storage_external_total
103
+ # Storage free (external) :storage_external_free
104
+ # Storage total (internal) :storage_internal_total
105
+ # Storage free (internal) :storage_internal_free
42
106
 
43
107
 
108
+ # The macros below are exported to JSON format as a file which is imported into
109
+ # the Android device running MacroDroid.
110
+
44
111
  RD_MACROS =<<EOF
45
112
  m: Camera flash light
46
113
  t: webhook
@@ -66,6 +133,50 @@ v: text
66
133
  t: webhook
67
134
  a: speak text ([lv=text])
68
135
 
136
+ m: vibrate
137
+ t: webhook
138
+ a: vibrate
139
+
140
+ m: play doda
141
+ t: webhook
142
+ a: play: Doda
143
+
144
+ m: Screen
145
+ v: on: false
146
+ t: WebHook
147
+ a:
148
+ If on = True
149
+ Screen On
150
+ Else
151
+ Screen Off
152
+ End If
153
+
154
+ m: Hotspot
155
+ v: enable: false
156
+ t: WebHook
157
+ a:
158
+ If enable = True
159
+ Enable Hotspot
160
+ Else
161
+ Disable Hotspot
162
+ End If
163
+
164
+ m: Take Picture
165
+ t: webhook
166
+ a:
167
+ Take Picture
168
+ Rear Facing
169
+ a: wait 2 seconds
170
+ a: webhook
171
+
172
+ m: stay awake
173
+ t: webhook
174
+ a: stay awake
175
+
176
+ m: stay awake off
177
+ t: webhook
178
+ a: stay awake off
179
+
69
180
  m: Share location
70
181
  t:
71
182
  WebHook
@@ -80,6 +191,47 @@ a:
80
191
  coords: [lv=coords]
81
192
  type: query
82
193
 
194
+ m: query
195
+ t: WebHook
196
+ v: qvar
197
+ a:
198
+ Set Variable
199
+ var: [[lv=qvar]]
200
+ a:
201
+ HTTP GET
202
+ [lv=qvar]: [lv=var]
203
+
204
+ m: query setting system
205
+ t: WebHook
206
+ v: qvar
207
+ a:
208
+ Set Variable
209
+ var: [setting_system=[lv=qvar]]
210
+ a:
211
+ HTTP GET
212
+ [lv=qvar]: [lv=var]
213
+
214
+ m: query setting global
215
+ t: WebHook
216
+ v: qvar
217
+ a:
218
+ Set Variable
219
+ var: [setting_global=[lv=qvar]]
220
+ a:
221
+ HTTP GET
222
+ [lv=qvar]: [lv=var]
223
+
224
+ m: query setting secure
225
+ t: WebHook
226
+ v: qvar
227
+ a:
228
+ Set Variable
229
+ var: [setting_secure=[lv=qvar]]
230
+ a:
231
+ HTTP GET
232
+ [lv=qvar]: [lv=var]
233
+
234
+
83
235
  m: shake device
84
236
  t: shake device
85
237
  a: webhook
@@ -90,9 +242,30 @@ a:
90
242
  webhook
91
243
  identifier: proximity
92
244
  option: 0
245
+
246
+ m: Power connected
247
+ t: Power Connected: Any
248
+ a: webhook
249
+
250
+ m: screen on off
251
+ t: screen on
252
+ a: webhook
93
253
 
94
254
  EOF
95
255
 
256
+ =begin
257
+ m: Screen
258
+ v: on: true
259
+ t: WebHook
260
+ a:
261
+ If on = true
262
+ Screen On
263
+ Else
264
+ Screen Off
265
+ End If
266
+
267
+ =end
268
+
96
269
  module RemoteDroid
97
270
 
98
271
  class Model
@@ -338,6 +511,7 @@ module RemoteDroid
338
511
  end
339
512
 
340
513
  @store = {}
514
+ @query = Query.new(self)
341
515
 
342
516
  end
343
517
 
@@ -346,7 +520,12 @@ module RemoteDroid
346
520
  end
347
521
 
348
522
  def invoke(name, options={})
349
- @control.method(name.to_sym).call(options)
523
+
524
+ if @control.respond_to? name.to_sym then
525
+ @control.method(name.to_sym).call(options)
526
+ else
527
+ @control.http_exec name.to_sym, options
528
+ end
350
529
  end
351
530
 
352
531
  # Object Property (op)
@@ -357,12 +536,35 @@ module RemoteDroid
357
536
  @model.op
358
537
  end
359
538
 
360
- def query(id)
539
+ def query(id=nil)
540
+
541
+ return @query unless id
361
542
 
362
543
  @store[id] = nil
544
+
545
+ sys = %i(accelerometer_rotation)
546
+
547
+ global = [:airplane_mode_on, :bluetooth_on, :cell_on, :device_name, \
548
+ :usb_mass_storage_enabled, :wifi_on]
549
+
550
+ secure = %i(bluetooth_name flashlight_enabled)
551
+
363
552
 
364
553
  # send http request via macrodroid.com API
365
- @control.http_exec id
554
+
555
+ if id.downcase.to_sym == :location then
556
+ @control.http_exec id
557
+ elsif sys.include? id
558
+ @control.http_exec :'query-setting-system', {qvar: id}
559
+ elsif global.include? id
560
+ @control.http_exec :'query-setting-global', {qvar: id}
561
+ elsif secure.include? id
562
+ @control.http_exec :'query-setting-secure', {qvar: id}
563
+ elsif id.downcase.to_sym == :'take-picture'
564
+ @control.http_exec id
565
+ else
566
+ @control.http_exec :query, {qvar: id}
567
+ end
366
568
 
367
569
  # wait for the local variable to be updated
368
570
  # timeout after 5 seoncds
@@ -370,9 +572,10 @@ module RemoteDroid
370
572
 
371
573
  begin
372
574
  sleep 1
373
- end until @store[id] or Time.now > t + 5
575
+ end until @store[id] or Time.now > t + 10
576
+
577
+ return {warning: 'HTTP response timeout'} if Time.now > t+5
374
578
 
375
-
376
579
  return @store[id]
377
580
 
378
581
 
@@ -412,11 +615,17 @@ module RemoteDroid
412
615
 
413
616
  alias trigger_fired trigger
414
617
 
415
- def update(key, val)
416
- @store[key.to_sym] = val
618
+ def update(id, val)
619
+
620
+ key = if %i(location take-picture).include? id
621
+ id
622
+ else
623
+ val.keys.first.to_sym
624
+ end
625
+
626
+ @store[key] = val
417
627
  end
418
628
 
419
-
420
629
  end
421
630
 
422
631
  class Service
@@ -445,6 +654,13 @@ module RemoteDroid
445
654
  end
446
655
 
447
656
  end
657
+
658
+ class ControlHelper
659
+
660
+ def initialize(callback)
661
+ @callback
662
+ end
663
+ end
448
664
 
449
665
  class Control
450
666
 
@@ -452,7 +668,7 @@ module RemoteDroid
452
668
 
453
669
  @deviceid, @remote_url, @debug = deviceid, remote_url, debug
454
670
  @torch = Torch.new(self)
455
- end
671
+ end
456
672
 
457
673
  def bluetooth()
458
674
  @bluetooth
@@ -461,6 +677,33 @@ module RemoteDroid
461
677
  def camera_flash_light(options={})
462
678
  http_exec 'camera-flash-light', options
463
679
  end
680
+
681
+ def hotspot(state=nil)
682
+
683
+ if state then
684
+ http_exec 'hotspot', {enable: state == :enable}
685
+ else
686
+
687
+ def self.enable()
688
+ http_exec 'hotspot', {enable: true}
689
+ end
690
+
691
+ def self.on()
692
+ self.enable
693
+ end
694
+
695
+ def self.disable()
696
+ http_exec 'hotspot', {enable: false}
697
+ end
698
+
699
+ def self.off()
700
+ self.disable
701
+ end
702
+
703
+ self
704
+
705
+ end
706
+ end
464
707
 
465
708
  def http_exec(command, options={})
466
709
 
@@ -486,14 +729,58 @@ module RemoteDroid
486
729
 
487
730
  alias say_time say_current_time
488
731
 
732
+ def screen(state=nil)
733
+
734
+ if state then
735
+ http_exec 'screen', {on: state == :on}
736
+ else
737
+
738
+ def self.on()
739
+ http_exec 'screen', {on: true}
740
+ end
741
+
742
+ def self.off()
743
+ http_exec 'screen', {on: false}
744
+ end
745
+
746
+ self
747
+
748
+ end
749
+ end
750
+
489
751
  def share_location(options={})
490
752
  http_exec 'share-location'
491
753
  end
492
754
 
493
- def speak_text(options={})
755
+ def speak_text(obj)
756
+
757
+ options = case obj
758
+ when String
759
+ {text: obj}
760
+ when Hash
761
+ obj
762
+ end
763
+
494
764
  http_exec 'speak-text', options
495
765
  end
496
766
 
767
+ alias say speak_text
768
+
769
+ def stay_awake(options={})
770
+ http_exec 'stay-awake', options
771
+ end
772
+
773
+ def stay_awake_off(options={})
774
+ http_exec 'stay-awake-off', options
775
+ end
776
+
777
+ def take_picture(options={})
778
+ http_exec 'take-picture', options
779
+ end
780
+
781
+ alias take_photo take_picture
782
+
783
+
497
784
  def toast(options={})
498
785
  http_exec :toast, options
499
786
  end
@@ -501,6 +788,10 @@ module RemoteDroid
501
788
  def torch(options={})
502
789
  http_exec :torch
503
790
  end
791
+
792
+ def vibrate(options={})
793
+ http_exec :vibrate
794
+ end
504
795
 
505
796
 
506
797
  def write(s)
@@ -512,12 +803,58 @@ module RemoteDroid
512
803
 
513
804
  alias export write
514
805
 
515
- def method_missing(method_name, *args)
806
+ def method_missing2(method_name, *args)
516
807
  http_exec(method_name, args.first)
517
808
  end
518
809
 
519
810
  end
520
811
 
812
+ class Query
813
+
814
+ def initialize(callback)
815
+ @callback = callback
816
+ end
817
+
818
+ def airplane_mode_enabled?()
819
+ q(:airplane_mode_on).to_i > 0
820
+ end
821
+
822
+ def battery()
823
+ q(:battery).to_i
824
+ end
825
+
826
+ def current_brightness()
827
+ q(:current_brightness).to_i
828
+ end
829
+
830
+ alias brightness current_brightness
831
+
832
+ def cell_id()
833
+ q(:cell_id)
834
+ end
835
+
836
+ alias cell_tower cell_id
837
+
838
+ def ip()
839
+ q(:ip)
840
+ end
841
+
842
+ def location()
843
+ @callback.query(:location)[:coords]
844
+ end
845
+
846
+ def take_picture()
847
+ @callback.query(:'take-picture')
848
+ end
849
+
850
+ private
851
+
852
+ def q(id)
853
+ @callback.query(id)[id]
854
+ end
855
+
856
+ end
857
+
521
858
  class Server
522
859
 
523
860
  def initialize(s, drb_host: '127.0.0.1', deviceid: nil)
@@ -540,6 +877,10 @@ module RemoteDroid
540
877
  @drb = OneDrb::Client.new host: host, port: '5777'
541
878
  end
542
879
 
880
+ def control
881
+ @drb.control
882
+ end
883
+
543
884
  def export(s)
544
885
  @drb.export(s)
545
886
  end
@@ -548,8 +889,9 @@ module RemoteDroid
548
889
  @drb.invoke(s, *args)
549
890
  end
550
891
 
551
- def query(id)
892
+ def query(id=nil)
552
893
 
894
+ return @drb.query unless id
553
895
  t = Time.now
554
896
  h = @drb.query(id)
555
897
  h.merge({latency: (Time.now - t).round(3)})
@@ -563,6 +905,89 @@ module RemoteDroid
563
905
  def store()
564
906
  @drb.store
565
907
  end
908
+
909
+ # -- helpful methods -----------------
910
+
911
+ def battery()
912
+ query.battery
913
+ end
914
+
915
+ def cell_tower()
916
+ query.cell_tower
917
+ end
918
+
919
+ def hotspot(state=nil)
920
+ control.hotspot state
921
+ end
922
+
923
+ def location()
924
+ query.location
925
+ end
926
+
927
+ def photo()
928
+ take_picture
929
+ end
930
+
931
+ def say(text)
932
+ control.speak_text text
933
+ end
934
+
935
+ def say_time()
936
+ control.say_time
937
+ end
938
+
939
+ alias saytime say_time
940
+
941
+ def screen(state=nil)
942
+ control.screen state
943
+ end
944
+
945
+ def screen_on()
946
+ screen :on
947
+ end
948
+
949
+ def screen_off()
950
+ screen :off
951
+ end
952
+
953
+ def stay_awake()
954
+ control.stay_awake
955
+ end
956
+
957
+ def stay_awake_off()
958
+ control.stay_awake_off
959
+ end
960
+
961
+ def take_picture(ftp_src: nil, fileout: '.')
962
+
963
+ #screen.on
964
+ r = query.take_picture
965
+
966
+ if ftp_src then
967
+
968
+ # the sleep statement will be replaced in the near future,
969
+ # but it's fine to demonstrate it works
970
+ #sleep 8
971
+
972
+ credentials, dir = ftp_src.match(/(ftp:\/\/[^\/]+)\/([^$]+)/).captures
973
+ ftp = MyMediaFTP.new(credentials)
974
+ ftp.cd dir
975
+ filename = ftp.ls.sort_by {|x| x[:ctime]}.last[:name]
976
+ ftp.cp filename, fileout
977
+
978
+ end
979
+
980
+ end
981
+
982
+ alias take_photo take_picture
983
+
984
+ def torch()
985
+ control.torch
986
+ end
987
+
988
+ def vibrate
989
+ control.vibrate
990
+ end
566
991
 
567
992
  end
568
993
 
@@ -620,8 +1045,11 @@ module RemoteDroid
620
1045
 
621
1046
  super(topic: topic) do |msg|
622
1047
 
623
- id, json = msg.split(/:\s+/,2)
624
- @remote.update id.to_sym, JSON.parse(json, symbolize_names: true)
1048
+ json, id = msg.split(/:\s+/,2).reverse
1049
+
1050
+ h = JSON.parse(json, symbolize_names: true)
1051
+ id ||= h.keys.first
1052
+ @remote.update id.to_sym, h
625
1053
 
626
1054
  end
627
1055
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: remotedroid
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Robertson
@@ -35,7 +35,7 @@ cert_chain:
35
35
  io3WPRDjULC924M5S8wbrus31v2AUjqFBPvmHr7caf/VHErWypV482xcDhWt1eif
36
36
  0G2k2ptozXcBS9odsqGUTb5N
37
37
  -----END CERTIFICATE-----
38
- date: 2020-10-06 00:00:00.000000000 Z
38
+ date: 2020-10-17 00:00:00.000000000 Z
39
39
  dependencies:
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: onedrb
@@ -106,7 +106,7 @@ dependencies:
106
106
  version: '0.9'
107
107
  - - ">="
108
108
  - !ruby/object:Gem::Version
109
- version: 0.9.2
109
+ version: 0.9.7
110
110
  type: :runtime
111
111
  prerelease: false
112
112
  version_requirements: !ruby/object:Gem::Requirement
@@ -116,7 +116,7 @@ dependencies:
116
116
  version: '0.9'
117
117
  - - ">="
118
118
  - !ruby/object:Gem::Version
119
- version: 0.9.2
119
+ version: 0.9.7
120
120
  description:
121
121
  email: james@jamesrobertson.eu
122
122
  executables: []
metadata.gz.sig CHANGED
Binary file