ewelink 1.1.0 → 1.2.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 +60 -54
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 21968b7bb562eb3c32f0011a501ea3978fabd5ba3cc50164854e7a544c607f09
|
4
|
+
data.tar.gz: cdedc7c05271d76f5f38317b3276bae9c24c7380877e97988c0aea9f048d88fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ddd38e7e100f20ce2a96edcf3e2c3a3ac1c2945c0ad49e93aeeb3ecf943d08db03756afb4847c28c55a7601f952a13abe1034858f66ba46ec8e6359523a2b696
|
7
|
+
data.tar.gz: fb913f0ae36bf7f72bb27c8af1e863deb55b8309f23a79dc799e677c2f5706671a7a7b2efdff1ad8a7bfeec46c6ffc23774564738a12ad4dc20ebf1f2f1fd2f8
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.2.0
|
data/lib/ewelink/api.rb
CHANGED
@@ -23,20 +23,22 @@ module Ewelink
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def press_rf_bridge_button!(uuid)
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
'
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
26
|
+
synchronize(:press_rf_bridge_button) do
|
27
|
+
button = find_rf_bridge_button!(uuid)
|
28
|
+
params = {
|
29
|
+
'appid' => APP_ID,
|
30
|
+
'deviceid' => button[:device_id],
|
31
|
+
'nonce' => nonce,
|
32
|
+
'params' => {
|
33
|
+
'cmd' => 'transmit',
|
34
|
+
'rfChl' => button[:channel],
|
35
|
+
},
|
36
|
+
'ts' => Time.now.to_i,
|
37
|
+
'version' => VERSION,
|
38
|
+
}
|
39
|
+
http_request(:post, '/api/user/device/status', body: JSON.generate(params), headers: authentication_headers)
|
40
|
+
true
|
41
|
+
end
|
40
42
|
end
|
41
43
|
|
42
44
|
def reload
|
@@ -48,33 +50,35 @@ module Ewelink
|
|
48
50
|
end
|
49
51
|
|
50
52
|
def rf_bridge_buttons
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
rf_bridge_devices.each do |device|
|
56
|
-
device_id = device['deviceid'].presence || next
|
57
|
-
device_name = device['name'].presence || next
|
58
|
-
buttons = device['params']['rfList'].each do |rf|
|
59
|
-
button = {
|
60
|
-
channel: rf['rfChl'],
|
61
|
-
device_id: device_id,
|
62
|
-
device_name: device_name,
|
63
|
-
}
|
64
|
-
remote_info = device['tags']['zyx_info'].find { |info| info['buttonName'].find { |data| data.key?(button[:channel].to_s) } }.presence || next
|
65
|
-
remote_name = remote_info['name'].try(:squish).presence || next
|
66
|
-
button_info = remote_info['buttonName'].find { |info| info.key?(button[:channel].to_s) }.presence || next
|
67
|
-
button_name = button_info.values.first.try(:squish).presence || next
|
68
|
-
button.merge!({
|
69
|
-
name: button_name,
|
70
|
-
remote_name: remote_name,
|
71
|
-
remote_type: remote_info['remote_type'],
|
72
|
-
})
|
73
|
-
button[:uuid] = Digest::UUID.uuid_v5(UUID_NAMESPACE, "#{button[:device_id]}/#{button[:channel]}")
|
74
|
-
buttons << button
|
53
|
+
synchronize(:rf_bridge_buttons) do
|
54
|
+
@rf_bridge_buttons ||= [].tap do |buttons|
|
55
|
+
rf_bridge_devices = devices.select { |device| device['uiid'] == RF_BRIDGE_DEVICE_UIID }.tap do |devices|
|
56
|
+
Ewelink.logger.debug(self.class.name) { "Found #{devices.size} RF 433MHz bridge device(s)" }
|
75
57
|
end
|
76
|
-
|
77
|
-
|
58
|
+
rf_bridge_devices.each do |device|
|
59
|
+
device_id = device['deviceid'].presence || next
|
60
|
+
device_name = device['name'].presence || next
|
61
|
+
buttons = device['params']['rfList'].each do |rf|
|
62
|
+
button = {
|
63
|
+
channel: rf['rfChl'],
|
64
|
+
device_id: device_id,
|
65
|
+
device_name: device_name,
|
66
|
+
}
|
67
|
+
remote_info = device['tags']['zyx_info'].find { |info| info['buttonName'].find { |data| data.key?(button[:channel].to_s) } }.presence || next
|
68
|
+
remote_name = remote_info['name'].try(:squish).presence || next
|
69
|
+
button_info = remote_info['buttonName'].find { |info| info.key?(button[:channel].to_s) }.presence || next
|
70
|
+
button_name = button_info.values.first.try(:squish).presence || next
|
71
|
+
button.merge!({
|
72
|
+
name: button_name,
|
73
|
+
remote_name: remote_name,
|
74
|
+
remote_type: remote_info['remote_type'],
|
75
|
+
})
|
76
|
+
button[:uuid] = Digest::UUID.uuid_v5(UUID_NAMESPACE, "#{button[:device_id]}/#{button[:channel]}")
|
77
|
+
buttons << button
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end.tap { |buttons| Ewelink.logger.debug(self.class.name) { "Found #{buttons.size} RF 433MHz bridge button(s)" } }
|
81
|
+
end
|
78
82
|
end
|
79
83
|
|
80
84
|
def switch_on?(uuid)
|
@@ -91,19 +95,21 @@ module Ewelink
|
|
91
95
|
end
|
92
96
|
|
93
97
|
def switches
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
98
|
+
synchronize(:switches) do
|
99
|
+
@switches ||= [].tap do |switches|
|
100
|
+
switch_devices = devices.select { |device| SWITCH_DEVICES_UIIDS.include?(device['uiid']) }
|
101
|
+
switch_devices.each do |device|
|
102
|
+
device_id = device['deviceid'].presence || next
|
103
|
+
name = device['name'].presence || next
|
104
|
+
switch = {
|
105
|
+
device_id: device_id,
|
106
|
+
name: name,
|
107
|
+
}
|
108
|
+
switch[:uuid] = Digest::UUID.uuid_v5(UUID_NAMESPACE, switch[:device_id])
|
109
|
+
switches << switch
|
110
|
+
end
|
111
|
+
end.tap { |switches| Ewelink.logger.debug(self.class.name) { "Found #{switches.size} switch(es)" } }
|
112
|
+
end
|
107
113
|
end
|
108
114
|
|
109
115
|
def turn_switch!(uuid, on)
|
@@ -194,7 +200,7 @@ module Ewelink
|
|
194
200
|
method = method.to_s.upcase
|
195
201
|
headers = (options[:headers] || {}).reverse_merge('Content-Type' => 'application/json')
|
196
202
|
Ewelink.logger.debug(self.class.name) { "#{method} #{url}" }
|
197
|
-
response =
|
203
|
+
response = HTTParty.send(method.downcase, url, options.merge(headers: headers).reverse_merge(timeout: TIMEOUT))
|
198
204
|
raise(Error.new("#{method} #{url}: #{response.code}")) unless response.success?
|
199
205
|
if response['error'] == 301 && response['region'].present?
|
200
206
|
@region = response['region']
|