ewelink 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/ewelink/api.rb +60 -54
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: aa2540d5e8dcf125b91c086731711b772516e28466e33b2bb668bd143abb5fe7
4
- data.tar.gz: caf1bfa5d91d0edefc143f49230b0592aafecbbb40e7e80a7d5279f5c3685e0d
3
+ metadata.gz: 21968b7bb562eb3c32f0011a501ea3978fabd5ba3cc50164854e7a544c607f09
4
+ data.tar.gz: cdedc7c05271d76f5f38317b3276bae9c24c7380877e97988c0aea9f048d88fa
5
5
  SHA512:
6
- metadata.gz: c09430a4c2f0a31d62c20828f8e0591cff4f808e9660ae3d309c5fd67edde27aa750ba2d864b1c2d0ad99268b32cb8b05837c407afa268a74ae4d6254aac3859
7
- data.tar.gz: 2a5d636f6a571ece7e7cf83cac4eae90b9457212e6260b946c1172dd773e1a438e4ecdf31dee531ada59810440fa4e7a1bfa0af996c974c133e52f61a644638d
6
+ metadata.gz: ddd38e7e100f20ce2a96edcf3e2c3a3ac1c2945c0ad49e93aeeb3ecf943d08db03756afb4847c28c55a7601f952a13abe1034858f66ba46ec8e6359523a2b696
7
+ data.tar.gz: fb913f0ae36bf7f72bb27c8af1e863deb55b8309f23a79dc799e677c2f5706671a7a7b2efdff1ad8a7bfeec46c6ffc23774564738a12ad4dc20ebf1f2f1fd2f8
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
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
- button = find_rf_bridge_button!(uuid)
27
- params = {
28
- 'appid' => APP_ID,
29
- 'deviceid' => button[:device_id],
30
- 'nonce' => nonce,
31
- 'params' => {
32
- 'cmd' => 'transmit',
33
- 'rfChl' => button[:channel],
34
- },
35
- 'ts' => Time.now.to_i,
36
- 'version' => VERSION,
37
- }
38
- http_request(:post, '/api/user/device/status', body: JSON.generate(params), headers: authentication_headers)
39
- true
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
- @rf_bridge_buttons ||= [].tap do |buttons|
52
- rf_bridge_devices = devices.select { |device| device['uiid'] == RF_BRIDGE_DEVICE_UIID }.tap do |devices|
53
- Ewelink.logger.debug(self.class.name) { "Found #{devices.size} RF 433MHz Bridge device(s)" }
54
- end
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
- end
77
- end.tap { |buttons| Ewelink.logger.debug(self.class.name) { "Found #{buttons.size} RF 433MHz bridge button(s)" } }
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
- @switches ||= [].tap do |switches|
95
- switch_devices = devices.select { |device| SWITCH_DEVICES_UIIDS.include?(device['uiid']) }
96
- switch_devices.each do |device|
97
- device_id = device['deviceid'].presence || next
98
- name = device['name'].presence || next
99
- switch = {
100
- device_id: device_id,
101
- name: name,
102
- }
103
- switch[:uuid] = Digest::UUID.uuid_v5(UUID_NAMESPACE, switch[:device_id])
104
- switches << switch
105
- end
106
- end.tap { |switches| Ewelink.logger.debug(self.class.name) { "Found #{switches.size} switch(es)" } }
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 = synchronize(:http_request) { HTTParty.send(method.downcase, url, options.merge(headers: headers).reverse_merge(timeout: TIMEOUT)) }
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']
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ewelink
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexis Toulotte