growatt 0.1.4 → 0.2.0

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: 690f64562aa9bb8165ed9ddd859d5858c39d4a347c9a428997969881cb0dcfa4
4
- data.tar.gz: 7a6236aa6d31d42ba90166dfbf3e64d5209e542eef2902186e394c7a708e41e4
3
+ metadata.gz: 6cdc0228981843d69bfcec6a7bfac1e9ec88e4511242901c7edfb1f5a75e35ee
4
+ data.tar.gz: a60b162152c7090b9baa7f1427c8218c59551de541a2e4cb877a2bd263d48f98
5
5
  SHA512:
6
- metadata.gz: b02ff867b268c0d4ea7697a53e76cf4a6afb9245afb8ad34e5982f03d4789c6a3effc8518cc19d707d9bdad8483d95192136e9b40f04489c50568c7142b8c2f3
7
- data.tar.gz: 4fd6b8ee8aafda44cf9ddada702f929a98c9a121ebaca71af70a786f6b8fb09fd884530a35542e1c1a2e4b1e6cff0178819656151449f6e017a117eaac2db018
6
+ metadata.gz: 58d0571cb4dce760266b931865e4fd7b0af69bd01c8ccbaaa51214ebd1bf5270acb3878f2356756413c9037842dc5084de2695a0cf640d5425252768dc0a307d
7
+ data.tar.gz: ea7d72d419209489861c5a109388f13160d3c32a5f02f5094c039562600c5f2a0c054a7ad8cca788753908c5b90cfe8b616e19ab235b22454fc6d6cdd3c86d12
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,12 +1,14 @@
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
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
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,83 @@
1
- # Growatt API
2
- [![Version](https://img.shields.io/gem/v/growatt.svg)](https://rubygems.org/gems/growatt)
3
-
4
- 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.
5
-
6
-
7
- ## Installation
8
-
9
- Add this line to your application's Gemfile:
10
-
11
- ```ruby
12
- gem 'growatt'
13
- ```
14
-
15
- And then execute:
16
-
17
- $ bundle install
18
-
19
- Or install it yourself as:
20
-
21
- $ gem install growatt
22
-
23
- ## Usage
24
-
25
- Before you start making the requests to API provide the endpoint and api key using the configuration wrapping.
26
-
27
- ```ruby
28
- require 'growatt'
29
- require 'logger'
30
-
31
- # use do block
32
- Growatt.configure do |config|
33
- config.username = ENV['GROWATT_USERNAME']
34
- config.password = ENV['GROWATT_PASSWORD']
35
- config.logger = Logger.new(TEST_LOGGER)
36
- end
37
-
38
- # or configure with options hash
39
- client = Growatt.client
40
- client.login
41
-
42
- ```
43
-
44
- ## Resources
45
- ### Authentication
46
- ```ruby
47
- # setup
48
- #
49
- begin
50
- client = Growatt.client
51
- client.login
52
- # turn invertor off
53
- client.turn_inverter('<serial_no>', false)
54
- rescue Growatt::AuthenticationError => e
55
- puts "Error logging in growatt api"
56
- puts e
57
- end
58
- ```
59
-
60
-
61
-
62
- ## Publishing
63
-
64
- 1. Update version in [version.rb](lib/growatt/version.rb).
65
- 2. Add release to [CHANGELOG.md](CHANGELOG.md)
66
- 3. Commit.
67
- 4. Test build.
68
- ```
69
- > rake build
70
-
71
- ```
72
- 5. Release
73
- ```
74
- > rake release
75
-
76
- ## Contributing
77
-
78
- Bug reports and pull requests are welcome on GitHub at https://github.com/jancotanis/growatt.
79
-
80
- ## License
81
-
82
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
83
- "# growatt"
1
+ # Growatt API
2
+ [![Version](https://img.shields.io/gem/v/growatt.svg)](https://rubygems.org/gems/growatt)
3
+
4
+ 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.
5
+
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'growatt'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install growatt
22
+
23
+ ## Usage
24
+
25
+ Before you start making the requests to API provide the endpoint and api key using the configuration wrapping.
26
+
27
+ ```ruby
28
+ require 'growatt'
29
+ require 'logger'
30
+
31
+ # use do block
32
+ Growatt.configure do |config|
33
+ config.username = ENV['GROWATT_USERNAME']
34
+ config.password = ENV['GROWATT_PASSWORD']
35
+ config.logger = Logger.new(TEST_LOGGER)
36
+ end
37
+
38
+ # or configure with options hash
39
+ client = Growatt.client
40
+ client.login
41
+
42
+ ```
43
+
44
+ ## Resources
45
+ ### Authentication
46
+ ```ruby
47
+ # setup
48
+ #
49
+ begin
50
+ client = Growatt.client
51
+ client.login
52
+ # turn invertor off
53
+ client.turn_inverter('<serial_no>', false)
54
+ rescue Growatt::AuthenticationError => e
55
+ puts "Error logging in growatt api"
56
+ puts e
57
+ end
58
+ ```
59
+
60
+
61
+
62
+ ## Publishing
63
+
64
+ 1. Update version in [version.rb](lib/growatt/version.rb).
65
+ 2. Add release to [CHANGELOG.md](CHANGELOG.md)
66
+ 3. Commit.
67
+ 4. Test build.
68
+ ```
69
+ > rake build
70
+
71
+ ```
72
+ 5. Release
73
+ ```
74
+ > rake release
75
+
76
+ ## Contributing
77
+
78
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jancotanis/growatt.
79
+
80
+ ## License
81
+
82
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
83
+ "# growatt"
data/Rakefile CHANGED
@@ -1,19 +1,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
- end
15
-
16
- require 'rubocop/rake_task'
17
- RuboCop::RakeTask.new
18
- task default: %i[test rubocop]
19
- #system './bin/cc-test-reporter after-build'
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
+ end
15
+
16
+ require 'rubocop/rake_task'
17
+ RuboCop::RakeTask.new
18
+ task default: %i[test rubocop]
19
+ #system './bin/cc-test-reporter after-build'
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,35 @@
1
- require "wrapi"
2
- require File.expand_path('authorization', __dir__)
3
- require File.expand_path('connection', __dir__)
4
-
5
- module Growatt
6
- # @private
7
- class API
8
-
9
- # @private
10
- attr_accessor *WrAPI::Configuration::VALID_OPTIONS_KEYS
11
-
12
- # Creates a new API and copies settings from singleton
13
- def initialize(options = {})
14
- options = Growatt.options.merge(options)
15
- WrAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
16
- send("#{key}=", options[key])
17
- end
18
- end
19
-
20
- def config
21
- conf = {}
22
- WrAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
23
- conf[key] = send key
24
- end
25
- conf
26
- end
27
-
28
- include WrAPI::Connection
29
- include Connection
30
- include WrAPI::Request
31
- include WrAPI::Authentication
32
- include Authentication
33
-
34
- end
35
- end
1
+ require "wrapi"
2
+ require File.expand_path('authorization', __dir__)
3
+ require File.expand_path('connection', __dir__)
4
+
5
+ module Growatt
6
+ # @private
7
+ class API
8
+
9
+ # @private
10
+ attr_accessor *WrAPI::Configuration::VALID_OPTIONS_KEYS
11
+
12
+ # Creates a new API and copies settings from singleton
13
+ def initialize(options = {})
14
+ options = Growatt.options.merge(options)
15
+ WrAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
16
+ send("#{key}=", options[key])
17
+ end
18
+ end
19
+
20
+ def config
21
+ conf = {}
22
+ WrAPI::Configuration::VALID_OPTIONS_KEYS.each do |key|
23
+ conf[key] = send key
24
+ end
25
+ conf
26
+ end
27
+
28
+ include WrAPI::Connection
29
+ include Connection
30
+ include WrAPI::Request
31
+ include WrAPI::Authentication
32
+ include Authentication
33
+
34
+ end
35
+ end
@@ -1,36 +1,36 @@
1
- require 'digest'
2
- require File.expand_path('error', __dir__)
3
-
4
- module Growatt
5
- # Deals with authentication flow and stores it within global configuration
6
- module Authentication
7
-
8
- # Authorize to the Growatt portal
9
- def login()
10
- raise ConfigurationError, "Username/password not set" unless username || password
11
- _password = hash_password(self.password) #unless is_password_hashed
12
-
13
- _format = self.format
14
- self.format = 'x-www-form-urlencoded'
15
- response = post('newTwoLoginAPI.do', {'userName': self.username, 'password': _password})
16
- self.format = _format
17
- data = response.body['back']
18
- if data && data['success']
19
- @login_data = data
20
- data
21
- else
22
- raise AuthenticationError.new(data['error'])
23
- end
24
- end
25
- private
26
- def hash_password(password)
27
- password_md5 = Digest::MD5.hexdigest(password.encode('utf-8'))
28
- (0...password_md5.length).step(2) do |i|
29
- if password_md5[i] == '0'
30
- password_md5[i] = 'c'
31
- end
32
- end
33
- password_md5
34
- end
35
- end
36
- end
1
+ require 'digest'
2
+ require File.expand_path('error', __dir__)
3
+
4
+ module Growatt
5
+ # Deals with authentication flow and stores it within global configuration
6
+ module Authentication
7
+
8
+ # Authorize to the Growatt portal
9
+ def login()
10
+ raise ConfigurationError, "Username/password not set" unless username || password
11
+ _password = hash_password(self.password) #unless is_password_hashed
12
+
13
+ _format = self.format
14
+ self.format = 'x-www-form-urlencoded'
15
+ response = post('newTwoLoginAPI.do', {'userName': self.username, 'password': _password})
16
+ self.format = _format
17
+ data = response.body['back']
18
+ if data && data['success']
19
+ @login_data = data
20
+ data
21
+ else
22
+ raise AuthenticationError.new(data['error'])
23
+ end
24
+ end
25
+ private
26
+ def hash_password(password)
27
+ password_md5 = Digest::MD5.hexdigest(password.encode('utf-8'))
28
+ (0...password_md5.length).step(2) do |i|
29
+ if password_md5[i] == '0'
30
+ password_md5[i] = 'c'
31
+ end
32
+ end
33
+ password_md5
34
+ end
35
+ end
36
+ end