stekker_easee 0.1.0 → 1.0.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
  SHA256:
3
- metadata.gz: b5592a4edc9d574ac3d942adea5527716bb97f15090f33e6829a2e002f5fee5c
4
- data.tar.gz: 9e26e2712745636dac113c1abc3282ea705a60f9598998e3d829dfd10222110a
3
+ metadata.gz: f1cb2855dca8dd2bd2bc7670e2da0db9b31c083e6dd35a80c0eacb78031d173f
4
+ data.tar.gz: 3aabf9fe36a3eb46f2af3062d1daca8db14946e39f6a69002472e0d9a185117d
5
5
  SHA512:
6
- metadata.gz: 836a495d985e421acf2508c2618de4034fb3bae460d1184eb40a09f2127875f6654bfd8a49c7986b7962623ec360addf5fd872d8b6ce54b525fd0f2683bfbe8c
7
- data.tar.gz: '06358a19035ef71ea2d7d6a7a071a832b888963feb26a81b8802b595c4ad630afa3947cbdabbbdeab5bfc4d39827d800a7d1db4b680adcefe3caa5e023422bfb'
6
+ metadata.gz: b19294d36bbea358b1f67a97b0fd3a726c6d6b113596ce631adf8585b9731dc6af0e258597fe92414ecea34736b6cfd1232253d1b1b4925786e83e94e03b8759
7
+ data.tar.gz: 1c0d69be491fd212755acaea9fd1b0e7f24801cabe177e7c4aaa419088632d51c9be26b7b4e7db312ffd1394c71051abfeb263bbd0e344f0d83d84887357b38a
@@ -15,7 +15,7 @@ jobs:
15
15
  uses: actions/checkout@v3
16
16
 
17
17
  - name: Install Ruby and gems
18
- uses: ruby/setup-ruby@ee2113536afb7f793eed4ce60e8d3b26db912da4
18
+ uses: ruby/setup-ruby@v1
19
19
  with:
20
20
  bundler-cache: true
21
21
 
