stekker_easee 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/Gemfile.lock +68 -75
- data/bin/release +1 -1
- data/easee.gemspec +0 -1
- data/lib/easee/amazon_gw_middleware.rb +10 -0
- data/lib/easee/client.rb +24 -7
- data/lib/easee/errors.rb +4 -0
- data/lib/easee/version.rb +1 -1
- data/lib/stekker_easee.rb +4 -1
- metadata +4 -17
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc3c3c0ca289246df91530ff1103931b3f0a847b0ccc812c836a1acfa6148b0f
|
4
|
+
data.tar.gz: f2d2eb1332ca65973f256feb4d8546ece4c4af06ca509229b865db7071ebbbc1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d2bbbace02bafae50a3adcbf1a75850d84c6f11b720071064aa83cb0eb33134dac2363c1f8f7378a9f90d9f095a8b8c8b28cfd250972df6e3da8c71fe12376bb
|
7
|
+
data.tar.gz: 953c5edf8b8d077a3e2d7a84ee27f88b1f74f214b2e34383378e9e123c72e1d31ba9dcca0a89ae59e8b8cf4c90f1b3ce39da3e58b4d6d1bbf82df66d2224b2ff
|
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,126 +1,119 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
stekker_easee (1.0.
|
4
|
+
stekker_easee (1.0.2)
|
5
5
|
activemodel
|
6
6
|
activesupport
|
7
7
|
faraday
|
8
|
-
faraday_middleware
|
9
8
|
|
10
9
|
GEM
|
11
10
|
remote: https://rubygems.org/
|
12
11
|
specs:
|
13
|
-
activemodel (7.
|
14
|
-
activesupport (= 7.
|
15
|
-
activesupport (7.
|
12
|
+
activemodel (7.1.3.2)
|
13
|
+
activesupport (= 7.1.3.2)
|
14
|
+
activesupport (7.1.3.2)
|
15
|
+
base64
|
16
|
+
bigdecimal
|
16
17
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
18
|
+
connection_pool (>= 2.2.5)
|
19
|
+
drb
|
17
20
|
i18n (>= 1.6, < 2)
|
18
21
|
minitest (>= 5.1)
|
22
|
+
mutex_m
|
19
23
|
tzinfo (~> 2.0)
|
20
|
-
addressable (2.8.
|
24
|
+
addressable (2.8.6)
|
21
25
|
public_suffix (>= 2.0.2, < 6.0)
|
22
26
|
ast (2.4.2)
|
23
|
-
base64 (0.
|
24
|
-
|
25
|
-
|
27
|
+
base64 (0.2.0)
|
28
|
+
bigdecimal (3.1.7)
|
29
|
+
concurrent-ruby (1.2.3)
|
30
|
+
connection_pool (2.4.1)
|
31
|
+
crack (1.0.0)
|
32
|
+
bigdecimal
|
26
33
|
rexml
|
27
|
-
diff-lcs (1.5.
|
28
|
-
|
29
|
-
|
30
|
-
faraday-
|
31
|
-
|
32
|
-
|
33
|
-
faraday-multipart (~> 1.0)
|
34
|
-
faraday-net_http (~> 1.0)
|
35
|
-
faraday-net_http_persistent (~> 1.0)
|
36
|
-
faraday-patron (~> 1.0)
|
37
|
-
faraday-rack (~> 1.0)
|
38
|
-
faraday-retry (~> 1.0)
|
39
|
-
ruby2_keywords (>= 0.0.4)
|
40
|
-
faraday-em_http (1.0.0)
|
41
|
-
faraday-em_synchrony (1.0.0)
|
42
|
-
faraday-excon (1.1.0)
|
43
|
-
faraday-httpclient (1.0.1)
|
44
|
-
faraday-multipart (1.0.4)
|
45
|
-
multipart-post (~> 2)
|
46
|
-
faraday-net_http (1.0.1)
|
47
|
-
faraday-net_http_persistent (1.2.0)
|
48
|
-
faraday-patron (1.0.0)
|
49
|
-
faraday-rack (1.0.0)
|
50
|
-
faraday-retry (1.0.3)
|
51
|
-
faraday_middleware (1.2.0)
|
52
|
-
faraday (~> 1.0)
|
34
|
+
diff-lcs (1.5.1)
|
35
|
+
drb (2.2.1)
|
36
|
+
faraday (2.9.0)
|
37
|
+
faraday-net_http (>= 2.0, < 3.2)
|
38
|
+
faraday-net_http (3.1.0)
|
39
|
+
net-http
|
53
40
|
gem-release (2.2.2)
|
54
|
-
hashdiff (1.0
|
55
|
-
i18n (1.14.
|
41
|
+
hashdiff (1.1.0)
|
42
|
+
i18n (1.14.4)
|
56
43
|
concurrent-ruby (~> 1.0)
|
57
|
-
json (2.
|
44
|
+
json (2.7.1)
|
58
45
|
language_server-protocol (3.17.0.3)
|
59
|
-
minitest (5.
|
60
|
-
|
61
|
-
|
62
|
-
|
46
|
+
minitest (5.22.3)
|
47
|
+
mutex_m (0.2.0)
|
48
|
+
net-http (0.4.1)
|
49
|
+
uri
|
50
|
+
parallel (1.24.0)
|
51
|
+
parser (3.3.0.5)
|
63
52
|
ast (~> 2.4.1)
|
64
53
|
racc
|
65
|
-
public_suffix (5.0.
|
66
|
-
racc (1.7.
|
67
|
-
rack (3.0.
|
54
|
+
public_suffix (5.0.5)
|
55
|
+
racc (1.7.3)
|
56
|
+
rack (3.0.10)
|
68
57
|
rainbow (3.1.1)
|
69
|
-
rake (13.0
|
70
|
-
regexp_parser (2.
|
71
|
-
rexml (3.
|
72
|
-
rspec (3.
|
73
|
-
rspec-core (~> 3.
|
74
|
-
rspec-expectations (~> 3.
|
75
|
-
rspec-mocks (~> 3.
|
76
|
-
rspec-core (3.
|
77
|
-
rspec-support (~> 3.
|
78
|
-
rspec-expectations (3.
|
58
|
+
rake (13.2.0)
|
59
|
+
regexp_parser (2.9.0)
|
60
|
+
rexml (3.3.9)
|
61
|
+
rspec (3.13.0)
|
62
|
+
rspec-core (~> 3.13.0)
|
63
|
+
rspec-expectations (~> 3.13.0)
|
64
|
+
rspec-mocks (~> 3.13.0)
|
65
|
+
rspec-core (3.13.0)
|
66
|
+
rspec-support (~> 3.13.0)
|
67
|
+
rspec-expectations (3.13.0)
|
79
68
|
diff-lcs (>= 1.2.0, < 2.0)
|
80
|
-
rspec-support (~> 3.
|
81
|
-
rspec-mocks (3.
|
69
|
+
rspec-support (~> 3.13.0)
|
70
|
+
rspec-mocks (3.13.0)
|
82
71
|
diff-lcs (>= 1.2.0, < 2.0)
|
83
|
-
rspec-support (~> 3.
|
84
|
-
rspec-support (3.
|
85
|
-
rubocop (1.
|
86
|
-
base64 (~> 0.1.1)
|
72
|
+
rspec-support (~> 3.13.0)
|
73
|
+
rspec-support (3.13.1)
|
74
|
+
rubocop (1.62.1)
|
87
75
|
json (~> 2.3)
|
88
76
|
language_server-protocol (>= 3.17.0)
|
89
77
|
parallel (~> 1.10)
|
90
|
-
parser (>= 3.
|
78
|
+
parser (>= 3.3.0.2)
|
91
79
|
rainbow (>= 2.2.2, < 4.0)
|
92
80
|
regexp_parser (>= 1.8, < 3.0)
|
93
81
|
rexml (>= 3.2.5, < 4.0)
|
94
|
-
rubocop-ast (>= 1.
|
82
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
95
83
|
ruby-progressbar (~> 1.7)
|
96
84
|
unicode-display_width (>= 2.4.0, < 3.0)
|
97
|
-
rubocop-ast (1.
|
98
|
-
parser (>= 3.
|
99
|
-
rubocop-capybara (2.
|
85
|
+
rubocop-ast (1.31.2)
|
86
|
+
parser (>= 3.3.0.4)
|
87
|
+
rubocop-capybara (2.20.0)
|
100
88
|
rubocop (~> 1.41)
|
101
|
-
rubocop-factory_bot (2.
|
102
|
-
rubocop (~> 1.
|
103
|
-
rubocop-rails (2.
|
89
|
+
rubocop-factory_bot (2.25.1)
|
90
|
+
rubocop (~> 1.41)
|
91
|
+
rubocop-rails (2.24.1)
|
104
92
|
activesupport (>= 4.2.0)
|
105
93
|
rack (>= 1.1)
|
106
94
|
rubocop (>= 1.33.0, < 2.0)
|
107
|
-
|
108
|
-
|
95
|
+
rubocop-ast (>= 1.31.1, < 2.0)
|
96
|
+
rubocop-rspec (2.28.0)
|
97
|
+
rubocop (~> 1.40)
|
109
98
|
rubocop-capybara (~> 2.17)
|
110
99
|
rubocop-factory_bot (~> 2.22)
|
100
|
+
rubocop-rspec_rails (~> 2.28)
|
101
|
+
rubocop-rspec_rails (2.28.2)
|
102
|
+
rubocop (~> 1.40)
|
111
103
|
ruby-progressbar (1.13.0)
|
112
|
-
ruby2_keywords (0.0.5)
|
113
104
|
timecop (0.9.8)
|
114
105
|
tzinfo (2.0.6)
|
115
106
|
concurrent-ruby (~> 1.0)
|
116
|
-
unicode-display_width (2.
|
117
|
-
|
107
|
+
unicode-display_width (2.5.0)
|
108
|
+
uri (0.13.0)
|
109
|
+
webmock (3.23.0)
|
118
110
|
addressable (>= 2.8.0)
|
119
111
|
crack (>= 0.3.2)
|
120
112
|
hashdiff (>= 0.4.0, < 2.0.0)
|
121
113
|
|
122
114
|
PLATFORMS
|
123
115
|
arm64-darwin-22
|
116
|
+
arm64-darwin-23
|
124
117
|
x86_64-linux
|
125
118
|
|
126
119
|
DEPENDENCIES
|
@@ -135,4 +128,4 @@ DEPENDENCIES
|
|
135
128
|
webmock (~> 3.18)
|
136
129
|
|
137
130
|
BUNDLED WITH
|
138
|
-
2.4.
|
131
|
+
2.4.6
|
data/bin/release
CHANGED
@@ -7,7 +7,7 @@ set -vx
|
|
7
7
|
version="$1"
|
8
8
|
|
9
9
|
# Do a pretend version bump to determine what the new version should be
|
10
|
-
bumped_version=$(gem bump "$version" --pretend --no-commit | awk '{ print $4 }' | tr -d '[:space:]')
|
10
|
+
bumped_version=$(gem bump --version "$version" --pretend --no-commit | awk '{ print $4 }' | tr -d '[:space:]')
|
11
11
|
|
12
12
|
# Use ruby to get the root level directory name
|
13
13
|
gem_name=$(ruby -e "puts File.basename(Dir.pwd)")
|
data/easee.gemspec
CHANGED
@@ -28,7 +28,6 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.add_runtime_dependency "activemodel"
|
29
29
|
spec.add_runtime_dependency "activesupport"
|
30
30
|
spec.add_runtime_dependency "faraday"
|
31
|
-
spec.add_runtime_dependency "faraday_middleware"
|
32
31
|
|
33
32
|
spec.metadata["rubygems_mfa_required"] = "true"
|
34
33
|
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
module Easee
|
2
|
+
class AmazonGwMiddleware < Faraday::Middleware
|
3
|
+
def on_complete(env)
|
4
|
+
return unless env.response_headers["X-Amzn-Errortype"] == "ForbiddenException"
|
5
|
+
|
6
|
+
response_values = Faraday::Response::RaiseError.new.response_values(env)
|
7
|
+
raise(Faraday::ForbiddenError, response_values)
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
data/lib/easee/client.rb
CHANGED
@@ -20,6 +20,13 @@ module Easee
|
|
20
20
|
@encryptor = encryptor
|
21
21
|
end
|
22
22
|
|
23
|
+
# https://developer.easee.cloud/reference/post_api-accounts-login
|
24
|
+
def login
|
25
|
+
with_error_handling do
|
26
|
+
request_access_token
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
23
30
|
# https://developer.easee.cloud/reference/post_api-chargers-id-unpair
|
24
31
|
def unpair(charger_id:, pin_code:)
|
25
32
|
post("/api/chargers/#{charger_id}/unpair", query: { pinCode: pin_code })
|
@@ -53,6 +60,11 @@ module Easee
|
|
53
60
|
post("/api/chargers/#{charger_id}/commands/resume_charging")
|
54
61
|
end
|
55
62
|
|
63
|
+
# https://developer.easee.com/reference/post_api-chargers-chargerid-commands-poll-lifetimeenergy
|
64
|
+
def poll_lifetime_energy(charger_id)
|
65
|
+
post("/api/chargers/#{charger_id}/commands/poll_lifetimeenergy")
|
66
|
+
end
|
67
|
+
|
56
68
|
# https://developer.easee.cloud/reference/get_api-chargers-id-config
|
57
69
|
def configuration(charger_id)
|
58
70
|
get("/api/chargers/#{charger_id}/config")
|
@@ -79,13 +91,14 @@ module Easee
|
|
79
91
|
Faraday.new(url: BASE_URL) do |conn|
|
80
92
|
conn.request :json
|
81
93
|
conn.response :raise_error
|
94
|
+
conn.use AmazonGwMiddleware
|
95
|
+
conn.response :json, content_type: /\bjson$/
|
82
96
|
end
|
83
97
|
end
|
84
98
|
|
85
99
|
def authenticated_connection
|
86
100
|
connection.tap do |conn|
|
87
101
|
conn.request :authorization, "Bearer", access_token
|
88
|
-
conn.response :json, content_type: /\bjson$/
|
89
102
|
end
|
90
103
|
end
|
91
104
|
|
@@ -116,17 +129,21 @@ module Easee
|
|
116
129
|
|
117
130
|
retry
|
118
131
|
end
|
132
|
+
rescue Faraday::TooManyRequestsError => e
|
133
|
+
raise Errors::RateLimitExceeded.new("Rate limit exceeded", e.response)
|
134
|
+
rescue Faraday::ForbiddenError => e
|
135
|
+
raise Errors::Forbidden, "Access denied to charger"
|
119
136
|
rescue Faraday::Error => e
|
120
|
-
if e.response_status ==
|
121
|
-
raise Errors::
|
122
|
-
else
|
123
|
-
raise Errors::RequestFailed.new("Request returned status #{e.response_status}", e.response)
|
137
|
+
if e.response_status == 400 && [100, 727].include?(e.response.dig(:body, "errorCode"))
|
138
|
+
raise Errors::InvalidCredentials, "Invalid username or password"
|
124
139
|
end
|
140
|
+
|
141
|
+
raise Errors::RequestFailed.new("Request returned status #{e.response_status}", e.response)
|
125
142
|
end
|
126
143
|
|
127
144
|
def access_token
|
128
145
|
encrypted_tokens = @token_cache.fetch(TOKENS_CACHE_KEY) do
|
129
|
-
@encryptor.encrypt(request_access_token, cipher_options: { deterministic: true })
|
146
|
+
@encryptor.encrypt(request_access_token.to_json, cipher_options: { deterministic: true })
|
130
147
|
end
|
131
148
|
|
132
149
|
plain_text_tokens = @encryptor.decrypt(encrypted_tokens)
|
@@ -137,7 +154,7 @@ module Easee
|
|
137
154
|
def refresh_access_token!
|
138
155
|
@token_cache.write(
|
139
156
|
TOKENS_CACHE_KEY,
|
140
|
-
@encryptor.encrypt(refresh_access_token, cipher_options: { deterministic: true }),
|
157
|
+
@encryptor.encrypt(refresh_access_token.to_json, cipher_options: { deterministic: true }),
|
141
158
|
expires_in: 1.day,
|
142
159
|
)
|
143
160
|
rescue Faraday::Error => e
|
data/lib/easee/errors.rb
CHANGED
@@ -4,6 +4,8 @@ module Easee
|
|
4
4
|
def retryable? = false
|
5
5
|
end
|
6
6
|
|
7
|
+
class InvalidCredentials < Base; end
|
8
|
+
|
7
9
|
class RequestFailed < Base
|
8
10
|
attr_reader :response
|
9
11
|
|
@@ -13,6 +15,8 @@ module Easee
|
|
13
15
|
end
|
14
16
|
end
|
15
17
|
|
18
|
+
class Forbidden < Base; end
|
19
|
+
|
16
20
|
class RateLimitExceeded < RequestFailed
|
17
21
|
def retryable? = true
|
18
22
|
end
|
data/lib/easee/version.rb
CHANGED
data/lib/stekker_easee.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
require "faraday"
|
2
|
-
require "active_support/
|
2
|
+
require "active_support/deprecation"
|
3
|
+
require "active_support/deprecator"
|
4
|
+
require "active_support/core_ext/numeric/time"
|
3
5
|
require "active_support/isolated_execution_state"
|
4
6
|
require "active_support/core_ext/hash"
|
5
7
|
|
@@ -11,6 +13,7 @@ require_relative "easee/meter_reading"
|
|
11
13
|
require_relative "easee/site"
|
12
14
|
require_relative "easee/state"
|
13
15
|
require_relative "easee/charger"
|
16
|
+
require_relative "easee/amazon_gw_middleware"
|
14
17
|
|
15
18
|
module Easee
|
16
19
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: stekker_easee
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Team Stekker
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -52,20 +52,6 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: faraday_middleware
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :runtime
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
55
|
description: Easee connector
|
70
56
|
email:
|
71
57
|
- support@stekker.com
|
@@ -86,6 +72,7 @@ files:
|
|
86
72
|
- bin/release
|
87
73
|
- bin/setup
|
88
74
|
- easee.gemspec
|
75
|
+
- lib/easee/amazon_gw_middleware.rb
|
89
76
|
- lib/easee/charger.rb
|
90
77
|
- lib/easee/client.rb
|
91
78
|
- lib/easee/configuration.rb
|
@@ -118,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
105
|
- !ruby/object:Gem::Version
|
119
106
|
version: '0'
|
120
107
|
requirements: []
|
121
|
-
rubygems_version: 3.4.
|
108
|
+
rubygems_version: 3.4.6
|
122
109
|
signing_key:
|
123
110
|
specification_version: 4
|
124
111
|
summary: Connect to your Easee charger
|