senec 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.rspec +3 -0
- data/.rubocop.yml +115 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +19 -0
- data/Gemfile.lock +63 -0
- data/LICENSE.txt +21 -0
- data/README.md +50 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/senec.rb +7 -0
- data/lib/senec/constants.rb +138 -0
- data/lib/senec/request.rb +58 -0
- data/lib/senec/value.rb +41 -0
- data/lib/senec/version.rb +3 -0
- data/senec.gemspec +28 -0
- metadata +64 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 1ca571cf19a300fc08c64d1c194ff240628850c4101ed3b6ce1957df09866ba5
|
4
|
+
data.tar.gz: 98b56df0080489a641856988739776aea7f90120fc4ae1dd9c80c2bbe153f6a7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8a6a7c00a1d5e199ed70b73341e389d52f63fe197ddf61098397726e278bf3b2140664ec8a1198289ee844e905a9b0fc5efe9ed770cf921bab21bbaadf0fe2fa
|
7
|
+
data.tar.gz: d62d573bfcff7fa4613cadbf485052397e772cf03c7380aad9dea6d54134aee7b4e86afc2408fa0d68697f2bdac3b7c75580d7cbfacd2d40ab985500657ef435
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-performance
|
3
|
+
- rubocop-rspec
|
4
|
+
|
5
|
+
AllCops:
|
6
|
+
TargetRubyVersion: 2.5
|
7
|
+
EnabledByDefault: true
|
8
|
+
|
9
|
+
### Metrics
|
10
|
+
|
11
|
+
Metrics/MethodLength:
|
12
|
+
Max: 20
|
13
|
+
|
14
|
+
### Bundler
|
15
|
+
|
16
|
+
Bundler/OrderedGems:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
### Style
|
20
|
+
|
21
|
+
Style/FrozenStringLiteralComment:
|
22
|
+
Enabled: false
|
23
|
+
|
24
|
+
Style/SymbolArray:
|
25
|
+
EnforcedStyle: brackets
|
26
|
+
|
27
|
+
Style/MixinUsage:
|
28
|
+
Enabled: false
|
29
|
+
|
30
|
+
Style/Documentation:
|
31
|
+
Enabled: false
|
32
|
+
|
33
|
+
Style/ClassAndModuleChildren:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
Style/Lambda:
|
37
|
+
EnforcedStyle: literal
|
38
|
+
|
39
|
+
Style/LambdaCall:
|
40
|
+
Enabled: false
|
41
|
+
|
42
|
+
Style/MethodCallWithArgsParentheses:
|
43
|
+
Enabled: false
|
44
|
+
|
45
|
+
Style/MissingElse:
|
46
|
+
Enabled: false
|
47
|
+
|
48
|
+
Style/Copyright:
|
49
|
+
Enabled: false
|
50
|
+
|
51
|
+
Style/InlineComment:
|
52
|
+
Enabled: false
|
53
|
+
|
54
|
+
Style/StringHashKeys:
|
55
|
+
Enabled: false
|
56
|
+
|
57
|
+
Style/MethodCalledOnDoEndBlock:
|
58
|
+
Enabled: false
|
59
|
+
|
60
|
+
Style/DocumentationMethod:
|
61
|
+
Enabled: false
|
62
|
+
|
63
|
+
Style/DisableCopsWithinSourceCodeDirective:
|
64
|
+
Enabled: false
|
65
|
+
|
66
|
+
Style/ConstantVisibility:
|
67
|
+
Enabled: false
|
68
|
+
|
69
|
+
### Layout
|
70
|
+
|
71
|
+
Layout/DotPosition:
|
72
|
+
EnforcedStyle: trailing
|
73
|
+
|
74
|
+
Layout/EndAlignment:
|
75
|
+
EnforcedStyleAlignWith: variable
|
76
|
+
|
77
|
+
Layout/SpaceInsideArrayLiteralBrackets:
|
78
|
+
Enabled: false
|
79
|
+
|
80
|
+
Layout/HashAlignment:
|
81
|
+
Enabled: false
|
82
|
+
|
83
|
+
Layout/MultilineMethodArgumentLineBreaks:
|
84
|
+
Enabled: false
|
85
|
+
|
86
|
+
Layout/MultilineArrayLineBreaks:
|
87
|
+
Enabled: false
|
88
|
+
|
89
|
+
Layout/MultilineAssignmentLayout:
|
90
|
+
Enabled: false
|
91
|
+
|
92
|
+
# RSpec
|
93
|
+
|
94
|
+
RSpec/MultipleExpectations:
|
95
|
+
Enabled: false
|
96
|
+
|
97
|
+
RSpec/AlignRightLetBrace:
|
98
|
+
Enabled: false
|
99
|
+
|
100
|
+
RSpec/MultipleDescribes:
|
101
|
+
Enabled: false
|
102
|
+
|
103
|
+
RSpec/NestedGroups:
|
104
|
+
Enabled: false
|
105
|
+
|
106
|
+
RSpec/ImplicitSubject:
|
107
|
+
Enabled: false
|
108
|
+
|
109
|
+
# Lint
|
110
|
+
|
111
|
+
Lint/ConstantResolution:
|
112
|
+
Enabled: false
|
113
|
+
|
114
|
+
Lint/NumberConversion:
|
115
|
+
Enabled: false
|
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at georg@ledermann.dev. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in senec.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
# Rake is a Make-like program implemented in Ruby (https://github.com/ruby/rake)
|
7
|
+
gem 'rake'
|
8
|
+
|
9
|
+
# rspec-3.10.0 (http://github.com/rspec)
|
10
|
+
gem 'rspec'
|
11
|
+
|
12
|
+
# Automatic Ruby code style checking tool. (https://github.com/rubocop-hq/rubocop)
|
13
|
+
gem 'rubocop'
|
14
|
+
|
15
|
+
# Automatic performance checking tool for Ruby code. (https://github.com/rubocop-hq/rubocop-performance)
|
16
|
+
gem 'rubocop-performance'
|
17
|
+
|
18
|
+
# Code style checking for RSpec files (https://github.com/rubocop-hq/rubocop-rspec)
|
19
|
+
gem 'rubocop-rspec'
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
senec (0.1.0)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
ast (2.4.1)
|
10
|
+
diff-lcs (1.4.4)
|
11
|
+
parallel (1.20.1)
|
12
|
+
parser (2.7.2.0)
|
13
|
+
ast (~> 2.4.1)
|
14
|
+
rainbow (3.0.0)
|
15
|
+
rake (13.0.1)
|
16
|
+
regexp_parser (2.0.0)
|
17
|
+
rexml (3.2.4)
|
18
|
+
rspec (3.10.0)
|
19
|
+
rspec-core (~> 3.10.0)
|
20
|
+
rspec-expectations (~> 3.10.0)
|
21
|
+
rspec-mocks (~> 3.10.0)
|
22
|
+
rspec-core (3.10.0)
|
23
|
+
rspec-support (~> 3.10.0)
|
24
|
+
rspec-expectations (3.10.0)
|
25
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
26
|
+
rspec-support (~> 3.10.0)
|
27
|
+
rspec-mocks (3.10.0)
|
28
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
29
|
+
rspec-support (~> 3.10.0)
|
30
|
+
rspec-support (3.10.0)
|
31
|
+
rubocop (1.4.2)
|
32
|
+
parallel (~> 1.10)
|
33
|
+
parser (>= 2.7.1.5)
|
34
|
+
rainbow (>= 2.2.2, < 4.0)
|
35
|
+
regexp_parser (>= 1.8)
|
36
|
+
rexml
|
37
|
+
rubocop-ast (>= 1.1.1)
|
38
|
+
ruby-progressbar (~> 1.7)
|
39
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
40
|
+
rubocop-ast (1.2.0)
|
41
|
+
parser (>= 2.7.1.5)
|
42
|
+
rubocop-performance (1.9.1)
|
43
|
+
rubocop (>= 0.90.0, < 2.0)
|
44
|
+
rubocop-ast (>= 0.4.0)
|
45
|
+
rubocop-rspec (2.0.0)
|
46
|
+
rubocop (~> 1.0)
|
47
|
+
rubocop-ast (>= 1.1.0)
|
48
|
+
ruby-progressbar (1.10.1)
|
49
|
+
unicode-display_width (1.7.0)
|
50
|
+
|
51
|
+
PLATFORMS
|
52
|
+
ruby
|
53
|
+
|
54
|
+
DEPENDENCIES
|
55
|
+
rake
|
56
|
+
rspec
|
57
|
+
rubocop
|
58
|
+
rubocop-performance
|
59
|
+
rubocop-rspec
|
60
|
+
senec!
|
61
|
+
|
62
|
+
BUNDLED WITH
|
63
|
+
2.1.4
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Georg Ledermann
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Unofficial Ruby Client for SENEC Home
|
2
|
+
|
3
|
+
Access your local SENEC Solar Battery Storage System
|
4
|
+
|
5
|
+
**WARNING:** This project was coded in a few hours just for fun after the photovoltaic stuff was installed in my house. I'm not affiliated in any way with the SENEC company.
|
6
|
+
|
7
|
+
Inspired by:
|
8
|
+
|
9
|
+
* https://github.com/mchwalisz/pysenec
|
10
|
+
* https://gist.github.com/smashnet/82ad0b9d7f0ba2e5098e6649ba08f88a
|
11
|
+
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
```bash
|
16
|
+
$ gem install senec
|
17
|
+
```
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
require 'senec'
|
23
|
+
|
24
|
+
request = Senec::Request.new host: '10.0.1.99'
|
25
|
+
|
26
|
+
puts "House power consumption: #{request.house_power} W"
|
27
|
+
puts "PV production: #{request.inverter_power} W"
|
28
|
+
puts "Battery charge power: #{request.bat_power} W"
|
29
|
+
puts "Grid power: #{request.grid_power} W"
|
30
|
+
puts "Current state of the system: #{request.current_state}"
|
31
|
+
```
|
32
|
+
|
33
|
+
## Development
|
34
|
+
|
35
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
36
|
+
|
37
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
38
|
+
|
39
|
+
## Contributing
|
40
|
+
|
41
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/ledermann/senec. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/ledermann/senec/blob/master/CODE_OF_CONDUCT.md).
|
42
|
+
|
43
|
+
|
44
|
+
## License
|
45
|
+
|
46
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
47
|
+
|
48
|
+
## Code of Conduct
|
49
|
+
|
50
|
+
Everyone interacting in this project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/senec/blob/master/CODE_OF_CONDUCT.md).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'senec'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/senec.rb
ADDED
@@ -0,0 +1,138 @@
|
|
1
|
+
module Senec # rubocop:disable Metrics/ModuleLength
|
2
|
+
# Taken from https://github.com/mchwalisz/pysenec
|
3
|
+
STATE_NAMES = {
|
4
|
+
0 => 'INITIAL STATE',
|
5
|
+
1 => 'ERROR INVERTER COMMUNICATION',
|
6
|
+
2 => 'ERROR ELECTRICY METER',
|
7
|
+
3 => 'RIPPLE CONTROL RECEIVER',
|
8
|
+
4 => 'INITIAL CHARGE',
|
9
|
+
5 => 'MAINTENANCE CHARGE',
|
10
|
+
6 => 'MAINTENANCE READY',
|
11
|
+
7 => 'MAINTENANCE REQUIRED',
|
12
|
+
8 => 'MAN. SAFETY CHARGE',
|
13
|
+
9 => 'SAFETY CHARGE READY',
|
14
|
+
10 => 'FULL CHARGE',
|
15
|
+
11 => 'EQUALIZATION: CHARGE',
|
16
|
+
12 => 'DESULFATATION: CHARGE',
|
17
|
+
13 => 'BATTERY FULL',
|
18
|
+
14 => 'CHARGE',
|
19
|
+
15 => 'BATTERY EMPTY',
|
20
|
+
16 => 'DISCHARGE',
|
21
|
+
17 => 'PV + DISCHARGE',
|
22
|
+
18 => 'GRID + DISCHARGE',
|
23
|
+
19 => 'PASSIVE',
|
24
|
+
20 => 'OFF',
|
25
|
+
21 => 'OWN CONSUMPTION',
|
26
|
+
22 => 'RESTART',
|
27
|
+
23 => 'MAN. EQUALIZATION: CHARGE',
|
28
|
+
24 => 'MAN. DESULFATATION: CHARGE',
|
29
|
+
25 => 'SAFETY CHARGE',
|
30
|
+
26 => 'BATTERY PROTECTION MODE',
|
31
|
+
27 => 'EG ERROR',
|
32
|
+
28 => 'EG CHARGE',
|
33
|
+
29 => 'EG DISCHARGE',
|
34
|
+
30 => 'EG PASSIVE',
|
35
|
+
31 => 'EG PROHIBIT CHARGE',
|
36
|
+
32 => 'EG PROHIBIT DISCHARGE',
|
37
|
+
33 => 'EMERGANCY CHARGE',
|
38
|
+
34 => 'SOFTWARE UPDATE',
|
39
|
+
35 => 'NSP ERROR',
|
40
|
+
36 => 'NSP ERROR: GRID',
|
41
|
+
37 => 'NSP ERROR: HARDWRE',
|
42
|
+
38 => 'NO SERVER CONNECTION',
|
43
|
+
39 => 'BMS ERROR',
|
44
|
+
40 => 'MAINTENANCE: FILTER',
|
45
|
+
41 => 'SLEEPING MODE',
|
46
|
+
42 => 'WAITING EXCESS',
|
47
|
+
43 => 'CAPACITY TEST: CHARGE',
|
48
|
+
44 => 'CAPACITY TEST: DISCHARGE',
|
49
|
+
45 => 'MAN. DESULFATATION: WAIT',
|
50
|
+
46 => 'MAN. DESULFATATION: READY',
|
51
|
+
47 => 'MAN. DESULFATATION: ERROR',
|
52
|
+
48 => 'EQUALIZATION: WAIT',
|
53
|
+
49 => 'EMERGANCY CHARGE: ERROR',
|
54
|
+
50 => 'MAN. EQUALIZATION: WAIT',
|
55
|
+
51 => 'MAN. EQUALIZATION: ERROR',
|
56
|
+
52 => 'MAN: EQUALIZATION: READY',
|
57
|
+
53 => 'AUTO. DESULFATATION: WAIT',
|
58
|
+
54 => 'ABSORPTION PHASE',
|
59
|
+
55 => 'DC-SWITCH OFF',
|
60
|
+
56 => 'PEAK-SHAVING: WAIT',
|
61
|
+
57 => 'ERROR BATTERY INVERTER',
|
62
|
+
58 => 'NPU-ERROR',
|
63
|
+
59 => 'BMS OFFLINE',
|
64
|
+
60 => 'MAINTENANCE CHARGE ERROR',
|
65
|
+
61 => 'MAN. SAFETY CHARGE ERROR',
|
66
|
+
62 => 'SAFETY CHARGE ERROR',
|
67
|
+
63 => 'NO CONNECTION TO MASTER',
|
68
|
+
64 => 'LITHIUM SAFE MODE ACTIVE',
|
69
|
+
65 => 'LITHIUM SAFE MODE DONE',
|
70
|
+
66 => 'BATTERY VOLTAGE ERROR',
|
71
|
+
67 => 'BMS DC SWITCHED OFF',
|
72
|
+
68 => 'GRID INITIALIZATION',
|
73
|
+
69 => 'GRID STABILIZATION',
|
74
|
+
70 => 'REMOTE SHUTDOWN',
|
75
|
+
71 => 'OFFPEAK-CHARGE',
|
76
|
+
72 => 'ERROR HALFBRIDGE',
|
77
|
+
73 => 'BMS: ERROR OPERATING TEMPERATURE',
|
78
|
+
74 => 'FACOTRY SETTINGS NOT FOUND',
|
79
|
+
75 => 'BACKUP POWER MODE - ACTIVE',
|
80
|
+
76 => 'BACKUP POWER MODE - BATTERY EMPTY',
|
81
|
+
77 => 'BACKUP POWER MODE ERROR',
|
82
|
+
78 => 'INITIALISING',
|
83
|
+
79 => 'INSTALLATION MODE',
|
84
|
+
80 => 'GRID OFFLINE',
|
85
|
+
81 => 'BMS UPDATE NEEDED',
|
86
|
+
82 => 'BMS CONFIGURATION NEEDED',
|
87
|
+
83 => 'INSULATION TEST',
|
88
|
+
84 => 'SELFTEST',
|
89
|
+
85 => 'EXTERNAL CONTROL',
|
90
|
+
86 => 'ERROR: TEMPERATURESENSOR',
|
91
|
+
87 => 'GRID OPERATOR: CHARGE PROHIBITED',
|
92
|
+
88 => 'GRID OPERATOR: DISCHARGE PROHIBITED',
|
93
|
+
89 => 'SPARE CAPACITY',
|
94
|
+
90 => 'SELFTEST ERROR',
|
95
|
+
91 => 'EARTH FAULT'
|
96
|
+
}.freeze
|
97
|
+
|
98
|
+
# Taken from https://gist.github.com/smashnet/82ad0b9d7f0ba2e5098e6649ba08f88a
|
99
|
+
BASIC_REQUEST = {
|
100
|
+
'STATISTIC': {
|
101
|
+
'CURRENT_STATE': '', # Current state of the system (int, see SYSTEM_STATE_NAME)
|
102
|
+
'LIVE_BAT_CHARGE_MASTER': '', # Battery charge amount since installation (kWh)
|
103
|
+
'LIVE_BAT_DISCHARGE_MASTER': '', # Battery discharge amount since installation (kWh)
|
104
|
+
'LIVE_GRID_EXPORT': '', # Grid export amount since installation (kWh)
|
105
|
+
'LIVE_GRID_IMPORT': '', # Grid import amount since installation (kWh)
|
106
|
+
'LIVE_HOUSE_CONS': '', # House consumption since installation (kWh)
|
107
|
+
'LIVE_PV_GEN': '', # PV generated power since installation (kWh)
|
108
|
+
'MEASURE_TIME': '' # Unix timestamp for above values (ms)
|
109
|
+
},
|
110
|
+
'ENERGY': {
|
111
|
+
'GUI_BAT_DATA_CURRENT': '', # Battery charge current: negative if discharging, positiv if charging (A)
|
112
|
+
'GUI_BAT_DATA_FUEL_CHARGE': '', # Remaining battery (percent)
|
113
|
+
'GUI_BAT_DATA_POWER': '', # Battery charge power: negative if discharging, positiv if charging (W)
|
114
|
+
'GUI_BAT_DATA_VOLTAGE': '', # Battery voltage (V)
|
115
|
+
'GUI_GRID_POW': '', # Grid power: negative if exporting, positiv if importing (W)
|
116
|
+
'GUI_HOUSE_POW': '', # House power consumption (W)
|
117
|
+
'GUI_INVERTER_POWER': '', # PV production (W)
|
118
|
+
'STAT_HOURS_OF_OPERATION': '' # Appliance hours of operation
|
119
|
+
},
|
120
|
+
'BMS': {
|
121
|
+
'CHARGED_ENERGY': '', # List: Charged energy per battery
|
122
|
+
'DISCHARGED_ENERGY': '', # List: Discharged energy per battery
|
123
|
+
'CYCLES': '' # List: Cycles per battery
|
124
|
+
},
|
125
|
+
'PV1': {
|
126
|
+
'MPP_CUR': '', # List: MPP current (A)
|
127
|
+
'MPP_POWER': '', # List: MPP power (W)
|
128
|
+
'MPP_VOL': '', # List: MPP voltage (V)
|
129
|
+
'POWER_RATIO': '', # Grid export limit (percent)
|
130
|
+
'P_TOTAL': '' # ?
|
131
|
+
},
|
132
|
+
'FACTORY': {
|
133
|
+
'DESIGN_CAPACITY': '', # Battery design capacity (Wh)
|
134
|
+
'MAX_CHARGE_POWER_DC': '', # Battery max charging power (W)
|
135
|
+
'MAX_DISCHARGE_POWER_DC': '' # Battery max discharging power (W)
|
136
|
+
}
|
137
|
+
}.freeze
|
138
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
|
+
require 'senec/value'
|
4
|
+
require 'senec/constants'
|
5
|
+
|
6
|
+
module Senec
|
7
|
+
class Request
|
8
|
+
def initialize(host:)
|
9
|
+
@host = host
|
10
|
+
end
|
11
|
+
|
12
|
+
def house_power
|
13
|
+
value = response.dig('ENERGY', 'GUI_HOUSE_POW')
|
14
|
+
Senec::Value.new(value).to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
def inverter_power
|
18
|
+
value = response.dig('ENERGY', 'GUI_INVERTER_POWER')
|
19
|
+
Senec::Value.new(value).to_i
|
20
|
+
end
|
21
|
+
|
22
|
+
def bat_power
|
23
|
+
value = response.dig('ENERGY', 'GUI_BAT_DATA_POWER')
|
24
|
+
Senec::Value.new(value).to_i
|
25
|
+
end
|
26
|
+
|
27
|
+
def grid_power
|
28
|
+
value = response.dig('ENERGY', 'GUI_GRID_POW')
|
29
|
+
Senec::Value.new(value).to_i
|
30
|
+
end
|
31
|
+
|
32
|
+
def current_state
|
33
|
+
value = response.dig('STATISTIC', 'CURRENT_STATE')
|
34
|
+
state = Senec::Value.new(value).to_i
|
35
|
+
|
36
|
+
STATE_NAMES[state]
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def response
|
42
|
+
@response ||= begin
|
43
|
+
res = Net::HTTP.post uri, Senec::BASIC_REQUEST.to_json
|
44
|
+
|
45
|
+
case res
|
46
|
+
when Net::HTTPOK
|
47
|
+
JSON.parse(res.body)
|
48
|
+
else
|
49
|
+
throw "Failure: #{res.value}"
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def uri
|
55
|
+
URI.parse("http://#{@host}/lala.cgi")
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/senec/value.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
module Senec
|
2
|
+
class Value
|
3
|
+
def initialize(data)
|
4
|
+
@data = data
|
5
|
+
end
|
6
|
+
|
7
|
+
def to_f
|
8
|
+
decoded_value
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_i
|
12
|
+
decoded_value.round
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def decoded_value
|
18
|
+
parts = @data.split('_')
|
19
|
+
prefix = parts[0]
|
20
|
+
value = parts[1]
|
21
|
+
|
22
|
+
case prefix
|
23
|
+
when 'fl'
|
24
|
+
hex2float(value)
|
25
|
+
when 'i3', 'u1', 'u3'
|
26
|
+
hex2int(value)
|
27
|
+
# TODO: There are some more prefixes to handle
|
28
|
+
else
|
29
|
+
raise ArgumentError, "#{@data} cannot be decoded!"
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def hex2float(hex)
|
34
|
+
[ "0x#{hex}".to_i(16) ].pack('L').unpack1('F')
|
35
|
+
end
|
36
|
+
|
37
|
+
def hex2int(hex)
|
38
|
+
"0x#{hex}".to_i(16)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/senec.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
require_relative 'lib/senec/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'senec'
|
5
|
+
spec.version = Senec::VERSION
|
6
|
+
spec.authors = ['Georg Ledermann']
|
7
|
+
spec.email = ['georg@ledermann.dev']
|
8
|
+
|
9
|
+
spec.summary = 'Unofficial Ruby Client for SENEC Home'
|
10
|
+
spec.description = 'Access your local SENEC Solar Battery Storage System'
|
11
|
+
spec.homepage = 'https://github.com/ledermann/senec'
|
12
|
+
spec.license = 'MIT'
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.5.0')
|
14
|
+
|
15
|
+
spec.metadata['homepage_uri'] = spec.homepage
|
16
|
+
spec.metadata['source_code_uri'] = 'https://github.com/ledermann/senec'
|
17
|
+
spec.metadata['changelog_uri'] = 'https://github.com/ledermann/releases'
|
18
|
+
|
19
|
+
# Specify which files should be added to the gem when it is released.
|
20
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
21
|
+
spec.files =
|
22
|
+
Dir.chdir(File.expand_path(__dir__)) do
|
23
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
24
|
+
end
|
25
|
+
spec.bindir = 'exe'
|
26
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
27
|
+
spec.require_paths = ['lib']
|
28
|
+
end
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: senec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Georg Ledermann
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-11-28 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Access your local SENEC Solar Battery Storage System
|
14
|
+
email:
|
15
|
+
- georg@ledermann.dev
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files: []
|
19
|
+
files:
|
20
|
+
- ".gitignore"
|
21
|
+
- ".rspec"
|
22
|
+
- ".rubocop.yml"
|
23
|
+
- ".travis.yml"
|
24
|
+
- CODE_OF_CONDUCT.md
|
25
|
+
- Gemfile
|
26
|
+
- Gemfile.lock
|
27
|
+
- LICENSE.txt
|
28
|
+
- README.md
|
29
|
+
- Rakefile
|
30
|
+
- bin/console
|
31
|
+
- bin/setup
|
32
|
+
- lib/senec.rb
|
33
|
+
- lib/senec/constants.rb
|
34
|
+
- lib/senec/request.rb
|
35
|
+
- lib/senec/value.rb
|
36
|
+
- lib/senec/version.rb
|
37
|
+
- senec.gemspec
|
38
|
+
homepage: https://github.com/ledermann/senec
|
39
|
+
licenses:
|
40
|
+
- MIT
|
41
|
+
metadata:
|
42
|
+
homepage_uri: https://github.com/ledermann/senec
|
43
|
+
source_code_uri: https://github.com/ledermann/senec
|
44
|
+
changelog_uri: https://github.com/ledermann/releases
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.5.0
|
54
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubygems_version: 3.1.4
|
61
|
+
signing_key:
|
62
|
+
specification_version: 4
|
63
|
+
summary: Unofficial Ruby Client for SENEC Home
|
64
|
+
test_files: []
|