ecobee 0.2.1 → 0.2.2

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: 4e2b2a04ef326e3e40a7e7c4191de520a5792d4d
4
- data.tar.gz: 88ff1e1a5805e3a157b0c7b5ce093210d3ab8393
3
+ metadata.gz: a99a3623251e1d3a912fe40894936a22b14fb1b1
4
+ data.tar.gz: 1340b44c08f9a2367b1da7e999fbbea6f46e10a1
5
5
  SHA512:
6
- metadata.gz: 5b902bc54d038513952d96a1e0b962a65b2748d8ff80447c700eb62ba6b793c15fb9bc907db76fff960ae656b08a4c3f3610699331fc5783f2902a37a9fe0a89
7
- data.tar.gz: 445de99fe41e275297d56859752c232e940da0604e43ec13881d09a4d6ab3b3f0fc2b3f3ce9a91b4cebf044c470881f6847b66d26d33841575df17edd096c2cc
6
+ metadata.gz: 12e17299139449ac3a03380e58df09517d933cb289b14793568ded8fc06ce7df51a0c64a5d25c84523addf447912a4b4deadafd62f28a621e906e6c468acc8f9
7
+ data.tar.gz: 1cd46185bde20e5bb5caff189c283dc61ad17da6ffbbc44f956ebf79574ec1a0f8cff8ee13ccb8b1715370f04e0e01dbf3cb9c80edaf4196f0bf941f0b186586
data/README.md CHANGED
@@ -5,19 +5,16 @@ Ecobee API Ruby Gem. Implements:
5
5
  - Persistent HTTP connection management
6
6
  - Methods for GET & POST requests w/ JSON parsing & error handling
7
7
  - Persistent storage for API key & refresh tokens
8
+ - Block/Proc hooks for token storage load/save to add app config data
9
+ - Abstraction class for simple thermostat interaction
8
10
  - Example usage scripts (see /examples/\*)
9
11
 
10
12
  TODO:
11
- - Move all HTTP interaction to a dedicated/shared class
12
- - Add and test more robust Status != 0 handling via Exceptions; document
13
- - Add retries for specific !0 statuses
14
- - Add random timeout padding to avoid race conditions with multiple clients when refreshing tokens
13
+ - Add dedicated symbol class to Thermostat
15
14
  - Add RDoc documentation
16
- - Add block/proc support to token storage routines
17
15
  - Add timeout to Ecobee::Token#wait
18
16
  - Add redirect based registration
19
17
  - Implement throttling algorithm based on API feedback
20
- - Create helper methods/classes with more abstraction
21
18
  - Create examples of proper error handling
22
19
 
23
20
  ## Installation
@@ -38,9 +35,11 @@ gem install ecobee
38
35
  - Give user Ecobee::Token#pin and instructions to register your Application via the [Ecobee My Apps Portal](https://www.ecobee.com/consumerportal/index.html#/my-apps).
39
36
  - You can call Ecobee::Token#wait to block until the user confirms the PIN code.
40
37
 
41
- 3. Instantiate Ecobee::Client with the token object.
38
+ 3. Instantiate Ecobee::Thermostat with the token object.
42
39
 
43
- 4. Call Ecobee::Client#get or Ecobee::Client#post to interact with [Ecobee's API](https://www.ecobee.com/home/developer/api/introduction/index.shtml).
40
+ 4. Use the simplified methods for common interactions, access the Thermostat object directly as a Hash to read values, or use the update method to post changes.
41
+
42
+ 5. Ecobee::Client#get or Ecobee::Client#post can be used for advanced interaction with [Ecobee's API](https://www.ecobee.com/home/developer/api/introduction/index.shtml).
44
43
 
45
44
  ## Development
46
45
 
@@ -2,11 +2,6 @@ require 'pp'
2
2
  require 'json'
3
3
  require 'net/http'
4
4
 
5
- #require 'ecobee/client'
6
- #require 'ecobee/register'
7
- #require 'ecobee/token'
8
- #require 'ecobee/version'
9
-
10
5
  require_relative 'ecobee/client'
11
6
  require_relative 'ecobee/register'
12
7
  require_relative 'ecobee/thermostat'
@@ -35,7 +30,7 @@ module Ecobee
35
30
 
