senec 0.5.0 → 0.6.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 +4 -4
- data/.github/workflows/push.yml +1 -1
- data/.rubocop.yml +4 -1
- data/.vscode/settings.json +18 -0
- data/Gemfile +10 -1
- data/README.md +3 -5
- data/lib/senec/request.rb +26 -27
- data/lib/senec/value.rb +15 -17
- data/lib/senec/version.rb +1 -1
- data/senec.gemspec +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 37a0113a0636d99436244e2e69122dba3d8e978c74c63858f2cc35774a3eb6b5
|
4
|
+
data.tar.gz: bffc7d07e16369e04b518034ab87feedc07ecdc97091e8694caf7b113ff8e95e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a10a927e07bf216f44e0fc7bd6770d61d851c6523b72fb040800667b65d5e0d4421352929091df67129b7dd1fa16111cc408be93da0398e94ffde0cf99c81f5
|
7
|
+
data.tar.gz: c0fa250c00fecf7f6a4a8ac2efc0e04740a3de1d6dfef469cf84e8ff63851e32a85835854edc47858f98109515f8c411d82c4a548a7886f7384a3915307bead5
|
data/.github/workflows/push.yml
CHANGED
data/.rubocop.yml
CHANGED
@@ -4,7 +4,7 @@ require:
|
|
4
4
|
- rubocop-rake
|
5
5
|
|
6
6
|
AllCops:
|
7
|
-
TargetRubyVersion: 2.
|
7
|
+
TargetRubyVersion: 2.7
|
8
8
|
NewCops: enable
|
9
9
|
|
10
10
|
Style/Documentation:
|
@@ -15,3 +15,6 @@ Style/FrozenStringLiteralComment:
|
|
15
15
|
|
16
16
|
Metrics/MethodLength:
|
17
17
|
Max: 15
|
18
|
+
|
19
|
+
Layout/LineLength:
|
20
|
+
AllowedPatterns: ['\A#'] # Allow long comments
|
@@ -0,0 +1,18 @@
|
|
1
|
+
{
|
2
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
3
|
+
"editor.formatOnSave": true,
|
4
|
+
"editor.tabSize": 2,
|
5
|
+
|
6
|
+
"files.trimTrailingWhitespace": true,
|
7
|
+
|
8
|
+
"ruby.lint": {
|
9
|
+
"rubocop": {
|
10
|
+
"forceExclusion": true
|
11
|
+
}
|
12
|
+
},
|
13
|
+
|
14
|
+
"[ruby]": {
|
15
|
+
"editor.defaultFormatter": "esbenp.prettier-vscode",
|
16
|
+
"editor.formatOnSave": true
|
17
|
+
}
|
18
|
+
}
|
data/Gemfile
CHANGED
@@ -6,7 +6,7 @@ gemspec
|
|
6
6
|
# Rake is a Make-like program implemented in Ruby (https://github.com/ruby/rake)
|
7
7
|
gem 'rake'
|
8
8
|
|
9
|
-
# rspec-3.
|
9
|
+
# rspec-3.12.0 (http://github.com/rspec)
|
10
10
|
gem 'rspec'
|
11
11
|
|
12
12
|
# Automatic Ruby code style checking tool. (https://github.com/rubocop/rubocop)
|
@@ -20,3 +20,12 @@ gem 'rubocop-rspec'
|
|
20
20
|
|
21
21
|
# A RuboCop plugin for Rake (https://github.com/rubocop/rubocop-rake)
|
22
22
|
gem 'rubocop-rake'
|
23
|
+
|
24
|
+
# HTTP should be easy (https://github.com/httprb/http)
|
25
|
+
gem 'http'
|
26
|
+
|
27
|
+
# Record your test suite's HTTP interactions and replay them during future test runs for fast, deterministic, accurate tests. (https://relishapp.com/vcr/vcr/docs)
|
28
|
+
gem 'vcr'
|
29
|
+
|
30
|
+
# Library for stubbing HTTP requests in Ruby. (https://github.com/bblimke/webmock)
|
31
|
+
gem 'webmock'
|
data/README.md
CHANGED
@@ -2,13 +2,12 @@
|
|
2
2
|
|
3
3
|
Access your local SENEC Solar Battery Storage System
|
4
4
|
|
5
|
-
**WARNING:**
|
5
|
+
**WARNING:** I'm not affiliated in any way with the SENEC company.
|
6
6
|
|
7
7
|
Inspired by:
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
- https://github.com/mchwalisz/pysenec
|
10
|
+
- https://gist.github.com/smashnet/82ad0b9d7f0ba2e5098e6649ba08f88a
|
12
11
|
|
13
12
|
## Installation
|
14
13
|
|
@@ -68,7 +67,6 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
68
67
|
|
69
68
|
Bug reports and pull requests are welcome on GitHub at https://github.com/solectrus/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/solectrus/senec/blob/master/CODE_OF_CONDUCT.md).
|
70
69
|
|
71
|
-
|
72
70
|
## License
|
73
71
|
|
74
72
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/lib/senec/request.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'http'
|
2
2
|
require 'json'
|
3
3
|
require 'senec/value'
|
4
4
|
require 'senec/constants'
|
@@ -10,71 +10,70 @@ module Senec
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def house_power
|
13
|
-
|
14
|
-
Senec::Value.new(value).to_i
|
13
|
+
get('ENERGY', 'GUI_HOUSE_POW')
|
15
14
|
end
|
16
15
|
|
17
16
|
def inverter_power
|
18
|
-
|
19
|
-
Senec::Value.new(value).to_i
|
17
|
+
get('ENERGY', 'GUI_INVERTER_POWER')
|
20
18
|
end
|
21
19
|
|
22
20
|
def bat_power
|
23
|
-
|
24
|
-
Senec::Value.new(value).to_i
|
21
|
+
get('ENERGY', 'GUI_BAT_DATA_POWER')
|
25
22
|
end
|
26
23
|
|
27
24
|
def bat_fuel_charge
|
28
|
-
|
29
|
-
Senec::Value.new(value).to_f
|
25
|
+
get('ENERGY', 'GUI_BAT_DATA_FUEL_CHARGE')
|
30
26
|
end
|
31
27
|
|
32
28
|
def bat_charge_current
|
33
|
-
|
34
|
-
Senec::Value.new(value).to_f
|
29
|
+
get('ENERGY', 'GUI_BAT_DATA_CURRENT')
|
35
30
|
end
|
36
31
|
|
37
32
|
def bat_voltage
|
38
|
-
|
39
|
-
Senec::Value.new(value).to_f
|
33
|
+
get('ENERGY', 'GUI_BAT_DATA_VOLTAGE')
|
40
34
|
end
|
41
35
|
|
42
36
|
def grid_power
|
43
|
-
|
44
|
-
Senec::Value.new(value).to_i
|
37
|
+
get('ENERGY', 'GUI_GRID_POW')
|
45
38
|
end
|
46
39
|
|
47
40
|
def wallbox_charge_power
|
48
|
-
|
49
|
-
Senec::Value.new(value).to_i
|
50
|
-
end
|
41
|
+
get('WALLBOX', 'APPARENT_CHARGING_POWER')
|
51
42
|
end
|
52
43
|
|
53
44
|
def case_temp
|
54
|
-
|
55
|
-
Senec::Value.new(value).to_f
|
45
|
+
get('TEMPMEASURE', 'CASE_TEMP')
|
56
46
|
end
|
57
47
|
|
58
48
|
def current_state
|
59
|
-
|
60
|
-
state = Senec::Value.new(value).to_i
|
49
|
+
state = get('STATISTIC', 'CURRENT_STATE')
|
61
50
|
|
62
51
|
STATE_NAMES[state]
|
63
52
|
end
|
64
53
|
|
65
54
|
def measure_time
|
66
|
-
|
67
|
-
Senec::Value.new(value).to_i
|
55
|
+
get('STATISTIC', 'MEASURE_TIME')
|
68
56
|
end
|
69
57
|
|
70
58
|
private
|
71
59
|
|
60
|
+
def get(*keys)
|
61
|
+
value = response.dig(*keys)
|
62
|
+
|
63
|
+
if value.is_a?(Array)
|
64
|
+
value.map do |v|
|
65
|
+
Senec::Value.new(v).decoded
|
66
|
+
end
|
67
|
+
else
|
68
|
+
Senec::Value.new(value).decoded
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
72
|
def response
|
73
73
|
@response ||= begin
|
74
|
-
res =
|
74
|
+
res = HTTP.post uri, json: Senec::BASIC_REQUEST
|
75
75
|
|
76
|
-
|
77
|
-
when Net::HTTPOK
|
76
|
+
if res.status.success?
|
78
77
|
JSON.parse(res.body)
|
79
78
|
else
|
80
79
|
throw "Failure: #{res.value}"
|
data/lib/senec/value.rb
CHANGED
@@ -4,37 +4,35 @@ module Senec
|
|
4
4
|
@data = data
|
5
5
|
end
|
6
6
|
|
7
|
-
def
|
8
|
-
decoded_value
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_i
|
12
|
-
decoded_value.round
|
13
|
-
end
|
14
|
-
|
15
|
-
private
|
16
|
-
|
17
|
-
def decoded_value
|
7
|
+
def decoded
|
18
8
|
parts = @data.split('_')
|
19
9
|
prefix = parts[0]
|
20
10
|
value = parts[1]
|
21
11
|
|
22
12
|
case prefix
|
23
13
|
when 'fl'
|
24
|
-
|
25
|
-
when 'i3', 'u1', 'u3'
|
26
|
-
|
14
|
+
decoded_float(value)
|
15
|
+
when 'i3', 'u1', 'u3', 'u6', 'u8'
|
16
|
+
decoded_int(value)
|
17
|
+
when 'st'
|
18
|
+
value
|
27
19
|
# TODO: There are some more prefixes to handle
|
28
20
|
else
|
29
|
-
raise ArgumentError, "#{@data}
|
21
|
+
raise ArgumentError, "#{@data} has unknown prefix!"
|
30
22
|
end
|
31
23
|
end
|
32
24
|
|
33
|
-
|
25
|
+
alias to_i decoded
|
26
|
+
alias to_f decoded
|
27
|
+
alias to_s decoded
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def decoded_float(hex)
|
34
32
|
["0x#{hex}".to_i(16)].pack('L').unpack1('F').round(1)
|
35
33
|
end
|
36
34
|
|
37
|
-
def
|
35
|
+
def decoded_int(hex)
|
38
36
|
"0x#{hex}".to_i(16)
|
39
37
|
end
|
40
38
|
end
|
data/lib/senec/version.rb
CHANGED
data/senec.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
10
10
|
spec.description = 'Access your local SENEC Solar Battery Storage System'
|
11
11
|
spec.homepage = 'https://github.com/solectrus/senec'
|
12
12
|
spec.license = 'MIT'
|
13
|
-
spec.required_ruby_version = Gem::Requirement.new('>= 2.
|
13
|
+
spec.required_ruby_version = Gem::Requirement.new('>= 2.7.0')
|
14
14
|
|
15
15
|
spec.metadata['homepage_uri'] = spec.homepage
|
16
16
|
spec.metadata['source_code_uri'] = 'https://github.com/solectrus/senec'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: senec
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Georg Ledermann
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-11-13 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Access your local SENEC Solar Battery Storage System
|
14
14
|
email:
|
@@ -21,6 +21,7 @@ files:
|
|
21
21
|
- ".gitignore"
|
22
22
|
- ".rspec"
|
23
23
|
- ".rubocop.yml"
|
24
|
+
- ".vscode/settings.json"
|
24
25
|
- CODE_OF_CONDUCT.md
|
25
26
|
- Gemfile
|
26
27
|
- LICENSE.txt
|
@@ -50,14 +51,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
50
51
|
requirements:
|
51
52
|
- - ">="
|
52
53
|
- !ruby/object:Gem::Version
|
53
|
-
version: 2.
|
54
|
+
version: 2.7.0
|
54
55
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
55
56
|
requirements:
|
56
57
|
- - ">="
|
57
58
|
- !ruby/object:Gem::Version
|
58
59
|
version: '0'
|
59
60
|
requirements: []
|
60
|
-
rubygems_version: 3.3.
|
61
|
+
rubygems_version: 3.3.25
|
61
62
|
signing_key:
|
62
63
|
specification_version: 4
|
63
64
|
summary: Unofficial Ruby Client for SENEC Home
|