data/.rubocop.yml CHANGED
@@ -1 +1,344 @@
1
- inherit_from: ../../.rubocop.yml
1
+ require:
2
+ - rubocop-rspec
3
+
4
+ AllCops:
5
+ NewCops: enable
6
+
7
+ Layout/BeginEndAlignment:
8
+ Enabled: true
9
+
10
+ Layout/BlockAlignment:
11
+ Enabled: true
12
+ EnforcedStyleAlignWith: start_of_block
13
+
14
+ Layout/EmptyLineBetweenDefs:
15
+ Enabled: false
16
+
17
+ Layout/EmptyLinesAroundAttributeAccessor:
18
+ Enabled: true
19
+
20
+ Layout/FirstArgumentIndentation:
21
+ Enabled: true
22
+ EnforcedStyle: consistent
23
+
24
+ Layout/FirstArrayElementIndentation:
25
+ Enabled: true
26
+ EnforcedStyle: consistent
27
+
28
+ Layout/FirstArrayElementLineBreak:
29
+ Enabled: true
30
+
31
+ Layout/FirstHashElementIndentation:
32
+ Enabled: true
33
+ EnforcedStyle: consistent
34
+
35
+ Layout/FirstHashElementLineBreak:
36
+ Enabled: true
37
+
38
+ Layout/FirstMethodArgumentLineBreak:
39
+ Enabled: true
40
+
41
+ Layout/FirstParameterIndentation:
42
+ Enabled: true
43
+ EnforcedStyle: consistent
44
+
45
+ Layout/LineLength:
46
+ Enabled: true
47
+ Max: 115
48
+
49
+ Layout/MultilineArrayBraceLayout:
50
+ Enabled: true
51
+ EnforcedStyle: new_line
52
+
53
+ Layout/MultilineArrayLineBreaks:
54
+ Enabled: true
55
+
56
+ Layout/MultilineHashBraceLayout:
57
+ Enabled: true
58
+ EnforcedStyle: new_line
59
+
60
+ Layout/MultilineHashKeyLineBreaks:
61
+ Enabled: true
62
+
63
+ Layout/MultilineMethodArgumentLineBreaks:
64
+ Enabled: true
65
+
66
+ Layout/MultilineMethodCallBraceLayout:
67
+ Enabled: true
68
+ EnforcedStyle: new_line
69
+
70
+ Layout/MultilineMethodCallIndentation:
71
+ Enabled: true
72
+ EnforcedStyle: indented
73
+
74
+ Layout/SpaceAroundMethodCallOperator:
75
+ Enabled: true
76
+
77
+ Layout/TrailingWhitespace:
78
+ AllowInHeredoc: true
79
+ Enabled: true
80
+
81
+ Lint/AmbiguousBlockAssociation:
82
+ Exclude:
83
+ - spec/**/*
84
+
85
+ Lint/BinaryOperatorWithIdenticalOperands:
86
+ Enabled: true
87
+
88
+ Lint/ConstantDefinitionInBlock:
89
+ Enabled: true
90
+
91
+ Lint/DeprecatedOpenSSLConstant:
92
+ Enabled: true
93
+
94
+ Lint/DuplicateBranch:
95
+ Enabled: false
96
+
97
+ Lint/DuplicateElsifCondition:
98
+ Enabled: true
99
+
100
+ Lint/DuplicateRequire:
101
+ Enabled: true
102
+
103
+ Lint/DuplicateRescueException:
104
+ Enabled: true
105
+
106
+ Lint/EmptyConditionalBody:
107
+ Enabled: true
108
+
109
+ Lint/EmptyFile:
110
+ Enabled: true
111
+
112
+ Lint/FloatComparison:
113
+ Enabled: true
114
+
115
+ Lint/IdentityComparison:
116
+ Enabled: true
117
+
118
+ Lint/MissingSuper:
119
+ Enabled: true
120
+
121
+ Lint/MixedRegexpCaptureTypes:
122
+ Enabled: true
123
+
124
+ Lint/OutOfRangeRegexpRef:
125
+ Enabled: true
126
+
127
+ Lint/RaiseException:
128
+ Enabled: true
129
+
130
+ Lint/SelfAssignment:
131
+ Enabled: true
132
+
133
+ Lint/StructNewOverride:
134
+ Enabled: true
135
+
136
+ Lint/TopLevelReturnWithArgument:
137
+ Enabled: true
138
+
139
+ Lint/TrailingCommaInAttributeDeclaration:
140
+ Enabled: true
141
+
142
+ Lint/UnreachableLoop:
143
+ Enabled: true
144
+
145
+ Lint/UselessAssignment:
146
+ Enabled: true
147
+
148
+ Lint/UselessMethodDefinition:
149
+ Enabled: true
150
+
151
+ Lint/UselessTimes:
152
+ Enabled: true
153
+
154
+ Metrics/AbcSize:
155
+ Enabled: false
156
+
157
+ Metrics/BlockLength:
158
+ Enabled: true
159
+
160
+ Metrics/ClassLength:
161
+ Enabled: false
162
+
163
+ Metrics/CyclomaticComplexity:
164
+ Max: 42
165
+
166
+ Metrics/MethodLength:
167
+ Max: 42
168
+
169
+ Metrics/ModuleLength:
170
+ Enabled: false
171
+
172
+ Metrics/ParameterLists:
173
+ CountKeywordArgs: false
174
+ Enabled: true
175
+
176
+ Metrics/PerceivedComplexity:
177
+ Max: 42
178
+
179
+ Naming/PredicateName:
180
+ Enabled: true
181
+ ForbiddenPrefixes: is_
182
+
183
+ Naming/VariableNumber:
184
+ Enabled: true
185
+
186
+ RSpec/AnyInstance:
187
+ Enabled: false
188
+
189
+ RSpec/DescribeClass:
190
+ Enabled: false
191
+
192
+ RSpec/DescribedClass:
193
+ Enabled: false
194
+
195
+ RSpec/ExampleLength:
196
+ Enabled: false
197
+
198
+ RSpec/MultipleExpectations:
199
+ Enabled: false
200
+
201
+ RSpec/NestedGroups:
202
+ Max: 4
203
+
204
+ RSpec/NoExpectationExample:
205
+ Exclude:
206
+ - spec/domain/**/*
207
+
208
+ RSpec/VerifiedDoubles:
209
+ Enabled: true
210
+
211
+ Style/AccessorGrouping:
212
+ Enabled: true
213
+
214
+ Style/ArrayCoercion:
215
+ Enabled: true
216
+
217
+ Style/AsciiComments:
218
+ Enabled: false
219
+
220
+ Style/BisectedAttrAccessor:
221
+ Enabled: true
222
+
223
+ Style/BlockDelimiters:
224
+ Enabled: true
225
+
226
+ Style/CaseLikeIf:
227
+ Enabled: true
228
+
229
+ Style/ClassAndModuleChildren:
230
+ Enabled: false
231
+
232
+ Style/CombinableLoops:
233
+ Enabled: true
234
+
235
+ Style/Documentation:
236
+ Enabled: false
237
+
238
+ Style/EmptyMethod:
239
+ EnforcedStyle: expanded
240
+
241
+ Style/ExplicitBlockArgument:
242
+ Enabled: true
243
+
244
+ Style/ExponentialNotation:
245
+ Enabled: true
246
+
247
+ Style/FrozenStringLiteralComment:
248
+ EnforcedStyle: never
249
+
250
+ Style/GlobalStdStream:
251
+ Enabled: true
252
+
253
+ Style/GuardClause:
254
+ Enabled: false
255
+
256
+ Style/HashAsLastArrayItem:
257
+ Enabled: true
258
+
259
+ Style/HashEachMethods:
260
+ Enabled: true
261
+
262
+ Style/HashLikeCase:
263
+ Enabled: true
264
+
265
+ Style/HashTransformKeys:
266
+ Enabled: true
267
+
268
+ Style/HashTransformValues:
269
+ Enabled: true
270
+
271
+ Style/IfInsideElse:
272
+ Enabled: false
273
+
274
+ Style/IfUnlessModifier:
275
+ Enabled: false
276
+
277
+ Style/KeywordParametersOrder:
278
+ Enabled: true
279
+
280
+ Style/Lambda:
281
+ EnforcedStyle: literal
282
+
283
+ Style/MultilineBlockChain:
284
+ Enabled: false
285
+
286
+ Style/NumericLiterals:
287
+ Enabled: false
288
+
289
+ Style/OptionalBooleanParameter:
290
+ Enabled: true
291
+
292
+ Style/RedundantAssignment:
293
+ Enabled: true
294
+
295
+ Style/RedundantFetchBlock:
296
+ Enabled: true
297
+
298
+ Style/RedundantFileExtensionInRequire:
299
+ Enabled: true
300
+
301
+ Style/RedundantRegexpCharacterClass:
302
+ Enabled: true
303
+
304
+ Style/RedundantRegexpEscape:
305
+ Enabled: true
306
+
307
+ Style/RedundantSelfAssignment:
308
+ Enabled: true
309
+
310
+ Style/RescueModifier:
311
+ Enabled: false
312
+
313
+ Style/SingleArgumentDig:
314
+ Enabled: true
315
+
316
+ Style/SlicingWithRange:
317
+ Enabled: true
318
+
319
+ Style/SoleNestedConditional:
320
+ Enabled: true
321
+
322
+ Style/StringConcatenation:
323
+ Enabled: true
324
+
325
+ Style/StringLiterals:
326
+ EnforcedStyle: double_quotes
327
+
328
+ Style/StringLiteralsInInterpolation:
329
+ EnforcedStyle: double_quotes
330
+
331
+ Style/SymbolArray:
332
+ EnforcedStyle: brackets
333
+
334
+ Style/TrailingCommaInArguments:
335
+ Enabled: true
336
+ EnforcedStyleForMultiline: comma
337
+
338
+ Style/TrailingCommaInArrayLiteral:
339
+ Enabled: true
340
+ EnforcedStyleForMultiline: comma
341
+
342
+ Style/TrailingCommaInHashLiteral:
343
+ Enabled: true
344
+ EnforcedStyleForMultiline: comma
data/Gemfile CHANGED
@@ -3,6 +3,7 @@ source "https://rubygems.org"
3
3
  # Specify your gem's dependencies in easee.gemspec
4
4
  gemspec
5
5
 
6
+ gem "gem-release", "~> 2.2"
6
7
  gem "rake", "~> 13.0"
7
8
  gem "rspec", "~> 3.0"
8
9
  gem "rubocop", "~> 1.7"
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- stekker_easee (0.1.0)
4
+ stekker_easee (1.0.1)
5
5
  activemodel
6
6
  activesupport
7
7
  faraday
@@ -10,16 +10,17 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activemodel (7.0.4.3)
14
- activesupport (= 7.0.4.3)
15
- activesupport (7.0.4.3)
13
+ activemodel (7.0.8)
14
+ activesupport (= 7.0.8)
15
+ activesupport (7.0.8)
16
16
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
17
  i18n (>= 1.6, < 2)
18
18
  minitest (>= 5.1)
19
19
  tzinfo (~> 2.0)
20
- addressable (2.8.1)
20
+ addressable (2.8.5)
21
21
  public_suffix (>= 2.0.2, < 6.0)
22
22
  ast (2.4.2)
23
+ base64 (0.1.1)
23
24
  concurrent-ruby (1.2.2)
24
25
  crack (0.4.5)
25
26
  rexml
@@ -49,70 +50,81 @@ GEM
49
50
  faraday-retry (1.0.3)
50
51
  faraday_middleware (1.2.0)