36
31
  HVAC_MODES = %w{auto auxHeatOnly cool heat off}
37
32
 
38
- REFRESH_PAD = 120
33
+ REFRESH_PAD = 30
39
34
  REFRESH_TOKEN_CHECK = 10
40
35
 
41
36
  SCOPES = [:smartWrite, :smartRead]
@@ -1,7 +1,6 @@
1
1
  module Ecobee
2
2
 
3
3
  class Client
4
-
5
4
  def initialize(token: nil)
6
5
  raise ArgumentError.new('Missing token') unless token
7
6
  @token = token
@@ -69,7 +68,6 @@ module Ecobee
69
68
  end
70
69
  @http
71
70
  end
72
-
73
71
  end
74
72
 
75
73
  class ClientError < StandardError ; end
@@ -1,4 +1,5 @@
1
1
  module Ecobee
2
+
2
3
  class Register
3
4
  attr_reader :expires_at, :result
4
5
 
@@ -47,4 +48,5 @@ module Ecobee
47
48
  end
48
49
 
49
50
  end
51
+
50
52
  end
@@ -1,4 +1,5 @@
1
1
  module Ecobee
2
+
2
3
  class ThermostatError < StandardError ; end
3
4
 
4
5
  class Thermostat < Hash
@@ -209,4 +210,5 @@ module Ecobee
209
210
  end
210
211
 
211
212
  end
213
+
212
214
  end
@@ -1,4 +1,5 @@
1
1
  module Ecobee
2
+
2
3
  class Token
3
4
  attr_reader :access_token,
4
5
  :access_token_expire,
@@ -40,15 +41,18 @@ module Ecobee
40
41
  end
41
42
 
42
43
  def access_token
43
- if(@access_token && @access_token_expire &&
44
- Time.now.to_i + @refresh_pad < @access_token_expire)
45
- @status = :ready
44
+ if(@access_token && @access_token_expire && !access_token_expired?)
45
+ @status = (@refresh_token ? :ready : :authorization_pending)
46
46
  @access_token
47
47
  else
48
48
  refresh_access_token
49
49
  end
50
50
  end
51
51
 
52
+ def access_token_expired?
53
+ Time.now.to_i > @access_token_expire - @refresh_pad
54
+ end
55
+
52
56
  def authorization
53
57
  "#{@token_type} #{access_token}"
54
58
  end
@@ -90,8 +94,11 @@ module Ecobee
90
94
  result = JSON.parse(response.body)
91
95
  if result.key? 'error'
92
96
  if result['error'] == 'invalid_grant'
93
- @status = :authorization_pending
94
- check_for_authorization
97
+ if access_token_expired?
98
+ register
99
+ else
100
+ check_for_authorization
101
+ end
95
102
  else
96
103
  puts "DUMPING(result): #{result.pretty_inspect}"
97
104
  raise Ecobee::TokenError.new(
@@ -134,6 +141,7 @@ module Ecobee
134
141
 
135
142
  private
136
143
 
144
+ # arrives here, expired
137
145
  def check_for_authorization
138
146
  check_for_authorization_single
139
147
  if @status == :authorization_pending
@@ -160,7 +168,6 @@ module Ecobee
160
168
  result = JSON.parse(response.body)
161
169
  if result.key? 'error'
162
170
  @status = :authorization_pending
163
-
164
171
  if result['error'] == 'invalid_client'
165
172
  register
166
173
  elsif !['slow_down', 'authorization_pending'].include? result['error']
@@ -294,6 +301,7 @@ module Ecobee
294
301
  @pin = result.pin
295
302
  @access_token = result.code
296
303
  @access_token_expire = result.expires_at
304
+ @refresh_token = nil
297
305
  @scope = result.scope
298
306
  check_for_authorization
299
307
  config_save
@@ -302,7 +310,6 @@ module Ecobee
302
310
 
303
311
  end
304
312
 
305
- class TokenError < StandardError
306
- end
313
+ class TokenError < StandardError ; end
307
314
 
308
315
  end
@@ -1,3 +1,3 @@
1
1
  module Ecobee
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ecobee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Zwissler
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-17 00:00:00.000000000 Z
11
+ date: 2016-08-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler