Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Ostrom #16354

Merged
merged 39 commits into from
Nov 22, 2024
Merged
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
3fcdc5f
Added ostrom tariff
kscholty Sep 26, 2024
8ae3ddc
New name for template
kscholty Sep 27, 2024
0ab6018
Deleted file for test purposes
kscholty Sep 27, 2024
3232dcb
Merge branch 'master' into tariff/ostrom
kscholty Sep 27, 2024
8365d4e
Revert "Deleted file for test purposes"
kscholty Sep 27, 2024
294357b
Linted template
kscholty Sep 27, 2024
0e69d9d
Automatic query of Simply Fai porices using
kscholty Sep 28, 2024
bc999ac
Merge branch 'master' into tariff/ostrom
kscholty Sep 28, 2024
ccc644f
Merge branch 'master' into tariff/ostrom
kscholty Sep 28, 2024
c35535e
Merge branch 'master' into tariff/ostrom
kscholty Sep 29, 2024
9df719f
Merge branch 'master' into tariff/ostrom
kscholty Sep 29, 2024
04ec7a2
Merge branch 'tariff/ostrom' of https://github.com/kscholty/evcc into…
kscholty Sep 29, 2024
919456c
Merge branch 'master' into tariff/ostrom
kscholty Oct 23, 2024
21f02b6
Add "skip test"
kscholty Oct 25, 2024
14b240b
Merge branch 'evcc-io:master' into tariff/ostrom
kscholty Oct 25, 2024
3921912
Merge branch 'master' into tariff/ostrom
kscholty Oct 30, 2024
9c2c1ee
Merge branch 'master' into tariff/ostrom
kscholty Nov 4, 2024
08d3cbe
Merge branch 'evcc-io:master' into tariff/ostrom
kscholty Nov 8, 2024
60c2a7c
Implemented changes for review comments
kscholty Nov 8, 2024
89bffac
Update tariff/ostrom.go
kscholty Nov 9, 2024
edf5629
Apply suggestions from code review
kscholty Nov 9, 2024
a937584
Merge branch 'evcc-io:master' into tariff/ostrom
kscholty Nov 9, 2024
67a9016
Implewmented more change requests.
kscholty Nov 9, 2024
6a48b43
Implemented change requests
kscholty Nov 9, 2024
32471e1
fixed lint error
kscholty Nov 9, 2024
f3c6d97
Changed ContractId in config to int64
kscholty Nov 10, 2024
b729ef7
Merge branch 'master' into tariff/ostrom
kscholty Nov 11, 2024
a68c41c
Merge branch 'evcc-io:master' into tariff/ostrom
kscholty Nov 13, 2024
81759a3
Merge branch 'master' into tariff/ostrom
kscholty Nov 19, 2024
b3ee25d
Merge branch 'evcc-io:master' into tariff/ostrom
kscholty Nov 20, 2024
41ce2dd
Implemented suggested changes
kscholty Nov 20, 2024
dd6adb7
Fixed index problem
kscholty Nov 20, 2024
063ac59
Simplify
andig Nov 21, 2024
77a8919
Panic on invalid type
andig Nov 21, 2024
62536cb
Simplify
andig Nov 21, 2024
c14c2e3
Merge branch 'evcc-io:master' into tariff/ostrom
kscholty Nov 21, 2024
603d06f
Using append for dynamic tarriffs.
kscholty Nov 21, 2024
050401a
Update tariff/ostrom.go
kscholty Nov 21, 2024
c20aa92
Removed lint problem
kscholty Nov 21, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions tariff/ostrom.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func ensureContractEx(cid int64, contracts []ostrom.Contract) (ostrom.Contract,
return contracts[0], nil
}

return zero, fmt.Errorf("cannot find contract")
return zero, errors.New("cannot find contract")
}

func NewOstromFromConfig(other map[string]interface{}) (api.Tariff, error) {
Expand Down Expand Up @@ -98,10 +98,11 @@ func NewOstromFromConfig(other map[string]interface{}) (api.Tariff, error) {
if err != nil {
return nil, err
}
done := make(chan error)

t.contractType = contract.Product
andig marked this conversation as resolved.
Show resolved Hide resolved
t.zip = contract.Address.Zip

done := make(chan error)
if t.Type() == api.TariffTypePriceStatic {
t.cityId, err = t.getCityId()
if err != nil {
Expand Down Expand Up @@ -158,9 +159,9 @@ func (t *Ostrom) getFixedPrice() (float64, error) {
}

func (t *Ostrom) RefreshToken(_ *oauth2.Token) (*oauth2.Token, error) {
tokenURL := ostrom.URI_AUTH + "/oauth2/token"
dataReader := strings.NewReader("grant_type=client_credentials")
req, _ := request.New(http.MethodPost, tokenURL, dataReader, map[string]string{
uri := ostrom.URI_AUTH + "/oauth2/token"
data := url.Values{"grant_type": {"client_credentials"}}
req, _ := request.New(http.MethodPost, uri, strings.NewReader(data.Encode()), map[string]string{
"Authorization": t.basic,
"Content-Type": request.FormContent,
"Accept": request.JSONContent,
Expand All @@ -185,29 +186,28 @@ func (t *Ostrom) GetContracts() ([]ostrom.Contract, error) {
// Unfortunately, the API does not allow to query the price for these yet.
func (t *Ostrom) runStatic(done chan error) {
var once sync.Once
var err error
var marketprice float64

tick := time.NewTicker(time.Hour)
for ; true; <-tick.C {
kscholty marked this conversation as resolved.
Show resolved Hide resolved
marketprice, err = t.getFixedPrice()
if err == nil {
ts := now.BeginningOfDay().Local()
data := make(api.Rates, 48)
for i := range data {
data[i] = api.Rate{
Start: ts,
End: ts.Add(time.Hour),
Price: marketprice / 100.0,
}
ts = data[i].End
}
mergeRates(t.data, data)
once.Do(func() { close(done) })
} else {
price, err := t.getFixedPrice()
if err != nil {
once.Do(func() { done <- err })
t.log.ERROR.Println(err)
kscholty marked this conversation as resolved.
Show resolved Hide resolved
continue
}

data := make(api.Rates, 48)
for i := range data {
ts := now.BeginningOfDay().Add(time.Duration(i) * time.Hour)
kscholty marked this conversation as resolved.
Show resolved Hide resolved
data[i] = api.Rate{
Start: ts,
End: ts.Add(time.Hour),
Price: price / 100.0,
}
}

mergeRates(t.data, data)
once.Do(func() { close(done) })
}
}

Expand Down