ewelink 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/ewelink/api.rb +7 -7
- data/lib/ewelink/runner.rb +6 -2
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f2548dd14bcfce1ce4cacb1a2768687d88e15bb4dae14223cadccd61176ab3d
|
4
|
+
data.tar.gz: 995f4281dd22f168ffe90dc2f072209bd25b13487bb171d5dbcc4efc94380811
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 74821997ef9c625b2506ebda9229ddac0605f7e4dda4ac836c60974fa6d17a2ebcb9cfd306947c60d958409e5277b6d2ebe1189effef32f91730bfa0be2a9883
|
7
|
+
data.tar.gz: 0d1999216c2006a5f70102190196a9c890ef9ab0c9aa6464402f8c843a51c8211852c560e62778d901eb91bf19f331f1008dd500b998cb59daf6ebe72477e5b1
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.3.0
|
data/lib/ewelink/api.rb
CHANGED
@@ -36,7 +36,7 @@ module Ewelink
|
|
36
36
|
'ts' => Time.now.to_i,
|
37
37
|
'version' => VERSION,
|
38
38
|
}
|
39
|
-
|
39
|
+
rest_request(:post, '/api/user/device/status', body: JSON.generate(params), headers: authentication_headers)
|
40
40
|
true
|
41
41
|
end
|
42
42
|
end
|
@@ -90,7 +90,7 @@ module Ewelink
|
|
90
90
|
'ts' => Time.now.to_i,
|
91
91
|
'version' => VERSION,
|
92
92
|
}
|
93
|
-
response =
|
93
|
+
response = rest_request(:get, '/api/user/device/status', headers: authentication_headers, query: params)
|
94
94
|
response['params']['switch'] == 'on'
|
95
95
|
end
|
96
96
|
|
@@ -129,7 +129,7 @@ module Ewelink
|
|
129
129
|
'ts' => Time.now.to_i,
|
130
130
|
'version' => VERSION,
|
131
131
|
}
|
132
|
-
|
132
|
+
rest_request(:post, '/api/user/device/status', body: JSON.generate(params), headers: authentication_headers)
|
133
133
|
true
|
134
134
|
end
|
135
135
|
|
@@ -156,7 +156,7 @@ module Ewelink
|
|
156
156
|
params['phoneNumber'] = phone_number
|
157
157
|
end
|
158
158
|
body = JSON.generate(params)
|
159
|
-
response =
|
159
|
+
response = rest_request(:post, '/api/user/login', { body: body, headers: { 'Authorization' => "Sign #{Base64.encode64(OpenSSL::HMAC.digest('SHA256', APP_SECRET, body))}" } })
|
160
160
|
raise(Error.new('Authentication token not found')) if response['at'].blank?
|
161
161
|
response['at'].tap { Ewelink.logger.debug(self.class.name) { 'Authentication token found' } }
|
162
162
|
end
|
@@ -173,7 +173,7 @@ module Ewelink
|
|
173
173
|
'ts' => Time.now.to_i,
|
174
174
|
'version' => VERSION,
|
175
175
|
}
|
176
|
-
response =
|
176
|
+
response = rest_request(:get, '/api/user/device', headers: authentication_headers, query: params)
|
177
177
|
response['devicelist'].tap { |devices| Ewelink.logger.debug(self.class.name) { "Found #{devices.size} device(s)" } }
|
178
178
|
end
|
179
179
|
end
|
@@ -195,7 +195,7 @@ module Ewelink
|
|
195
195
|
@region ||= DEFAULT_REGION
|
196
196
|
end
|
197
197
|
|
198
|
-
def
|
198
|
+
def rest_request(method, path, options = {})
|
199
199
|
url = "#{URL.gsub('#{region}', region)}#{path}"
|
200
200
|
method = method.to_s.upcase
|
201
201
|
headers = (options[:headers] || {}).reverse_merge('Content-Type' => 'application/json')
|
@@ -205,7 +205,7 @@ module Ewelink
|
|
205
205
|
if response['error'] == 301 && response['region'].present?
|
206
206
|
@region = response['region']
|
207
207
|
Ewelink.logger.debug(self.class.name) { "Switched to region #{region.inspect}" }
|
208
|
-
return
|
208
|
+
return rest_request(method, path, options)
|
209
209
|
end
|
210
210
|
remove_instance_variable(:@authentication_token) if instance_variable_defined?(:@authentication_token) && [401, 403].include?(response['error'])
|
211
211
|
raise(Error.new("#{method} #{url}: #{response['error']} #{response['msg']}".strip)) if response['error'].present? && response['error'] != 0
|
data/lib/ewelink/runner.rb
CHANGED
@@ -9,13 +9,14 @@ module Ewelink
|
|
9
9
|
options[:turn_switches_on_uuids].each { |uuid| api.turn_switch!(uuid, :on) }
|
10
10
|
options[:turn_switches_off_uuids].each { |uuid| api.turn_switch!(uuid, :off) }
|
11
11
|
options[:press_rf_bridge_buttons_uuids].each { |uuid| api.press_rf_bridge_button!(uuid) }
|
12
|
+
puts(JSON.pretty_generate(options[:switch_status_uuids].map { |uuid| [uuid, api.switch_on?(uuid) ? 'on' : 'off'] }.to_h))
|
12
13
|
end
|
13
14
|
|
14
15
|
private
|
15
16
|
|
16
17
|
def options
|
17
18
|
@options ||= begin
|
18
|
-
options = { press_rf_bridge_buttons_uuids: [], turn_switches_off_uuids: [], turn_switches_on_uuids: [] }
|
19
|
+
options = { press_rf_bridge_buttons_uuids: [], turn_switches_off_uuids: [], turn_switches_on_uuids: [], switch_status_uuids: [] }
|
19
20
|
parser = OptionParser.new do |opts|
|
20
21
|
opts.banner = 'Manage eWeLink smart home devices'
|
21
22
|
opts.version = File.read(File.expand_path('../../VERSION', __dir__)).strip
|
@@ -46,6 +47,9 @@ module Ewelink
|
|
46
47
|
opts.on('--press-rf-bridge-button BUTTON_UUID', 'Press RF 433MHz bridge button with specified UUID') do |uuid|
|
47
48
|
options[:press_rf_bridge_buttons_uuids] << uuid
|
48
49
|
end
|
50
|
+
opts.on('--switch-status SWITCH_UUID', 'Displays switch status of specified UUID') do |uuid|
|
51
|
+
options[:switch_status_uuids] << uuid
|
52
|
+
end
|
49
53
|
opts.on('-v', '--verbose', 'Verbose mode') do
|
50
54
|
Ewelink.logger.level = :debug
|
51
55
|
end
|
@@ -61,7 +65,7 @@ module Ewelink
|
|
61
65
|
STDERR.puts(parser.summarize)
|
62
66
|
exit(1)
|
63
67
|
end
|
64
|
-
if [:list_switches, :list_rf_bridge_buttons, :turn_switches_on_uuids, :turn_switches_off_uuids, :press_rf_bridge_buttons_uuids].map { |action| options[action] }.all?(&:blank?)
|
68
|
+
if [:list_switches, :list_rf_bridge_buttons, :turn_switches_on_uuids, :turn_switches_off_uuids, :press_rf_bridge_buttons_uuids, :switch_status_uuids].map { |action| options[action] }.all?(&:blank?)
|
65
69
|
STDERR.puts('An action must be specified (listing switches, press RF bridge button, etc.)')
|
66
70
|
STDERR.puts(parser.summarize)
|
67
71
|
exit(1)
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ewelink
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexis Toulotte
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-
|
11
|
+
date: 2020-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -109,7 +109,7 @@ homepage: https://github.com/alexistoulotte/ewelink
|
|
109
109
|
licenses:
|
110
110
|
- MIT
|
111
111
|
metadata: {}
|
112
|
-
post_install_message:
|
112
|
+
post_install_message:
|
113
113
|
rdoc_options: []
|
114
114
|
require_paths:
|
115
115
|
- lib
|
@@ -125,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
127
|
rubygems_version: 3.0.3
|
128
|
-
signing_key:
|
128
|
+
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: Manage eWeLink devices
|
131
131
|
test_files: []
|