sma_api 0.1.3 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 36a9ddcb7964e241dd22e1aedeb60c4d349579c1573f40fd006cad4a25f7531a
4
- data.tar.gz: 9f1d8eff6ce63d13aeb22c5036f8139906fb41f482d4db0b4116ce93f4b509da
3
+ metadata.gz: 0dc92d3abe35f2de18b03c9bc2e09c38b0e4807ae1f03182929b4cbf8dc89c4a
4
+ data.tar.gz: e03b4fdf64401d7ac504fb313487588643f36824a34ff24ae33295c3cec7cc4b
5
5
  SHA512:
6
- metadata.gz: '097ece0e24a75bc31cfaa491d4c7e217ff3d0519d45ef2574183d49ddc60d22873a2fc3773a6f4031f0f17eb13df5cafeb6704c765b4ec94f92bf866db733add'
7
- data.tar.gz: 1b100eb1cd43594b59876e3e724d826ece9715f8b9de67b09530e8ebf88ee645b5b08bbf9e4be7d515fba7642be45955ac853022c0a8ecb4159e4c80b846d074
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}"
@@ -6,7 +6,7 @@ module SmaApi
6
6
  def initialize(host:, password:, sid: nil)
7
7
  @host = host
8
8
  @password = password
9
- @client = Http.new(host: host, password: password, sid: sid)
9
+ @client = Http.new(host:, password:, sid:)
10
10
  end
11
11
 
12
12
  # The current session id. If empty, it will create a new session
@@ -28,11 +28,11 @@ module SmaApi
28
28
  # @param keys [Array<String>] List of keys
29
29
  # @return [Hash] Key-value pairs
30
30
  def get_values(keys)
31
- result = @client.post('/dyn/getValues.json', { destDev: [], keys: keys })
31
+ result = @client.post('/dyn/getValues.json', { destDev: [], keys: })
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
 
@@ -40,13 +40,13 @@ module SmaApi
40
40
  #
41
41
  # @return [Array] List of directories and files
42
42
  def get_fs(path)
43
- result = @client.post('/dyn/getFS.json', { destDev: [], path: path })
43
+ result = @client.post('/dyn/getFS.json', { destDev: [], path: })
44
44
 
45
45
  result['result'].first[1][path].map do |f|
46
46
  type = f.key?('f') ? 'f' : 'd'
47
47
  {
48
48
  name: f['d'] || f['f'],
49
- type: type,
49
+ type:,
50
50
  last_modified: Time.at(f['tm']),
51
51
  size: f['s']
52
52
  }
@@ -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/http.rb CHANGED
@@ -88,12 +88,12 @@ module SmaApi
88
88
  end
89
89
 
90
90
  def retrieve_file(url)
91
- res = http.get('/fs' + url_with_sid(url))
91
+ res = http.get("/fs#{url_with_sid(url)}")
92
92
 
93
93
  unless res.code == '200'
94
94
  # Try again because invalid sid does not result in a 401
95
95
  create_session
96
- res = http.get('/fs' + url_with_sid(url))
96
+ res = http.get("/fs#{url_with_sid(url)}")
97
97
 
98
98
  raise "Error retrieving file (#{res.code} #{res.message})" unless res.code == '200'
99
99
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module SmaApi
2
- VERSION = "0.1.3"
4
+ VERSION = '0.2.1'
3
5
  end
data/lib/sma_api.rb CHANGED
@@ -1,7 +1,8 @@
1
- require "sma_api/client"
2
- require "sma_api/http"
3
- require "sma_api/version"
1
+ # frozen_string_literal: true
4
2
 
3
+ require 'sma_api/client'
4
+ require 'sma_api/http'
5
+ require 'sma_api/version'
5
6
 
6
7
  module SmaApi
7
8
  class Error < StandardError; 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.1.3
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rutger Wessels
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-09-14 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
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '2.1'
19
+ version: '2.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '2.1'
26
+ version: '2.3'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: byebug
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -31,9 +31,6 @@ dependencies:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '11.1'
34
- - - ">="
35
- - !ruby/object:Gem::Version
36
- version: 11.1.3
37
34
  type: :development
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
@@ -41,9 +38,6 @@ dependencies:
41
38
  - - "~>"
42
39
  - !ruby/object:Gem::Version
43
40
  version: '11.1'
44
- - - ">="
45
- - !ruby/object:Gem::Version
46
- version: 11.1.3
47
41
  - !ruby/object:Gem::Dependency
