ecobee 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 48dab0a8186e1abe5f05115a744bf06a6167b718
4
- data.tar.gz: d76e8de7fbf97ae44095436197f1d7085a324d9d
3
+ metadata.gz: b62f3e7da3fde7ec3f2b62407f1f4f656179ff29
4
+ data.tar.gz: 39a2c7d8f683b4094052ce433bc94d97064e6026
5
5
  SHA512:
6
- metadata.gz: 7e5ca066357160e4f43a67d90f6186437cf98f7a1105f1dba652eac447c588cec03c43f8c2e44f3caf791a0eabca9fc4b64f213f4a588e32c0ad9411cade0c05
7
- data.tar.gz: 0bbc4eb430f37858787f915b10ab4af799fac335651344357e41becf7a883e3dd090d9359438e04ab0b9de50671df6cd4ab084b051b8ed244be8b777142c157a
6
+ metadata.gz: bc42968dec571366c148e4c6ebaf365be8c587bfeaf31355aa833302b474776bd95e8c8fc04c61ea207a3a26d81e49dcd540154994e615fe67e2097fe0778236
7
+ data.tar.gz: a1d941292c3b5be46861e8020f03c515d85f3810009ad4eb7efbaea2dab1bd613a96b733aec772324ab8553a6982ea1309aceb240d142b094acf2037b5084592
@@ -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(
@@ -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
@@ -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
- @http = Ecobee::HTTP.new(log_file: "/tmp/token.log", token: self)
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
- check_for_authorization_single
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
- puts "check_for_authorization_single"
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 check_for_authorization_single
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)
@@ -1,3 +1,3 @@
1
1
  module Ecobee
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecobee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Zwissler