51
52
  faraday (~> 1.0)
53
+ gem-release (2.2.2)
52
54
  hashdiff (1.0.1)
53
- i18n (1.12.0)
55
+ i18n (1.14.1)
54
56
  concurrent-ruby (~> 1.0)
55
57
  json (2.6.3)
56
- minitest (5.18.0)
58
+ language_server-protocol (3.17.0.3)
59
+ minitest (5.20.0)
57
60
  multipart-post (2.3.0)
58
- parallel (1.22.1)
59
- parser (3.2.1.1)
61
+ parallel (1.23.0)
62
+ parser (3.2.2.3)
60
63
  ast (~> 2.4.1)
61
- public_suffix (5.0.1)
62
- rack (3.0.7)
64
+ racc
65
+ public_suffix (5.0.3)
66
+ racc (1.7.1)
67
+ rack (3.0.8)
63
68
  rainbow (3.1.1)
64
69
  rake (13.0.6)
65
- regexp_parser (2.7.0)
66
- rexml (3.2.5)
70
+ regexp_parser (2.8.1)
71
+ rexml (3.2.6)
67
72
  rspec (3.12.0)
68
73
  rspec-core (~> 3.12.0)
69
74
  rspec-expectations (~> 3.12.0)
70
75
  rspec-mocks (~> 3.12.0)
71
- rspec-core (3.12.1)
76
+ rspec-core (3.12.2)
72
77
  rspec-support (~> 3.12.0)
73
- rspec-expectations (3.12.2)
78
+ rspec-expectations (3.12.3)
74
79
  diff-lcs (>= 1.2.0, < 2.0)
75
80
  rspec-support (~> 3.12.0)
76
- rspec-mocks (3.12.4)
81
+ rspec-mocks (3.12.6)
77
82
  diff-lcs (>= 1.2.0, < 2.0)
78
83
  rspec-support (~> 3.12.0)
79
- rspec-support (3.12.0)
80
- rubocop (1.48.1)
84
+ rspec-support (3.12.1)
85
+ rubocop (1.56.3)
86
+ base64 (~> 0.1.1)
81
87
  json (~> 2.3)
88
+ language_server-protocol (>= 3.17.0)
82
89
  parallel (~> 1.10)
