sma_api 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +7 -7
- data/lib/sma_api/client.rb +14 -1
- data/lib/sma_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0dc92d3abe35f2de18b03c9bc2e09c38b0e4807ae1f03182929b4cbf8dc89c4a
|
4
|
+
data.tar.gz: e03b4fdf64401d7ac504fb313487588643f36824a34ff24ae33295c3cec7cc4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
10
|
-
Firmware version is
|
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
|
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
|
-
-
|
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
|
-
###
|
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}"
|
data/lib/sma_api/client.rb
CHANGED
@@ -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] =
|
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
|
data/lib/sma_api/version.rb
CHANGED
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.
|
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:
|
11
|
+
date: 2024-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|