48
42
  name: rake
49
43
  requirement: !ruby/object:Gem::Requirement
@@ -64,76 +58,70 @@ dependencies:
64
58
  requirements:
65
59
  - - "~>"
66
60
  - !ruby/object:Gem::Version
67
- version: '3.9'
61
+ version: '3.12'
68
62
  type: :development
69
63
  prerelease: false
70
64
  version_requirements: !ruby/object:Gem::Requirement
71
65
  requirements:
72
66
  - - "~>"
73
67
  - !ruby/object:Gem::Version
74
- version: '3.9'
68
+ version: '3.12'
75
69
  - !ruby/object:Gem::Dependency
76
70
  name: rubocop
77
71
  requirement: !ruby/object:Gem::Requirement
78
72
  requirements:
79
73
  - - "~>"
80
74
  - !ruby/object:Gem::Version
81
- version: 0.82.0
75
+ version: '1.40'
82
76
  type: :development
83
77
  prerelease: false
84
78
  version_requirements: !ruby/object:Gem::Requirement
85
79
  requirements:
86
80
  - - "~>"
87
81
  - !ruby/object:Gem::Version
88
- version: 0.82.0
82
+ version: '1.40'
89
83
  - !ruby/object:Gem::Dependency
90
84
  name: rubocop-rspec
91
85
  requirement: !ruby/object:Gem::Requirement
92
86
  requirements:
93
87
  - - "~>"
94
88
  - !ruby/object:Gem::Version
95
- version: '1.39'
89
+ version: '2.16'
96
90
  type: :development
97
91
  prerelease: false
98
92
  version_requirements: !ruby/object:Gem::Requirement
99
93
  requirements:
100
94
  - - "~>"
101
95
  - !ruby/object:Gem::Version
102
- version: '1.39'
96
+ version: '2.16'
103
97
  - !ruby/object:Gem::Dependency
104
98
  name: vcr
105
99
  requirement: !ruby/object:Gem::Requirement
106
100
  requirements:
107
101
  - - "~>"
108
102
  - !ruby/object:Gem::Version
109
- version: '5.1'
103
+ version: '6.1'
110
104
  type: :development
111
105
  prerelease: false
112
106
  version_requirements: !ruby/object:Gem::Requirement
113
107
  requirements:
114
108
  - - "~>"
115
109
  - !ruby/object:Gem::Version
116
- version: '5.1'
110
+ version: '6.1'
117
111
  - !ruby/object:Gem::Dependency
118
112
  name: webmock
119
113
  requirement: !ruby/object:Gem::Requirement
120
114
  requirements:
121
115
  - - "~>"
122
116
  - !ruby/object:Gem::Version
123
- version: '3.8'
124
- - - ">="
125
- - !ruby/object:Gem::Version
126
- version: 3.8.3
117
+ version: '3.18'
127
118
  type: :development
128
119
  prerelease: false
129
120
  version_requirements: !ruby/object:Gem::Requirement
130
121
  requirements:
131
122
  - - "~>"
132
123
  - !ruby/object:Gem::Version
133
- version: '3.8'
134
- - - ">="
135
- - !ruby/object:Gem::Version
136
- version: 3.8.3
124
+ version: '3.18'
137
125
  description: Extract data from a SMA Inverter web interface.
138
126
  email:
139
127
  - rutger@rutgerwessels.nl
@@ -152,7 +140,8 @@ licenses:
152
140
  - MIT
153
141
  metadata:
154
142
  changelog_uri: https://github.com/rutgerw/sma_api/blob/master/CHANGELOG.md
155
- post_install_message:
143
+ rubygems_mfa_required: 'true'
144
+ post_install_message:
156
145
  rdoc_options: []
157
146
  require_paths:
158
147
  - lib
@@ -160,15 +149,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
160
149
  requirements:
161
150
  - - ">="
162
151
  - !ruby/object:Gem::Version
163
- version: '0'
152
+ version: '3.1'
164
153
  required_rubygems_version: !ruby/object:Gem::Requirement
165
154
  requirements:
166
155
  - - ">="
167
156
  - !ruby/object:Gem::Version
168
157
  version: '0'
169
158
  requirements: []
170
- rubygems_version: 3.1.2
171
- signing_key:
159
+ rubygems_version: 3.3.26
160
+ signing_key:
172
161
  specification_version: 4
173
162
  summary: Extract data from a SMA Inverter web interface.
174
163
  test_files: []