83
- parser (>= 3.2.0.0)
90
+ parser (>= 3.2.2.3)
84
91
  rainbow (>= 2.2.2, < 4.0)
85
92
  regexp_parser (>= 1.8, < 3.0)
86
93
  rexml (>= 3.2.5, < 4.0)
87
- rubocop-ast (>= 1.26.0, < 2.0)
94
+ rubocop-ast (>= 1.28.1, < 2.0)
88
95
  ruby-progressbar (~> 1.7)
89
96
  unicode-display_width (>= 2.4.0, < 3.0)
90
- rubocop-ast (1.28.0)
97
+ rubocop-ast (1.29.0)
91
98
  parser (>= 3.2.1.0)
92
- rubocop-capybara (2.17.1)
99
+ rubocop-capybara (2.18.0)
93
100
  rubocop (~> 1.41)
94
- rubocop-rails (2.18.0)
101
+ rubocop-factory_bot (2.23.1)
102
+ rubocop (~> 1.33)
103
+ rubocop-rails (2.21.0)
95
104
  activesupport (>= 4.2.0)
96
105
  rack (>= 1.1)
97
106
  rubocop (>= 1.33.0, < 2.0)
98
- rubocop-rspec (2.19.0)
107
+ rubocop-rspec (2.24.0)
99
108
  rubocop (~> 1.33)
100
109
  rubocop-capybara (~> 2.17)
110
+ rubocop-factory_bot (~> 2.22)
101
111
  ruby-progressbar (1.13.0)
102
112
  ruby2_keywords (0.0.5)
103
- timecop (0.9.6)
113
+ timecop (0.9.8)
104
114
  tzinfo (2.0.6)
105
115
  concurrent-ruby (~> 1.0)
106
116
  unicode-display_width (2.4.2)
107
- webmock (3.18.1)
117
+ webmock (3.19.1)
108
118
  addressable (>= 2.8.0)
109
119
  crack (>= 0.3.2)
110
120
  hashdiff (>= 0.4.0, < 2.0.0)
111
121
 
112
122
  PLATFORMS
113
123
  arm64-darwin-22
124
+ x86_64-linux
114
125
 
115
126
  DEPENDENCIES
127
+ gem-release (~> 2.2)
116
128
  rake (~> 13.0)
117
129
  rspec (~> 3.0)
118
130
  rubocop (~> 1.7)
