sunnycarcharger-agent 1.1.0 → 1.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +5 -1
- data/exe/sunnycarcharger-agent +7 -3
- data/lib/sunnycarcharger/agent/config.rb +11 -0
- data/lib/sunnycarcharger/agent/fronius.rb +23 -13
- data/lib/sunnycarcharger/agent/invertor_data.rb +2 -0
- data/lib/sunnycarcharger/agent/version.rb +1 -1
- data/test/sunnycarcharger/agent/fronius_test.rb +6 -4
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e597967d1cfd8c1ee46871b7a305827914023f8beeb15e79b3a6aaf1b0682d1b
|
4
|
+
data.tar.gz: d59ea067d905fc3f28b5c25f330bf91351bd41574fd8eb8b3030799417633fb0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 71a65178b4a571925bed92ef6b3cc4b59a9804ae3e9dde69def469183a666c23535e417e6f33da634c33f817e1502199bc22089b1c0db3bd2aed0bc045dc56d8
|
7
|
+
data.tar.gz: 1b2a926d280593da53996986ed39d8e32c9b6a99393560321b9a1c3044b1990262afb016e31c5850b0382cbbb4929a70e173ec4d5dc1dbb72fd27a5a8b842a41
|
data/README.md
CHANGED
@@ -20,9 +20,13 @@ gem install sunnycarcharger-agent
|
|
20
20
|
## Usage
|
21
21
|
|
22
22
|
```plain
|
23
|
-
FRONIUS_IP=192.168.1.2 WEB_TOKEN=<token from sunnycarcharger.com> sunnycarcharger-agent
|
23
|
+
FRONIUS_IP=192.168.1.2:5757 WEB_TOKEN=<token from sunnycarcharger.com> sunnycarcharger-agent
|
24
|
+
# or
|
25
|
+
FRONIUS_IPS=192.168.1.2:5757,192.168.1.3:5757 WEB_TOKEN=<token from sunnycarcharger.com> sunnycarcharger-agent
|
24
26
|
```
|
25
27
|
|
28
|
+
Use either `$FRONIUS_IPS` or `$FRONIUS_IP` to provide a comma separated list of IP address that the Fronius inverter might be available on. Include the `:port` if its not the default port of `80`.
|
29
|
+
|
26
30
|
## License
|
27
31
|
|
28
32
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/exe/sunnycarcharger-agent
CHANGED
@@ -2,14 +2,16 @@
|
|
2
2
|
|
3
3
|
require "sunnycarcharger/agent"
|
4
4
|
|
5
|
-
puts "Fronius IP
|
5
|
+
puts "Fronius IP addresses: #{Config.fronius_ips.join(", ")}"
|
6
6
|
puts "Web URL: #{Config.web_url}"
|
7
7
|
|
8
8
|
startup_errors = false
|
9
9
|
|
10
10
|
fronius_client = Sunnycarcharger::Agent::Fronius.new
|
11
11
|
unless fronius_client.connected?
|
12
|
-
|
12
|
+
Config.fronius_ips.each do |ip|
|
13
|
+
warn "ERROR: Fronius #{ip} could not be connected"
|
14
|
+
end
|
13
15
|
startup_errors = true
|
14
16
|
end
|
15
17
|
web_client = Sunnycarcharger::Agent::Web.new
|
@@ -24,7 +26,9 @@ loop do
|
|
24
26
|
begin
|
25
27
|
invertor_data = fronius_client.fetch
|
26
28
|
rescue Faraday::ConnectionFailed, Errno::ECONNREFUSED
|
27
|
-
|
29
|
+
Config.fronius_ips.each do |ip|
|
30
|
+
warn "ERROR: Fronius #{ip} could not be connected"
|
31
|
+
end
|
28
32
|
end
|
29
33
|
|
30
34
|
begin
|
@@ -8,12 +8,23 @@ class AgentConfig < Anyway::Config
|
|
8
8
|
attr_config refresh_interval: 1 # minutes
|
9
9
|
|
10
10
|
attr_config :fronius_ip
|
11
|
+
attr_config fronius_ips: []
|
11
12
|
|
12
13
|
extend_options do |parser, config|
|
13
14
|
parser.on_tail "-h", "--help" do
|
14
15
|
puts parser
|
15
16
|
end
|
16
17
|
end
|
18
|
+
|
19
|
+
on_load do
|
20
|
+
if fronius_ip
|
21
|
+
if fronius_ip.is_a?(Array)
|
22
|
+
self.fronius_ips = fronius_ip
|
23
|
+
elsif fronius_ip.is_a?(String)
|
24
|
+
self.fronius_ips = [fronius_ip]
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
17
28
|
end
|
18
29
|
|
19
30
|
Config = AgentConfig.new
|
@@ -1,22 +1,31 @@
|
|
1
1
|
require "faraday"
|
2
2
|
|
3
3
|
class Sunnycarcharger::Agent::Fronius
|
4
|
-
def initialize(
|
5
|
-
raise ArgumentError, "Missing Fronius IP
|
6
|
-
@
|
4
|
+
def initialize(ips: Config.fronius_ips)
|
5
|
+
raise ArgumentError, "Missing Fronius IP addresses" unless ips
|
6
|
+
@ips = ips
|
7
7
|
end
|
8
8
|
|
9
9
|
def client
|
10
|
-
@client ||=
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
10
|
+
@client ||= begin
|
11
|
+
successful_client = nil
|
12
|
+
@ips.find do |ip|
|
13
|
+
successful_client = Faraday.new(
|
14
|
+
"http://" + ip,
|
15
|
+
headers: {"User-Agent" => "sunnycarcharger-agent"}
|
16
|
+
) do |conn|
|
17
|
+
conn.request :json
|
18
|
+
conn.response :json
|
19
|
+
conn.response :raise_error
|
20
|
+
# conn.request :retry, retry_options if retry_options # Must be registered after :raise_error
|
21
|
+
conn.adapter Faraday.default_adapter
|
22
|
+
conn.options.timeout = 3
|
23
|
+
end
|
24
|
+
true
|
25
|
+
rescue Faraday::ConnectionFailed, Errno::ECONNREFUSED
|
26
|
+
false
|
27
|
+
end
|
28
|
+
successful_client || raise("Could not connect to any of the provided Fronius IP addresses")
|
20
29
|
end
|
21
30
|
end
|
22
31
|
|
@@ -35,6 +44,7 @@ class Sunnycarcharger::Agent::Fronius
|
|
35
44
|
body = response.dig("Body", "Data", "0")
|
36
45
|
data.energy_consumed = body.dig("EnergyReal_WAC_Sum_Consumed").to_i
|
37
46
|
data.energy_produced = body.dig("EnergyReal_WAC_Sum_Produced").to_i
|
47
|
+
data.serial = body.dig("Details", "Serial")
|
38
48
|
rescue => e
|
39
49
|
puts "Error fetching energy_consumed and energy_produced: #{e}"
|
40
50
|
end
|
@@ -1,4 +1,5 @@
|
|
1
1
|
class Sunnycarcharger::Agent::InvertorData
|
2
|
+
attr_accessor :serial
|
2
3
|
attr_accessor :power_from_grid, :power_to_load, :power_from_solar, :solar_energy_today
|
3
4
|
attr_accessor :energy_consumed, :energy_produced
|
4
5
|
|
@@ -8,6 +9,7 @@ class Sunnycarcharger::Agent::InvertorData
|
|
8
9
|
|
9
10
|
def as_json
|
10
11
|
{
|
12
|
+
serial: serial,
|
11
13
|
power_from_grid: power_from_grid,
|
12
14
|
power_to_load: power_to_load,
|
13
15
|
power_from_solar: power_from_solar,
|
@@ -4,8 +4,8 @@ require "test_helper"
|
|
4
4
|
|
5
5
|
describe Sunnycarcharger::Agent::Fronius do
|
6
6
|
it "fetches from fronius" do
|
7
|
-
|
8
|
-
agent = Sunnycarcharger::Agent::Fronius.new(
|
7
|
+
fronius_ips = ["192.168.86.26"]
|
8
|
+
agent = Sunnycarcharger::Agent::Fronius.new(ips: fronius_ips)
|
9
9
|
VCR.use_cassette("fronius-midday") do
|
10
10
|
data = agent.fetch
|
11
11
|
|
@@ -14,14 +14,15 @@ describe Sunnycarcharger::Agent::Fronius do
|
|
14
14
|
assert_equal(6444, data.power_from_solar.to_i)
|
15
15
|
assert_equal(2844, data.power_to_load.to_i)
|
16
16
|
assert_equal(38601, data.solar_energy_today.to_i)
|
17
|
+
assert_equal("745995", data.serial)
|
17
18
|
assert data.energy_consumed
|
18
19
|
assert data.energy_produced
|
19
20
|
end
|
20
21
|
end
|
21
22
|
|
22
23
|
it "fetches from fronius at night" do
|
23
|
-
|
24
|
-
agent = Sunnycarcharger::Agent::Fronius.new(
|
24
|
+
fronius_ips = ["192.168.86.26"]
|
25
|
+
agent = Sunnycarcharger::Agent::Fronius.new(ips: fronius_ips)
|
25
26
|
VCR.use_cassette("fronius-night") do
|
26
27
|
data = agent.fetch
|
27
28
|
|
@@ -29,6 +30,7 @@ describe Sunnycarcharger::Agent::Fronius do
|
|
29
30
|
assert_equal(0, data.power_from_solar.to_i)
|
30
31
|
assert_equal(335, data.power_to_load.to_i)
|
31
32
|
assert_equal(62134, data.solar_energy_today.to_i)
|
33
|
+
assert_equal("745995", data.serial)
|
32
34
|
assert data.energy_consumed
|
33
35
|
assert data.energy_produced
|
34
36
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sunnycarcharger-agent
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dr Nic Williams
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: anyway_config
|
@@ -129,7 +129,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
129
129
|
- !ruby/object:Gem::Version
|
130
130
|
version: '0'
|
131
131
|
requirements: []
|
132
|
-
rubygems_version: 3.4.
|
132
|
+
rubygems_version: 3.4.20
|
133
133
|
signing_key:
|
134
134
|
specification_version: 4
|
135
135
|
summary: Run agent within home network to get solar invertor data and upload to Sunny
|