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 +4 -4
- data/README.md +7 -8
- data/lib/ecobee.rb +1 -6
- data/lib/ecobee/client.rb +0 -2
- data/lib/ecobee/register.rb +2 -0
- data/lib/ecobee/thermostat.rb +2 -0
- data/lib/ecobee/token.rb +15 -8
- data/lib/ecobee/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a99a3623251e1d3a912fe40894936a22b14fb1b1
|
4
|
+
data.tar.gz: 1340b44c08f9a2367b1da7e999fbbea6f46e10a1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
-
|
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::
|
38
|
+
3. Instantiate Ecobee::Thermostat with the token object.
|
42
39
|
|
43
|
-
4.
|
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
|
|
data/lib/ecobee.rb
CHANGED
@@ -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 =
|
33
|
+
REFRESH_PAD = 30
|
39
34
|
REFRESH_TOKEN_CHECK = 10
|
40
35
|
|
41
36
|
SCOPES = [:smartWrite, :smartRead]
|
data/lib/ecobee/client.rb
CHANGED
data/lib/ecobee/register.rb
CHANGED
data/lib/ecobee/thermostat.rb
CHANGED
data/lib/ecobee/token.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
94
|
-
|
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
|
data/lib/ecobee/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2016-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|