remotedroid 0.4.2 → 0.5.2
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,227 @@
|
|
1
|
+
module RemoteDroid
|
2
|
+
|
3
|
+
class Model
|
4
|
+
include AppRoutes
|
5
|
+
|
6
|
+
def initialize(obj=nil, root: 'device1', debug: false)
|
7
|
+
|
8
|
+
super()
|
9
|
+
@root, @debug = root, debug
|
10
|
+
@location = nil
|
11
|
+
|
12
|
+
if obj then
|
13
|
+
|
14
|
+
s = obj.strip
|
15
|
+
|
16
|
+
puts 's: ' + s.inspect if @debug
|
17
|
+
|
18
|
+
if s[0] == '<' or s.lines[1][0..1] == ' ' then
|
19
|
+
|
20
|
+
puts 'before easydom' if @debug
|
21
|
+
|
22
|
+
s2 = if s.lines[1][0..1] == ' ' then
|
23
|
+
|
24
|
+
lines = s.lines.map do |line|
|
25
|
+
line.sub(/(\w+) +is +(\w+)$/) {|x| "#{$1} {switch: #{$2}}" }
|
26
|
+
end
|
27
|
+
|
28
|
+
lines.join
|
29
|
+
|
30
|
+
else
|
31
|
+
s
|
32
|
+
end
|
33
|
+
|
34
|
+
@ed = EasyDom.new(s2)
|
35
|
+
else
|
36
|
+
build(s, root: root)
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
|
43
|
+
def build(raw_requests, root: @root)
|
44
|
+
|
45
|
+
@ed = EasyDom.new(debug: false, root: root)
|
46
|
+
raw_requests.lines.each {|line| request(line) }
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
def get_thing(h)
|
52
|
+
|
53
|
+
h[:thing].gsub!(/ /,'_')
|
54
|
+
|
55
|
+
if not h.has_key? :location then
|
56
|
+
location = false
|
57
|
+
h[:location] = find_path(h[:thing])
|
58
|
+
else
|
59
|
+
location = true
|
60
|
+
end
|
61
|
+
|
62
|
+
puts 'h: ' + h.inspect if @debug
|
63
|
+
|
64
|
+
a = []
|
65
|
+
a += h[:location].split(/ /)
|
66
|
+
a << h[:thing]
|
67
|
+
status = a.inject(@ed) {|r,x| r.send(x)}.send(h[:action])
|
68
|
+
|
69
|
+
if location then
|
70
|
+
"The %s %s is %s." % [h[:location], h[:thing], status]
|
71
|
+
else
|
72
|
+
"%s is %s." % [h[:thing].capitalize, status]
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
# Object Property (op)
|
78
|
+
# Helpful for accessing properites in dot notation
|
79
|
+
# e.g. op.livingroom.light.switch = 'off'
|
80
|
+
#
|
81
|
+
def op()
|
82
|
+
@ed
|
83
|
+
end
|
84
|
+
|
85
|
+
def query(s)
|
86
|
+
@ed.e.element(s)
|
87
|
+
end
|
88
|
+
|
89
|
+
# request accepts a string in plain english
|
90
|
+
# e.g. request 'switch the livingroom light on'
|
91
|
+
#
|
92
|
+
def request(s)
|
93
|
+
|
94
|
+
params = {request: s}
|
95
|
+
requests(params)
|
96
|
+
h = find_request(s)
|
97
|
+
|
98
|
+
method(h.first[-1]).call(h).gsub(/_/,' ')
|
99
|
+
|
100
|
+
end
|
101
|
+
|
102
|
+
def set_thing(h)
|
103
|
+
|
104
|
+
h[:thing].gsub!(/ /,'_')
|
105
|
+
h[:location] = find_path(h[:thing]) unless h.has_key? :location
|
106
|
+
|
107
|
+
a = []
|
108
|
+
a += h[:location].split(/ /)
|
109
|
+
a << h[:thing]
|
110
|
+
|
111
|
+
a.inject(@ed) {|r,x| r.send(x)}.send(h[:action], h[:value])
|
112
|
+
|
113
|
+
end
|
114
|
+
|
115
|
+
def to_sliml(level: 0)
|
116
|
+
|
117
|
+
s = @ed.to_sliml
|
118
|
+
|
119
|
+
return s if level.to_i > 0
|
120
|
+
|
121
|
+
lines = s.lines.map do |line|
|
122
|
+
|
123
|
+
line.sub(/\{[^\}]+\}/) do |x|
|
124
|
+
|
125
|
+
a = x.scan(/\w+: +[^ ]+/)
|
126
|
+
if a.length == 1 and x[/switch:/] then
|
127
|
+
|
128
|
+
val = x[/(?<=switch: ) *["']([^"']+)/,1]
|
129
|
+
'is ' + val
|
130
|
+
else
|
131
|
+
x
|
132
|
+
end
|
133
|
+
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
lines.join
|
138
|
+
|
139
|
+
end
|
140
|
+
|
141
|
+
def to_xml(options=nil)
|
142
|
+
@ed.xml(pretty: true).gsub(' style=\'\'','')
|
143
|
+
end
|
144
|
+
|
145
|
+
alias xml to_xml
|
146
|
+
|
147
|
+
# to_xml() is the preferred method
|
148
|
+
|
149
|
+
protected
|
150
|
+
|
151
|
+
def requests(params)
|
152
|
+
|
153
|
+
# e.g. switch the livingroom gas_fire off
|
154
|
+
#
|
155
|
+
get /(?:switch|turn) the ([^ ]+) +([^ ]+) +(on|off)$/ do |location, device, onoff|
|
156
|
+
{type: :set_thing, action: 'switch=', location: location, thing: device, value: onoff}
|
157
|
+
end
|
158
|
+
|
159
|
+
# e.g. switch the gas _fire off
|
160
|
+
#
|
161
|
+
get /(?:switch|turn) the ([^ ]+) +(on|off)$/ do |device, onoff|
|
162
|
+
{type: :set_thing, action: 'switch=', thing: device, value: onoff}
|
163
|
+
end
|
164
|
+
|
165
|
+
# e.g. is the livingroom gas_fire on?
|
166
|
+
#
|
167
|
+
get /is the ([^ ]+) +([^ ]+) +(?:on|off)\??$/ do |location, device|
|
168
|
+
{type: :get_thing, action: 'switch', location: location, thing: device}
|
169
|
+
end
|
170
|
+
|
171
|
+
# e.g. enable airplane mode
|
172
|
+
#
|
173
|
+
get /((?:dis|en)able) ([^$]+)$/ do |state, service|
|
174
|
+
{type: :set_thing, action: 'switch=', thing: service, value: state + 'd'}
|
175
|
+
end
|
176
|
+
|
177
|
+
# e.g. switch airplane mode off
|
178
|
+
#
|
179
|
+
get /switch (.*) (on|off)/ do |service, rawstate|
|
180
|
+
|
181
|
+
state = rawstate == 'on' ? 'enabled' : 'disabled'
|
182
|
+
{type: :set_thing, action: 'switch=', thing: service, value: state}
|
183
|
+
|
184
|
+
end
|
185
|
+
|
186
|
+
# e.g. is airplane mode enabed?
|
187
|
+
#
|
188
|
+
get /is (.*) +(?:(?:dis|en)abled)\??$/ do |service|
|
189
|
+
{type: :get_thing, action: 'switch', thing: service.gsub(/ /,'_')}
|
190
|
+
end
|
191
|
+
|
192
|
+
# e.g. is the gas_fire on?
|
193
|
+
#
|
194
|
+
get /is the ([^ ]+) +(?:on|off)\??$/ do |device|
|
195
|
+
location = find_path(device)
|
196
|
+
{type: :get_thing, action: 'switch', location: location, thing: device}
|
197
|
+
end
|
198
|
+
|
199
|
+
# e.g. fetch the livingroom temperature reading
|
200
|
+
#
|
201
|
+
get /fetch the ([^ ]+) +([^ ]+) +(?:reading)$/ do |location, device|
|
202
|
+
{type: :get_thing, action: 'reading', location: location, thing: device}
|
203
|
+
end
|
204
|
+
|
205
|
+
# e.g. fetch the temperature reading
|
206
|
+
#
|
207
|
+
get /fetch the ([^ ]+) +(?:reading)$/ do |device|
|
208
|
+
location = find_path(device)
|
209
|
+
{type: :get_thing, action: 'reading', location: location, thing: device}
|
210
|
+
end
|
211
|
+
|
212
|
+
end
|
213
|
+
|
214
|
+
private
|
215
|
+
|
216
|
+
def find_path(s)
|
217
|
+
puts 'find_path s: ' + s.inspect if @debug
|
218
|
+
found = query('//'+ s)
|
219
|
+
return unless found
|
220
|
+
a = found.backtrack.to_xpath.split('/')
|
221
|
+
a[1..-2].join(' ')
|
222
|
+
end
|
223
|
+
|
224
|
+
alias find_request run_route
|
225
|
+
|
226
|
+
end
|
227
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
module RemoteDroid
|
2
|
+
|
3
|
+
class Query
|
4
|
+
|
5
|
+
attr_accessor :locations
|
6
|
+
|
7
|
+
def initialize(callback)
|
8
|
+
@callback = callback
|
9
|
+
@locations = []
|
10
|
+
end
|
11
|
+
|
12
|
+
def airplane_mode_enabled?()
|
13
|
+
q(:airplane_mode_on).to_i > 0
|
14
|
+
end
|
15
|
+
|
16
|
+
def battery()
|
17
|
+
q(:battery).to_i
|
18
|
+
end
|
19
|
+
|
20
|
+
def current_brightness()
|
21
|
+
q(:current_brightness).to_i
|
22
|
+
end
|
23
|
+
|
24
|
+
alias brightness current_brightness
|
25
|
+
|
26
|
+
def cell_id()
|
27
|
+
q(:cell_id)
|
28
|
+
end
|
29
|
+
|
30
|
+
alias cell_tower cell_id
|
31
|
+
|
32
|
+
def ip()
|
33
|
+
q(:ip)
|
34
|
+
end
|
35
|
+
|
36
|
+
def location()
|
37
|
+
|
38
|
+
r = @callback.query(:location)
|
39
|
+
return r if r.nil? or r.empty? or r[:coords].nil?
|
40
|
+
|
41
|
+
r[:coords] = r[:coords].split(',')
|
42
|
+
r[:time] = Time.parse(r[:time])
|
43
|
+
@locations << r
|
44
|
+
@locations.shift if @locations.length > 1000
|
45
|
+
|
46
|
+
return r
|
47
|
+
end
|
48
|
+
|
49
|
+
def take_picture()
|
50
|
+
@callback.query(:'take-picture')
|
51
|
+
end
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def q(id)
|
56
|
+
@callback.query(id)[id]
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
60
|
+
end
|
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.
|
4
|
+
version: 0.5.2
|
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-
|
38
|
+
date: 2020-10-21 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.
|
109
|
+
version: 0.9.12
|
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.
|
119
|
+
version: 0.9.12
|
120
120
|
description:
|
121
121
|
email: james@jamesrobertson.eu
|
122
122
|
executables: []
|
@@ -124,6 +124,11 @@ extensions: []
|
|
124
124
|
extra_rdoc_files: []
|
125
125
|
files:
|
126
126
|
- lib/remotedroid.rb
|
127
|
+
- lib/remotedroid/client.rb
|
128
|
+
- lib/remotedroid/control.rb
|
129
|
+
- lib/remotedroid/controller.rb
|
130
|
+
- lib/remotedroid/model.rb
|
131
|
+
- lib/remotedroid/query.rb
|
127
132
|
homepage: https://github.com/jrobertson/remotedroid
|
128
133
|
licenses:
|
129
134
|
- MIT
|
metadata.gz.sig
CHANGED
Binary file
|