-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add solcast support * Fix typo * Fix solcast with single site * Prefer "case" over "if" * Use .env.test.local to record solcast response * Cleanup Loop class, add test for 100% test coverage * Fix tests by adding fake solcast config --------- Co-authored-by: Georg Ledermann <[email protected]>
- Loading branch information
Showing
19 changed files
with
382 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# solcast.com configuration | ||
# https://toolkit.solcast.com.au/ | ||
|
||
# first, create a free account on https://toolkit.solcast.com.au/ and create a "site" for your PV system | ||
# up to two strings are supported, both will be assigned an ID that looks like "1234-5678-9abc-def0" | ||
|
||
# use solcast | ||
FORECAST_PROVIDER=solcast | ||
|
||
# copy api key from solcast account | ||
SOLCAST_APIKEY=secret-solcast-api-key | ||
SOLCAST_SITE=1111-2222-3333-4444 | ||
|
||
# Update interval in seconds (beware of the rate-limit!) | ||
FORECAST_INTERVAL=8640 | ||
|
||
# for multiple strings: | ||
# FORECAST_CONFIGURATIONS=2 | ||
# SOLCAST_0_SITE=1111-2222-3333-4444 | ||
# SOLCAST_1_SITE=5555-6666-7777-8888 | ||
|
||
# InfluxDB configuration | ||
INFLUX_HOST=eu-central-1-1.aws.cloud2.influxdata.com | ||
INFLUX_SCHEMA=https | ||
INFLUX_PORT=443 | ||
INFLUX_TOKEN=the-secret-token-from-influxdata | ||
[email protected] | ||
INFLUX_BUCKET=my-bucket-name | ||
INFLUX_MEASUREMENT=Forecast |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
.env | ||
.env* | ||
coverage/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
require 'net/http' | ||
require_relative 'config' | ||
require_relative 'forecast' | ||
|
||
class ForecastSolar < Forecast | ||
BASE_URL = 'https://api.forecast.solar'.freeze | ||
|
||
def uri(index) | ||
URI.parse(formatted_url(index)) | ||
end | ||
|
||
def current(index) | ||
# Change mapping: | ||
# "result": { | ||
# "watts": { | ||
# "1632979620": 0, | ||
# "1632984240": 28, | ||
# "1632988800": 119, | ||
# ..... | ||
# => | ||
# { 1632979620 => 0, 1632980640 => 28, 1632981600 => 119, ... } | ||
|
||
forecast_response(index).dig('result', 'watts').transform_keys(&:to_i) | ||
end | ||
|
||
private | ||
|
||
def base_url | ||
[BASE_URL, config.forecast_solar_apikey, 'estimate'].compact.join('/') | ||
end | ||
|
||
def raw_url | ||
"#{base_url}/:lat/:lon/:dec/:az/:kwp" \ | ||
'?damping=:damping_morning,:damping_evening' \ | ||
'&time=seconds' | ||
end | ||
|
||
def parameters(index) | ||
cfg = config.forecast_configurations[index] | ||
{ | ||
lat: cfg[:latitude], | ||
lon: cfg[:longitude], | ||
dec: cfg[:declination], | ||
az: cfg[:azimuth], | ||
kwp: cfg[:kwp], | ||
damping_morning: cfg[:damping_morning], | ||
damping_evening: cfg[:damping_evening], | ||
} | ||
end | ||
|
||
def formatted_url(index) | ||
raw_url.tap do |url| | ||
parameters(index).each { |key, value| url.sub!(":#{key}", value) } | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.