data/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # Connect to the Easee API
2
+
3
+ ## How to use this without any technical knowledge
4
+
5
+ With this gem, you can connect to Easee chargers to smart charge your vehicle.
6
+
7
+ However, for an even more seamless experience, we recommend using
8
+ the [Stekker app](https://stekker.com/?utm_source=github&utm_medium=referral&utm_campaign=opensource). Our mobile app is
9
+ designed to make smart charging effortless, eliminating the need for any configuration. Simply install the app, and it
10
+ will handle the rest. Our app uses advanced algorithms to determine the best times to charge your vehicle, ensuring
11
+ you'll use the most sustainable and cheapest energy available.
12
+
13
+ ## Build your own with this gem
14
+
15
+ We are proud to introduce this open source project, the Easee charger Ruby gem. As passionate ruby developers, we
16
+ believe in giving back to the community and contributing to the growth of this amazing language. That's why we are
17
+ making our Easee connection accessible to everyone through open source. Our goal is to make smart charging easier and
18
+ more accessible, and we hope that by opening up our project, we can help others in the community achieve their own
19
+ goals.
20
+
21
+ ## Installation
22
+
23
+ Add this line to your application's Gemfile:
24
+
25
+ ```ruby
26
+ gem "stekker_easee"
27
+ ```
28
+
29
+ And then execute:
30
+
31
+ $ bundle install
32
+
33
+ Or install it yourself as:
34
+
35
+ $ gem install stekker_easee
36
+
37
+ ## Usage
38
+
39
+ You can use this without Rails in the following way:
40
+
41
+ ```
42
+ $ bin/console
43
+ ```
44
+
45
+ ```ruby
46
+ client = Easee::Client.new(username: "username@example.com", password: "password")
47
+ # => #<Easee::Client @user_name="[FILTERED]", @password="[FILTERED]", @token_cache=#<ActiveSupport::Cache::MemoryStore entries=0, ...
48
+
49
+ # This is the charger's serial number
50
+ charger_id = "ABCDEFGH"
51
+
52
+ # Get the state of a charger
53
+ client.state(charger_id).charging?
54
+ # => false
55
+ ```
56
+
57
+ ## Contributing
58
+
59
+ Bug reports and pull requests are welcome on GitHub at https://github.com/stekker/easee.
60
+
61
+ ## Publishing
62
+
63
+ ```bash
64
+ # - bumps the gem version to the next major, minor or patch version.
65
+ # - creates commit for the version bump
66
+ # - tags the commit
67
+ # - pushes the commit and tag
68
+ # - publishes the gem to Rubygems
69
+ bin/release [major|minor|patch]
70
+ # See also https://github.com/svenfuchs/gem-release#gem-bump
71
+ ```
data/bin/release ADDED
@@ -0,0 +1,28 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ # Read major/minor/patch argument
7
+ version="$1"
8
+
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:]')
11
+
12
+ # Use ruby to get the root level directory name
13
+ gem_name=$(ruby -e "puts File.basename(Dir.pwd)")
14
+
15
+ # Update version file
16
+ gem bump --version "$bumped_version" --no-commit
17
+
18
+ # Run bundle install to ensure gem version in Gemfile is updated
19
+ bundle install
20
+
21
+ # Stage Gemfile.lock and the version file
22
+ git add Gemfile.lock "lib/$gem_name/version.rb"
23
+
24
+ # Finally create the bump commit
25
+ git commit -m "Bump $gem_name to $bumped_version"
26
+
27
+ # Create a tag, push the commit and tag, and release to Rubygems
28
+ gem bump --version "$bumped_version" --no-commit --tag --push --release
@@ -0,0 +1,12 @@
1
+ module Easee
2
+ class Charger
3
+ def initialize(data)
4
+ @data = data.symbolize_keys
5
+ end
6
+
7
+ def id = @data.fetch(:id)
8
+ def name = @data.fetch(:name)
9
+ def color = @data.fetch(:color)
10
+ def product_code = @data.fetch(:productCode)
11
+ end
12
+ end
data/lib/easee/client.rb CHANGED
@@ -30,6 +30,13 @@ module Easee
30
30
  post("/api/chargers/#{charger_id}/pair", query: { pinCode: pin_code })
31
31
  end
32
32
 
33
+ # https://developer.easee.cloud/reference/get_api-chargers
34
+ def chargers
35
+ get("/api/chargers").then do |response|
36
+ response.body.map { |data| Charger.new(data) }
37
+ end
38
+ end
39
+
33
40
  # https://developer.easee.cloud/reference/get_api-chargers-id-state
34
41
  def state(charger_id)
35
42
  get("/api/chargers/#{charger_id}/state")
@@ -46,11 +53,13 @@ module Easee
46
53
  post("/api/chargers/#{charger_id}/commands/resume_charging")
47
54
  end
48
55
 
56
+ # https://developer.easee.cloud/reference/get_api-chargers-id-config
49
57
  def configuration(charger_id)
50
58
  get("/api/chargers/#{charger_id}/config")
51
59
  .then { |response| Configuration.new(response.body) }
52
60
  end
53
61
 
62
+ # https://developer.easee.cloud/reference/get_api-chargers-id-site
54
63
  def site(charger_id)
55
64
  get("/api/chargers/#{charger_id}/site")
56
65
  .then { |response| Site.new(response.body) }
@@ -108,7 +117,11 @@ module Easee
108
117
  retry
109
118
  end
110
119
  rescue Faraday::Error => e
