ecobee 0.3.0 → 0.3.1
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/lib/ecobee/http.rb +3 -2
- data/lib/ecobee/thermostat.rb +1 -1
- data/lib/ecobee/token.rb +10 -6
- data/lib/ecobee/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b62f3e7da3fde7ec3f2b62407f1f4f656179ff29
|
4
|
+
data.tar.gz: 39a2c7d8f683b4094052ce433bc94d97064e6026
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc42968dec571366c148e4c6ebaf365be8c587bfeaf31355aa833302b474776bd95e8c8fc04c61ea207a3a26d81e49dcd540154994e615fe67e2097fe0778236
|
7
|
+
data.tar.gz: a1d941292c3b5be46861e8020f03c515d85f3810009ad4eb7efbaea2dab1bd613a96b733aec772324ab8553a6982ea1309aceb240d142b094acf2037b5084592
|
data/lib/ecobee/http.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
1
|
module Ecobee
|
2
|
-
|
3
|
-
class HTTPError < StandardError ; end
|
2
|
+
class HTTPError < StandardError ; end
|
4
3
|
class AuthError < HTTPError ; end
|
5
4
|
|
6
5
|
class HTTP
|
@@ -127,6 +126,8 @@ module Ecobee
|
|
127
126
|
elsif !response['status'].key? 'code'
|
128
127
|
raise Ecobee::HTTPError.new('Validate Error: Missing Status Code')
|
129
128
|
elsif response['status']['code'] == 14
|
129
|
+
log "validate_status: token expired access_token_expire: #{@token.access_token_expire}"
|
130
|
+
log "validate_status: now: #{Time.now.to_i}"
|
130
131
|
:retry
|
131
132
|
elsif response['status']['code'] != 0
|
132
133
|
raise Ecobee::HTTPError.new(
|
data/lib/ecobee/thermostat.rb
CHANGED
@@ -240,7 +240,7 @@ module Ecobee
|
|
240
240
|
body = my_selection
|
241
241
|
body.merge!({ 'functions' => functions }) if functions
|
242
242
|
body.merge!({ 'thermostat' => thermostat }) if thermostat
|
243
|
-
@http.post(:thermostat, body: body)
|
243
|
+
@http.post(arg: :thermostat, body: body)
|
244
244
|
end
|
245
245
|
|
246
246
|
end
|
data/lib/ecobee/token.rb
CHANGED
@@ -26,6 +26,7 @@ module Ecobee
|
|
26
26
|
access_token_expire: nil,
|
27
27
|
app_key: nil,
|
28
28
|
callbacks: {},
|
29
|
+
log_file: nil,
|
29
30
|
refresh_token: nil,
|
30
31
|
scope: SCOPES[0],
|
31
32
|
token_file: DEFAULT_FILES
|
@@ -40,7 +41,8 @@ module Ecobee
|
|
40
41
|
|
41
42
|
@authorization_thread, @pin, @status, @token_type = nil
|
42
43
|
@poll_interval = DEFAULT_POLL_INTERVAL
|
43
|
-
|
44
|
+
|
45
|
+
@http = Ecobee::HTTP.new(log_file: log_file, token: self)
|
44
46
|
|
45
47
|
@refresh_pad = REFRESH_PAD + rand(REFRESH_PAD)
|
46
48
|
|
@@ -52,8 +54,10 @@ module Ecobee
|
|
52
54
|
if @access_token
|
53
55
|
if access_token_expired?
|
54
56
|
if @refresh_token
|
57
|
+
@http.log "access_token: refreshing #{@access_token}, #{@access_token_expire}, #{Time.now.to_i}"
|
55
58
|
refresh_access_token
|
56
59
|
else
|
60
|
+
@http.log "access_token: token_register"
|
57
61
|
token_register
|
58
62
|
end
|
59
63
|
else
|
@@ -63,8 +67,10 @@ module Ecobee
|
|
63
67
|
puts "Status: MISMATCH: #{@status} vs #{desired_status}" if @status
|
64
68
|
@status = desired_status
|
65
69
|
end
|
70
|
+
@http.log "access_token: good #{@access_token}, #{@access_token_expire}, #{Time.now.to_i}"
|
66
71
|
@access_token
|
67
72
|
else
|
73
|
+
@http.log "access_token: check_for_authorization #{@access_token}, #{@access_token_expire}"
|
68
74
|
check_for_authorization
|
69
75
|
end
|
70
76
|
end
|
@@ -162,23 +168,21 @@ module Ecobee
|
|
162
168
|
|
163
169
|
# arrives here, expired
|
164
170
|
def check_for_authorization
|
165
|
-
|
171
|
+
do_check_for_authorization
|
166
172
|
if @status == :authorization_pending
|
167
173
|
unless @authorization_thread && @authorization_thread.alive?
|
168
174
|
@authorization_thread = Thread.new {
|
169
175
|
loop do
|
170
|
-
puts "Sleeping for #{@poll_interval}"
|
171
176
|
sleep @poll_interval
|
172
177
|
break if @status == :ready
|
173
|
-
|
174
|
-
check_for_authorization_single
|
178
|
+
do_check_for_authorization
|
175
179
|
end
|
176
180
|
}
|
177
181
|
end
|
178
182
|
end
|
179
183
|
end
|
180
184
|
|
181
|
-
def
|
185
|
+
def do_check_for_authorization
|
182
186
|
arg = sprintf("?grant_type=ecobeePin&code=%s&client_id=%s",
|
183
187
|
@access_token,
|
184
188
|
@app_key)
|
data/lib/ecobee/version.rb
CHANGED