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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 74fbebb7d35be601f1f1c0f5c2bf102f71fbf5c571e709fb86253de8025dc02c
4
- data.tar.gz: '008397000fb1cf8cac6c17e4cf427fa5f1a6a0f904b1968cc6d02b2c8bd6052c'
3
+ metadata.gz: e597967d1cfd8c1ee46871b7a305827914023f8beeb15e79b3a6aaf1b0682d1b
4
+ data.tar.gz: d59ea067d905fc3f28b5c25f330bf91351bd41574fd8eb8b3030799417633fb0
5
5
  SHA512:
6
- metadata.gz: b2093e938beaa6e0a89f540505ba364aeb975343cd5f8eb5bd03df2dba77006c6ae189c0993f83bc9cfb71dce49a358cd3bc057b42c10c01a684010144f99d6b
7
- data.tar.gz: abc63c83d4a0d46305b22a2f264649cfa0ebe7b2520e96c8c56e1f498d6bfdf77058a16684596b60bc1299d7f82008327e3939986bb11498500ee14a01790103
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).
@@ -2,14 +2,16 @@
2
2
 
3
3
  require "sunnycarcharger/agent"
4
4
 
5
- puts "Fronius IP address: #{Config.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
- warn "ERROR: Fronius #{Config.fronius_ip} could not be connected"
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
- warn "ERROR: Fronius #{Config.fronius_ip} could not be connected"
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(ip: Config.fronius_ip)
5
- raise ArgumentError, "Missing Fronius IP address" unless ip
6
- @ip = ip
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 ||= Faraday.new(
11
- "http://" + @ip,
12
- headers: {"User-Agent" => "sunnycarcharger-agent"}
13
- ) do |conn|
14
- conn.request :json
15
- conn.response :json
16
- conn.response :raise_error
17
- # conn.request :retry, retry_options if retry_options # Must be registered after :raise_error
18
- conn.adapter Faraday.default_adapter
19
- conn.options.timeout = 3
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,
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Sunnycarcharger
4
4
  module Agent
5
- VERSION = "1.1.0"
5
+ VERSION = "1.1.1"
6
6
  end
7
7
  end
@@ -4,8 +4,8 @@ require "test_helper"
4
4
 
5
5
  describe Sunnycarcharger::Agent::Fronius do
6
6
  it "fetches from fronius" do
7
- fronius_ip = "192.168.86.26"
8
- agent = Sunnycarcharger::Agent::Fronius.new(ip: fronius_ip)
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
- fronius_ip = "192.168.86.26"
24
- agent = Sunnycarcharger::Agent::Fronius.new(ip: fronius_ip)
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.0
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-07-30 00:00:00.000000000 Z
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.17
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