growatt 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/.env.template +4 -4
- data/.gitignore +47 -47
- data/CHANGELOG.md +16 -14
- data/Gemfile +6 -6
- data/README.md +114 -83
- data/Rakefile +22 -19
- data/growatt.gemspec +37 -37
- data/lib/growatt/api.rb +59 -35
- data/lib/growatt/authorization.rb +91 -36
- data/lib/growatt/client.rb +219 -160
- data/lib/growatt/connection.rb +45 -26
- data/lib/growatt/const.rb +47 -29
- data/lib/growatt/error.rb +24 -12
- data/lib/growatt/pagination.rb +32 -26
- data/lib/growatt/version.rb +5 -5
- data/lib/growatt.rb +62 -27
- metadata +4 -14
- data/test/auth_test.rb +0 -20
- data/test/client_test.rb +0 -69
- data/test/test_helper.rb +0 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 77b696ab2333a1954a2e62dcacffea1cb9f1c4ba02f06e34001d90abc25ec4a2
|
4
|
+
data.tar.gz: ae2ce05b85d79cec90ca7beb35e820f0d2529b95c215fb2ebf88213c7c3d8b92
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 433e4623b99df6514698821dbbd0ad319d736c47840b2c670f216b1bf9302f6cedede2c0f8ef9eb7bd02741f2d3ae0b8f179d72b14d69448852a7fc5eb6d219f
|
7
|
+
data.tar.gz: 2b6d7c7f0b69bace8f2b45ad838ff091e0af665ddc1dfae0c970a7bb0d692882428534eb706793102ce2524b00345f8eb02a9b771bb3dafc07dee2fa73c9c893
|
data/.env.template
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# demo token used
|
2
|
-
GROWATT_USERNAME=username
|
3
|
-
GROWATT_PASSWORD=password
|
4
|
-
|
1
|
+
# demo token used
|
2
|
+
GROWATT_USERNAME=username
|
3
|
+
GROWATT_PASSWORD=password
|
4
|
+
|
data/.gitignore
CHANGED
@@ -1,47 +1,47 @@
|
|
1
|
-
*.gem
|
2
|
-
*.rbc
|
3
|
-
/.config
|
4
|
-
/coverage/
|
5
|
-
/InstalledFiles
|
6
|
-
/pkg/
|
7
|
-
/spec/reports/
|
8
|
-
/spec/examples.txt
|
9
|
-
/test/tmp/
|
10
|
-
/test/version_tmp/
|
11
|
-
/tmp/
|
12
|
-
/data/
|
13
|
-
*.log
|
14
|
-
*.txt
|
15
|
-
*.json
|
16
|
-
*.yml
|
17
|
-
.DS_Store
|
18
|
-
__pycache__
|
19
|
-
*.py
|
20
|
-
|
21
|
-
# Used by dotenv library to load environment variables.
|
22
|
-
.env
|
23
|
-
|
24
|
-
|
25
|
-
## Documentation cache and generated files:
|
26
|
-
/.yardoc/
|
27
|
-
/_yardoc/
|
28
|
-
/doc/
|
29
|
-
/rdoc/
|
30
|
-
|
31
|
-
## Environment normalization:
|
32
|
-
/.bundle/
|
33
|
-
/vendor/bundle
|
34
|
-
/lib/bundler/man/
|
35
|
-
|
36
|
-
# for a library or gem, you might want to ignore these files since the code is
|
37
|
-
# intended to run in multiple environments; otherwise, check them in:
|
38
|
-
# Gemfile.lock
|
39
|
-
# .ruby-version
|
40
|
-
# .ruby-gemset
|
41
|
-
|
42
|
-
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
43
|
-
.rvmrc
|
44
|
-
|
45
|
-
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
46
|
-
# .rubocop-https?--*
|
47
|
-
Gemfile.lock
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
/.config
|
4
|
+
/coverage/
|
5
|
+
/InstalledFiles
|
6
|
+
/pkg/
|
7
|
+
/spec/reports/
|
8
|
+
/spec/examples.txt
|
9
|
+
/test/tmp/
|
10
|
+
/test/version_tmp/
|
11
|
+
/tmp/
|
12
|
+
/data/
|
13
|
+
*.log
|
14
|
+
*.txt
|
15
|
+
*.json
|
16
|
+
*.yml
|
17
|
+
.DS_Store
|
18
|
+
__pycache__
|
19
|
+
*.py
|
20
|
+
|
21
|
+
# Used by dotenv library to load environment variables.
|
22
|
+
.env
|
23
|
+
|
24
|
+
|
25
|
+
## Documentation cache and generated files:
|
26
|
+
/.yardoc/
|
27
|
+
/_yardoc/
|
28
|
+
/doc/
|
29
|
+
/rdoc/
|
30
|
+
|
31
|
+
## Environment normalization:
|
32
|
+
/.bundle/
|
33
|
+
/vendor/bundle
|
34
|
+
/lib/bundler/man/
|
35
|
+
|
36
|
+
# for a library or gem, you might want to ignore these files since the code is
|
37
|
+
# intended to run in multiple environments; otherwise, check them in:
|
38
|
+
# Gemfile.lock
|
39
|
+
# .ruby-version
|
40
|
+
# .ruby-gemset
|
41
|
+
|
42
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
43
|
+
.rvmrc
|
44
|
+
|
45
|
+
# Used by RuboCop. Remote config files pulled in from inherit_from directive.
|
46
|
+
# .rubocop-https?--*
|
47
|
+
Gemfile.lock
|
data/CHANGELOG.md
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
## [Unreleased]
|
2
|
-
|
3
|
-
## [0.1.0] - 2024-05-28
|
4
|
-
- Initial release
|
5
|
-
## [0.1.1] - 2024-05-28
|
6
|
-
- remove unused require
|
7
|
-
## [0.1.2] - 2024-05-29
|
8
|
-
- add missing dependency
|
9
|
-
## [0.1.3] - 2024-05-30
|
10
|
-
- fix api issues to get inverter data
|
11
|
-
## [0.1.4] - 2024-05-30
|
12
|
-
- fix api issues where some api require correct Accept header
|
13
|
-
## [0.2.0] - 2024-06-03
|
14
|
-
- rename method to reflect export limitations
|
1
|
+
## [Unreleased]
|
2
|
+
|
3
|
+
## [0.1.0] - 2024-05-28
|
4
|
+
- Initial release
|
5
|
+
## [0.1.1] - 2024-05-28
|
6
|
+
- remove unused require
|
7
|
+
## [0.1.2] - 2024-05-29
|
8
|
+
- add missing dependency
|
9
|
+
## [0.1.3] - 2024-05-30
|
10
|
+
- fix api issues to get inverter data
|
11
|
+
## [0.1.4] - 2024-05-30
|
12
|
+
- fix api issues where some api require correct Accept header
|
13
|
+
## [0.2.0] - 2024-06-03
|
14
|
+
- rename method to reflect export limitations
|
15
|
+
## [0.2.1] - 2025-03-19
|
16
|
+
- add dcumenttion
|
data/Gemfile
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
source 'https://rubygems.org'
|
4
|
-
|
5
|
-
# Specify your gem's dependencies in growatt.gemspec
|
6
|
-
gemspec
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in growatt.gemspec
|
6
|
+
gemspec
|
data/README.md
CHANGED
@@ -1,83 +1,114 @@
|
|
1
|
-
# Growatt API
|
2
|
-
[](https://rubygems.org/gems/growatt)
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
```
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
config.
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
client.
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
1
|
+
# Growatt API
|
2
|
+
[](https://rubygems.org/gems/growatt)
|
3
|
+
[](https://codeclimate.com/github/jancotanis/growatt/maintainability)
|
4
|
+
[](https://codeclimate.com/github/jancotanis/growatt/test_coverage)
|
5
|
+
|
6
|
+
This is a wrapper for the Growatt rest API. Main objective is to turn inverter on/off. This has been testen with MOD-9000TL-X.
|
7
|
+
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
|
11
|
+
Add this line to your application's Gemfile:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'growatt'
|
15
|
+
```
|
16
|
+
|
17
|
+
And then execute:
|
18
|
+
|
19
|
+
$ bundle install
|
20
|
+
|
21
|
+
Or install it yourself as:
|
22
|
+
|
23
|
+
$ gem install growatt
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
Before you start making the requests to API provide the username and password using with Shinephone app.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
require 'growatt'
|
31
|
+
require 'logger'
|
32
|
+
TEST_LOGGER = './test.log'
|
33
|
+
# use do block
|
34
|
+
Growatt.configure do |config|
|
35
|
+
config.username = ENV['GROWATT_USERNAME']
|
36
|
+
config.password = ENV['GROWATT_PASSWORD']
|
37
|
+
config.logger = Logger.new(TEST_LOGGER)
|
38
|
+
end
|
39
|
+
|
40
|
+
# or configure with options hash
|
41
|
+
client = Growatt.client
|
42
|
+
client.login
|
43
|
+
|
44
|
+
```
|
45
|
+
|
46
|
+
## Resources
|
47
|
+
### Authentication and configuration
|
48
|
+
```ruby
|
49
|
+
# setup
|
50
|
+
#
|
51
|
+
begin
|
52
|
+
client = Growatt.client
|
53
|
+
client.login
|
54
|
+
# turn invertor off
|
55
|
+
client.turn_inverter('<serial_no>', false)
|
56
|
+
rescue Growatt::AuthenticationError => e
|
57
|
+
puts "Error login to growatt api"
|
58
|
+
puts e
|
59
|
+
end
|
60
|
+
```
|
61
|
+
### Read data
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
# create client (don't forget to configure authentication)
|
65
|
+
# get data for first inverter for first defined plant
|
66
|
+
plants = client.plant_list
|
67
|
+
plant_id = plants.data.first.plantId
|
68
|
+
devices = client.inverter_list(plant_id)
|
69
|
+
inverter = devices.first
|
70
|
+
|
71
|
+
yymm = Time.now.strftime("%Y%m")
|
72
|
+
puts "- loading period #{yymm}"
|
73
|
+
data = client.inverter_data(inverter.deviceSn,Growatt::Timespan::MONTH,current_month)
|
74
|
+
|
75
|
+
```
|
76
|
+
|
77
|
+
### Control
|
78
|
+
|
79
|
+
```ruby
|
80
|
+
# continu from read data example above
|
81
|
+
inverter = devices.first
|
82
|
+
|
83
|
+
# turn inverter on/of
|
84
|
+
client.turn_inverter(inverter.deviceSn, false)
|
85
|
+
|
86
|
+
# or limit energy export
|
87
|
+
client.export_limit(inverter.deviceSn,Growatt::ExportLimit::PERCENTAGE, 100)
|
88
|
+
# allow energy export to grid
|
89
|
+
client.export_limit(inverter.deviceSn,Growatt::ExportLimit::DISABLE)
|
90
|
+
```
|
91
|
+
|
92
|
+
## Publishing
|
93
|
+
|
94
|
+
1. Update version in [version.rb](lib/growatt/version.rb).
|
95
|
+
2. Add release to [CHANGELOG.md](CHANGELOG.md)
|
96
|
+
3. Commit.
|
97
|
+
4. Test build.
|
98
|
+
```
|
99
|
+
> rake build
|
100
|
+
|
101
|
+
```
|
102
|
+
5. Release
|
103
|
+
```
|
104
|
+
> rake release
|
105
|
+
```
|
106
|
+
|
107
|
+
## Contributing
|
108
|
+
|
109
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/jancotanis/growatt.
|
110
|
+
|
111
|
+
## License
|
112
|
+
|
113
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
114
|
+
"# growatt"
|
data/Rakefile
CHANGED
@@ -1,19 +1,22 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require 'bundler/gem_tasks'
|
4
|
-
require 'dotenv'
|
5
|
-
require 'rake/testtask'
|
6
|
-
|
7
|
-
Dotenv.load
|
8
|
-
|
9
|
-
|
10
|
-
Rake::TestTask.new(:test) do |t|
|
11
|
-
t.libs << 'test'
|
12
|
-
t.libs << 'lib'
|
13
|
-
t.test_files = FileList['test/**/*_test.rb']
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'bundler/gem_tasks'
|
4
|
+
require 'dotenv'
|
5
|
+
require 'rake/testtask'
|
6
|
+
|
7
|
+
Dotenv.load
|
8
|
+
|
9
|
+
system './bin/cc-test-reporter before-build'
|
10
|
+
Rake::TestTask.new(:test) do |t|
|
11
|
+
t.libs << 'test'
|
12
|
+
t.libs << 'lib'
|
13
|
+
t.test_files = FileList['test/**/*_test.rb']
|
14
|
+
at_exit do
|
15
|
+
system './bin/cc-test-reporter after-build'
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
require 'rubocop/rake_task'
|
20
|
+
RuboCop::RakeTask.new
|
21
|
+
task default: %i[test rubocop]
|
22
|
+
|
data/growatt.gemspec
CHANGED
@@ -1,37 +1,37 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'lib/growatt/version'
|
4
|
-
|
5
|
-
Gem::Specification.new do |s|
|
6
|
-
s.name = 'growatt'
|
7
|
-
s.version = Growatt::VERSION
|
8
|
-
s.authors = ['Janco Tanis']
|
9
|
-
s.email = 'gems@jancology.com'
|
10
|
-
s.license = 'MIT'
|
11
|
-
|
12
|
-
s.summary = 'A Ruby wrapper for the Growatt APIs (readonly)'
|
13
|
-
s.homepage = 'https://rubygems.org/gems/growatt'
|
14
|
-
|
15
|
-
s.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
|
16
|
-
|
17
|
-
s.metadata['homepage_uri'] = s.homepage
|
18
|
-
s.metadata['source_code_uri'] = 'https://github.com/jancotanis/growatt'
|
19
|
-
|
20
|
-
# Specify which files should be added to the gem when it is released.
|
21
|
-
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
-
s.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
-
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
24
|
-
end
|
25
|
-
s.bindir = 'exe'
|
26
|
-
s.executables = s.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
27
|
-
s.require_paths = ['lib']
|
28
|
-
|
29
|
-
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
30
|
-
s.platform = Gem::Platform::RUBY
|
31
|
-
s.add_runtime_dependency 'wrapi', ">= 0.3.0"
|
32
|
-
s.add_runtime_dependency 'faraday-cookie_jar'
|
33
|
-
s.add_development_dependency 'dotenv'
|
34
|
-
s.add_development_dependency 'minitest'
|
35
|
-
s.add_development_dependency 'simplecov'
|
36
|
-
s.add_development_dependency 'rubocop'
|
37
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'lib/growatt/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'growatt'
|
7
|
+
s.version = Growatt::VERSION
|
8
|
+
s.authors = ['Janco Tanis']
|
9
|
+
s.email = 'gems@jancology.com'
|
10
|
+
s.license = 'MIT'
|
11
|
+
|
12
|
+
s.summary = 'A Ruby wrapper for the Growatt APIs (readonly)'
|
13
|
+
s.homepage = 'https://rubygems.org/gems/growatt'
|
14
|
+
|
15
|
+
s.required_ruby_version = Gem::Requirement.new('>= 2.4.0')
|
16
|
+
|
17
|
+
s.metadata['homepage_uri'] = s.homepage
|
18
|
+
s.metadata['source_code_uri'] = 'https://github.com/jancotanis/growatt'
|
19
|
+
|
20
|
+
# Specify which files should be added to the gem when it is released.
|
21
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
22
|
+
s.files = Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
s.bindir = 'exe'
|
26
|
+
s.executables = s.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
27
|
+
s.require_paths = ['lib']
|
28
|
+
|
29
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
30
|
+
s.platform = Gem::Platform::RUBY
|
31
|
+
s.add_runtime_dependency 'wrapi', ">= 0.3.0"
|
32
|
+
s.add_runtime_dependency 'faraday-cookie_jar'
|
33
|
+
s.add_development_dependency 'dotenv'
|
34
|
+
s.add_development_dependency 'minitest'
|
35
|
+
s.add_development_dependency 'simplecov'
|
36
|
+
s.add_development_dependency 'rubocop'
|
37
|
+
end
|
data/lib/growatt/api.rb
CHANGED
@@ -1,35 +1,59 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'wrapi'
|
4
|
+
require File.expand_path('authorization', __dir__)
|
5
|
+
require File.expand_path('connection', __dir__)
|
6
|
+
|
7
|
+
module Growatt
|
8
|
+
# The `API` class is an internal component of the Growatt module.
|
9
|
+
# It is responsible for managing API configurations, connections, and authentication.
|
10
|
+
#
|
11
|
+
# This class should not be accessed directly. Instead, use `Growatt.client` to interact with the API.
|
12
|
+
#
|
13
|
+
class API
|
14
|
+
# Attribute accessors for all valid configuration options.
|
15
|
+
#
|
16
|
+
# These options are defined in `WrAPI::Configuration::VALID_OPTIONS_KEYS`.
|
17
|
+
attr_accessor *WrAPI::Configuration::VALID_OPTIONS_KEYS
|
18
|
+
|
19
|
+
# Initializes a new `Growatt::API` instance.
|
20
|
+
#
|
21
|
+
# This method copies configuration settings from the Growatt module singleton and allows
|
22
|
+
# for optional overrides through the `options` parameter.
|
23
|
+
#
|
24
|
+
# @param options [Hash] Optional configuration overrides.
|
25
|
+
#
|
26
|
+
# @example Creating an API instance with custom options:
|
27
|
+
# api = Growatt::API.new(user_agent: "CustomClient/1.0")
|
28
|
+
#
|
29
|
+
def initialize(options = {})
|
30
|
+
options = Growatt.options.merge(options)
|
31
|
+
WrAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
|
32
|
+
send("#{key}=", options[key])
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
# Retrieves the current API configuration as a hash.
|
37
|
+
#
|
38
|
+
# @return [Hash] A hash containing the current API configuration.
|
39
|
+
#
|
40
|
+
# @example Getting the current configuration:
|
41
|
+
# api.config # => { endpoint: "https://server.growatt.com/", user_agent: "Ruby Growatt API client ..." }
|
42
|
+
#
|
43
|
+
def config
|
44
|
+
conf = {}
|
45
|
+
WrAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
|
46
|
+
conf[key] = send key
|
47
|
+
end
|
48
|
+
conf
|
49
|
+
end
|
50
|
+
|
51
|
+
# Includes required modules for making API requests, handling authentication,
|
52
|
+
# and establishing connections.
|
53
|
+
include WrAPI::Connection
|
54
|
+
include Connection
|
55
|
+
include WrAPI::Request
|
56
|
+
include WrAPI::Authentication
|
57
|
+
include Authentication
|
58
|
+
end
|
59
|
+
end
|