sma_api 0.2.0 → 0.2.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: 7e76c957bc8c28c065e5d09ae6af7f19da1fdfbf37750a4717142caf0995cb00
4
- data.tar.gz: 7eb2af1e6cb5e5c5cafb1347a48e062db2031bee1f627fbefa77a538afa6b857
3
+ metadata.gz: 0dc92d3abe35f2de18b03c9bc2e09c38b0e4807ae1f03182929b4cbf8dc89c4a
4
+ data.tar.gz: e03b4fdf64401d7ac504fb313487588643f36824a34ff24ae33295c3cec7cc4b
5
5
  SHA512:
6
- metadata.gz: 9615bf3a31e8010b649dafc7da9ecf63aaeef714b6aae91155c7a2fd8da20fdf3be3069b04f61c6cce5d0e092f0282940322cc793359fefedf611bdf8272807f
7
- data.tar.gz: b45b79f2e061d98c85ecbaa1b3904f968db56664b38558a051dce4b00e44bcaadb75c818784afe45d8e2ac6ff9759a2059bf433641d9509e87e6381201a1b72b
6
+ metadata.gz: 0c914d046551021c6e8c98890a600b94bbf7452778d9e5f3ee6ce5c06b8d287b55d58ecc5a16a908c4180ce0c567fbb50c55b06bccf17497d0fea1db03c6c5b4
7
+ data.tar.gz: 772823374578e87813516d2a16f2988e106b68dba1bd5a9e7b6391cca0ece4538588e39ac28b670ca5f1b13d3e9264e056c0fba59701c283c23b8146da85a08f
data/README.md CHANGED
@@ -2,12 +2,12 @@
2
2
 
3
3
  This gem provides an API for the web interface of SMA inverters.
4
4
 
5
- The gem is in early development and should not be considered stable. Everything might change.
5
+ The gem is not under active development but I will maintain it.
6
6
 
7
7
  ## Supported inverters
8
8
 
9
- This gem has been developed using a SMA Sunny Boy 3.0 (SB3.0-1AV-41 902).
10
- Firmware version is 3.10.18.R
9
+ This gem has been developed using a SMA Sunny Boy 3.0 (SB3.0-1AV-41).
10
+ Firmware version is 4.0.55.R
11
11
 
12
12
  It will probably work with other SMA products that have a recent firmware. But
13
13
  it has not been tested.
@@ -34,11 +34,11 @@ The web interface of the inverter does not allow an unlimited number of sessions
34
34
  There seems to be a limit of 4 sessions. Another attempt to login will result into
35
35
  an error message from the web interface, which is turned into a `SmaApi::Error`
36
36
  that has the `Creating session failed` message. The software in the inverter will
37
- free up a session after a 5 minute inactivity.
37
+ free up a session after 5 minutes of inactivity.
38
38
 
39
39
  There are different ways of handling the session:
40
40
  - Create the `SmaApi::Client` instance just once and use it multiple times
41
- - Store the session id in a cache (file, Redis or another solution)
41
+ - Create the `SmaApi::Client` instance using the session id from a cache (Redis, a file)
42
42
  - Use `client.destroy_session` to explicitly remove the session
43
43
 
44
44
  ### Create client once
@@ -55,7 +55,7 @@ while true do
55
55
  end
56
56
  ```
57
57
 
58
- ### Cache the session id
58
+ ### Use the session id when creating the client
59
59
 
60
60
  In case the `sid` is not valid anymore, the client will try to create a new session.
61
61
 
@@ -74,7 +74,7 @@ while true do
74
74
 
75
75
  # If sid has been changed, save it to the sid file
76
76
  if client.sid != sid
77
- File.open(sid_file, 'w') { |f| f.puts sid }
77
+ File.open(sid_file, 'w') { |f| f.puts client.sid }
78
78
  end
79
79
 
80
80
  puts "#{Time.now}\tCurrent yield: #{current_yield}"
@@ -32,7 +32,7 @@ module SmaApi
32
32
  return nil unless result['result']
33
33
 
34
34
  keys.each_with_object({}) do |k, h|
35
- h[k] = scalar_value(result['result'].first[1][k])
35
+ h[k] = get_value(k, result)
36
36
  end
37
37
  end
38
38
 
@@ -70,6 +70,19 @@ module SmaApi
70
70
 
71
71
  private
72
72
 
73
+ def get_value(requested_key, result)
74
+ split_by_underscore = requested_key.split('_')
75
+ if split_by_underscore.size == 3
76
+ array_value(result, split_by_underscore[0..1].join('_'), split_by_underscore[2].to_i)
77
+ else
78
+ scalar_value(result['result'].first[1][requested_key])
79
+ end
80
+ end
81
+
82
+ def array_value(result, result_key, position)
83
+ result['result'].first[1][result_key]['1'][position]['val']
84
+ end
85
+
73
86
  def scalar_value(value)
74
87
  value['1'].first['val']
75
88
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SmaApi
4
- VERSION = '0.2.0'
4
+ VERSION = '0.2.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sma_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rutger Wessels
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-06-22 00:00:00.000000000 Z
11
+ date: 2024-05-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler