ewelink 3.2.0 → 3.3.0
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
- data/README.mdown +3 -0
- data/VERSION +1 -1
- data/ewelink.gemspec +2 -1
- data/lib/ewelink.rb +1 -0
- data/lib/ewelink/api.rb +59 -43
- metadata +26 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0663d2b0ebc1394f91996e8b8ee54954c8bf02b07b7cdec7448a7c0d2816a715
|
4
|
+
data.tar.gz: 4ad467928041577a73e382a241575c4ad9524c4c9d141df1e5689b673353bede
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 529c2969099aa2db41238b5f4380f7a7dd69a68cf7e043546cc297fb43b8146b6fbe34ff1df19865de8bcf5b04d8bffbb20e274da7cb22da42b310cf808628b1
|
7
|
+
data.tar.gz: 6d74b68ecc5abfae875808286c1666ac793e1970104ea59e87ce34ccd3c0446baf82e0101e9406bbf6e6e08c23c957b275904d924ed480f11f3db4108901b4f7
|
data/README.mdown
CHANGED
@@ -77,6 +77,9 @@ api.press_rf_bridge_button!(button[:uuid])
|
|
77
77
|
|
78
78
|
### Additional options
|
79
79
|
|
80
|
+
- `async_actions` (`true` | `false`): To perform actions (pressing an RF
|
81
|
+
bridge button or turning a switch on/off) in asynchronous mode. (default:
|
82
|
+
`false`).
|
80
83
|
- `update_devices_status_on_connect` (`true` | `false`): To update devices
|
81
84
|
status (on, off) when connecting to Ewelink API (default: `false`).
|
82
85
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
3.
|
1
|
+
3.3.0
|
data/ewelink.gemspec
CHANGED
@@ -18,7 +18,8 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.add_dependency 'activesupport', '>= 6.0.0', '< 7.0.0'
|
19
19
|
s.add_dependency 'faye-websocket', '>= 0.11.0', '< 0.12.0'
|
20
20
|
s.add_dependency 'httparty', '>= 0.18.0', '< 0.19.0'
|
21
|
+
s.add_dependency 'thread', '>= 0.2.0', '< 0.3.0'
|
21
22
|
|
22
23
|
s.add_development_dependency 'byebug', '>= 11.0.0', '< 12.0.0'
|
23
|
-
s.add_development_dependency 'rake', '>=
|
24
|
+
s.add_development_dependency 'rake', '>= 13.0.0', '< 14.0.0'
|
24
25
|
end
|
data/lib/ewelink.rb
CHANGED
data/lib/ewelink/api.rb
CHANGED
@@ -18,7 +18,8 @@ module Ewelink
|
|
18
18
|
|
19
19
|
attr_reader :email, :password, :phone_number
|
20
20
|
|
21
|
-
def initialize(email: nil, password:, phone_number: nil, update_devices_status_on_connect: false)
|
21
|
+
def initialize(async_actions: false, email: nil, password:, phone_number: nil, update_devices_status_on_connect: false)
|
22
|
+
@async_actions = async_actions.present?
|
22
23
|
@email = email.presence.try(:strip)
|
23
24
|
@mutexs = {}
|
24
25
|
@password = password.presence || raise(Error.new(":password must be specified"))
|
@@ -32,25 +33,31 @@ module Ewelink
|
|
32
33
|
start_web_socket_authentication_check_thread
|
33
34
|
end
|
34
35
|
|
36
|
+
def async_actions?
|
37
|
+
@async_actions
|
38
|
+
end
|
39
|
+
|
35
40
|
def press_rf_bridge_button!(uuid)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
'
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
41
|
+
process_action do
|
42
|
+
synchronize(:press_rf_bridge_button) do
|
43
|
+
button = find_rf_bridge_button!(uuid)
|
44
|
+
web_socket_wait_for(-> { web_socket_authenticated? }, initialize_web_socket: true) do
|
45
|
+
params = {
|
46
|
+
'action' => 'update',
|
47
|
+
'apikey' => button[:api_key],
|
48
|
+
'deviceid' => button[:device_id],
|
49
|
+
'params' => {
|
50
|
+
'cmd' => 'transmit',
|
51
|
+
'rfChl' => button[:channel],
|
52
|
+
},
|
53
|
+
'sequence' => web_socket_sequence,
|
54
|
+
'ts' => 0,
|
55
|
+
'userAgent' => 'app',
|
56
|
+
}
|
57
|
+
Ewelink.logger.debug(self.class.name) { "Pressing RF bridge button #{button[:uuid].inspect}" }
|
58
|
+
send_to_web_socket(JSON.generate(params))
|
59
|
+
true
|
60
|
+
end
|
54
61
|
end
|
55
62
|
end
|
56
63
|
end
|
@@ -172,31 +179,33 @@ module Ewelink
|
|
172
179
|
end
|
173
180
|
|
174
181
|
def turn_switch!(uuid, on)
|
175
|
-
|
176
|
-
on
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
'
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
182
|
+
process_action do
|
183
|
+
if ['on', :on, 'true'].include?(on)
|
184
|
+
on = true
|
185
|
+
elsif ['off', :off, 'false'].include?(on)
|
186
|
+
on = false
|
187
|
+
end
|
188
|
+
switch = find_switch!(uuid)
|
189
|
+
@web_socket_switches_statuses[switch[:uuid]] = nil
|
190
|
+
web_socket_wait_for(-> { web_socket_authenticated? }, initialize_web_socket: true) do
|
191
|
+
params = {
|
192
|
+
'action' => 'update',
|
193
|
+
'apikey' => switch[:api_key],
|
194
|
+
'deviceid' => switch[:device_id],
|
195
|
+
'params' => {
|
196
|
+
'switch' => on ? 'on' : 'off',
|
197
|
+
},
|
198
|
+
'sequence' => web_socket_sequence,
|
199
|
+
'ts' => 0,
|
200
|
+
'userAgent' => 'app',
|
201
|
+
}
|
202
|
+
Ewelink.logger.debug(self.class.name) { "Turning switch #{switch[:uuid].inspect} #{on ? 'on' : 'off'}" }
|
203
|
+
send_to_web_socket(JSON.generate(params))
|
204
|
+
end
|
205
|
+
sleep(SWITCH_STATUS_CHANGE_CHECK_TIMEOUT)
|
206
|
+
switch_on?(switch[:uuid]) # Waiting for switch status update
|
207
|
+
true
|
196
208
|
end
|
197
|
-
sleep(SWITCH_STATUS_CHANGE_CHECK_TIMEOUT)
|
198
|
-
switch_on?(switch[:uuid]) # Waiting for switch status update
|
199
|
-
true
|
200
209
|
end
|
201
210
|
|
202
211
|
def update_devices_status_on_connect?
|
@@ -289,6 +298,13 @@ module Ewelink
|
|
289
298
|
SecureRandom.hex[0, 8]
|
290
299
|
end
|
291
300
|
|
301
|
+
def process_action(&block)
|
302
|
+
return yield unless async_actions?
|
303
|
+
@async_actions_thread_pool ||= Thread.pool(1)
|
304
|
+
@async_actions_thread_pool.process(&block)
|
305
|
+
nil
|
306
|
+
end
|
307
|
+
|
292
308
|
def region
|
293
309
|
@region ||= DEFAULT_REGION
|
294
310
|
end
|
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: 3.
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alexis Toulotte
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-04-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -70,6 +70,26 @@ dependencies:
|
|
70
70
|
- - "<"
|
71
71
|
- !ruby/object:Gem::Version
|
72
72
|
version: 0.19.0
|
73
|
+
- !ruby/object:Gem::Dependency
|
74
|
+
name: thread
|
75
|
+
requirement: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: 0.2.0
|
80
|
+
- - "<"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 0.3.0
|
83
|
+
type: :runtime
|
84
|
+
prerelease: false
|
85
|
+
version_requirements: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.2.0
|
90
|
+
- - "<"
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: 0.3.0
|
73
93
|
- !ruby/object:Gem::Dependency
|
74
94
|
name: byebug
|
75
95
|
requirement: !ruby/object:Gem::Requirement
|
@@ -96,20 +116,20 @@ dependencies:
|
|
96
116
|
requirements:
|
97
117
|
- - ">="
|
98
118
|
- !ruby/object:Gem::Version
|
99
|
-
version:
|
119
|
+
version: 13.0.0
|
100
120
|
- - "<"
|
101
121
|
- !ruby/object:Gem::Version
|
102
|
-
version:
|
122
|
+
version: 14.0.0
|
103
123
|
type: :development
|
104
124
|
prerelease: false
|
105
125
|
version_requirements: !ruby/object:Gem::Requirement
|
106
126
|
requirements:
|
107
127
|
- - ">="
|
108
128
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
129
|
+
version: 13.0.0
|
110
130
|
- - "<"
|
111
131
|
- !ruby/object:Gem::Version
|
112
|
-
version:
|
132
|
+
version: 14.0.0
|
113
133
|
description: Manage eWeLink smart home devices
|
114
134
|
email: al@alweb.org
|
115
135
|
executables:
|