111
- raise Errors::RequestFailed.new("Request returned status #{e.response_status}", e.response)
120
+ if e.response_status == 429 # HTTP 429 TooManyRequests
121
+ raise Errors::RateLimitExceeded.new("Rate limit exceeded", e.response)
122
+ else
123
+ raise Errors::RequestFailed.new("Request returned status #{e.response_status}", e.response)
124
+ end
112
125
  end
113
126
 
114
127
  def access_token
data/lib/easee/errors.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  module Easee
2
2
  module Errors
3
- class Base < ::StandardError; end
3
+ class Base < ::StandardError
4
+ def retryable? = false
5
+ end
4
6
 
5
7
  class RequestFailed < Base
6
8
  attr_reader :response
@@ -10,5 +12,9 @@ module Easee
10
12
  super(message)
11
13
  end
12
14
  end
15
+
16
+ class RateLimitExceeded < RequestFailed
17
+ def retryable? = true
18
+ end
13
19
  end
14
20
  end
data/lib/easee/site.rb CHANGED
@@ -9,12 +9,14 @@ module Easee
9
9
  def building_number = address.fetch(:buildingNumber)
10
10
  def zip = address.fetch(:zip)
11
11
  def area = address.fetch(:area)
12
- def country_id = address.fetch(:country).fetch(:id)
12
+ def country_id = country[:id]
13
13
  def latitude = address.fetch(:latitude)
14
14
  def longitude = address.fetch(:longitude)
15
15
 
16
16
  private
17
17
 
18
+ def country = address.fetch(:country) || {}
19
+
18
20
  def address
19
21
  @address ||= @data.fetch(:address)
20
22
  end
data/lib/easee/state.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  module Easee
2
2
  class State
3
+ OP_MODE_UNKNOWN = :unknown
4
+
3
5
  CHARGER_OP_MODES = {
4
6
  0 => :offline,
5
7
  1 => :disconnected,
@@ -21,12 +23,15 @@ module Easee
21
23
  def meter_reading
22
24
  MeterReading.new(
23
25
  reading_kwh: @data.fetch(:lifetimeEnergy),
24
- timestamp: Time.current,
26
+ timestamp: Time.zone.parse(@data.fetch(:latestPulse)),
25
27
  )
26
28
  end
27
29
 
28
30
  private
29
31
 
30
- def charger_op_mode = CHARGER_OP_MODES.fetch(@data.fetch(:chargerOpMode))
32
+ def charger_op_mode
33
+ numeric_op_mode = @data.fetch(:chargerOpMode)
34
+ CHARGER_OP_MODES.fetch(numeric_op_mode) { OP_MODE_UNKNOWN }
35
+ end
31
36
  end
32
37
  end
data/lib/easee/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Easee
2
- VERSION = "0.1.0".freeze
2
+ VERSION = "1.0.1".freeze
3
3
  end
data/lib/stekker_easee.rb CHANGED
@@ -10,6 +10,7 @@ require_relative "easee/errors"
10
10
  require_relative "easee/meter_reading"
11
11
  require_relative "easee/site"
12
12
  require_relative "easee/state"
13
+ require_relative "easee/charger"
13
14
 
14
15
  module Easee
15
16
  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: 0.1.0
4
+ version: 1.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Team Stekker
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-04-05 00:00:00.000000000 Z
11
+ date: 2023-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel
@@ -80,10 +80,13 @@ files:
80
80
  - ".ruby-version"
81
81
  - Gemfile
82
82
  - Gemfile.lock
83
+ - README.md
83
84
  - Rakefile
84
85
  - bin/console
86
+ - bin/release
85
87
  - bin/setup
86
88
  - easee.gemspec
89
+ - lib/easee/charger.rb
87
90
  - lib/easee/client.rb
88
91
  - lib/easee/configuration.rb
89
92
  - lib/easee/errors.rb
@@ -115,7 +118,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
115
118
  - !ruby/object:Gem::Version
116
119
  version: '0'
117
120
  requirements: []
118
- rubygems_version: 3.4.6
121
+ rubygems_version: 3.4.18
119
122
  signing_key:
120
123
  specification_version: 4
121
124
  summary: Connect to your Easee charger