Skip to content
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
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
6 changes: 4 additions & 2 deletions api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import (
"io"
"net/url"
"time"

"github.com/evcc-io/evcc/api/internal"
)

//go:generate go tool mockgen -package api -destination mock.go github.com/evcc-io/evcc/api Charger,ChargeState,CurrentLimiter,CurrentGetter,PhaseSwitcher,PhaseGetter,FeatureDescriber,Identifier,Meter,MeterEnergy,PhaseCurrents,Vehicle,ChargeRater,Battery,BatteryController,BatterySocLimiter,Circuit,Tariff

var ContextTitle internal.ContextKey

// Meter provides total active power in W
type Meter interface {
CurrentPower() (float64, error)
Expand Down Expand Up @@ -140,11 +144,9 @@ type PhaseDescriber interface {
type Vehicle interface {
Battery
BatteryCapacity
IconDescriber
FeatureDescriber
PhaseDescriber
TitleDescriber
SetTitle(string)
Identifiers() []string
OnIdentified() ActionConfig
}
Expand Down
6 changes: 6 additions & 0 deletions api/internal/context.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package internal

// ContextKey is just an empty struct. It exists so context keys can be
// an immutable public variable with a unique type. It's immutable
// because nobody else can create a ContextKey, being unexported.
type ContextKey struct{}
5 changes: 3 additions & 2 deletions cmd/soc/main.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package main

import (
"context"
"fmt"
"log"
"math"
Expand Down Expand Up @@ -34,7 +35,7 @@ func main() {
log.Fatal("not enough arguments")
}

params := make(map[string]interface{})
params := make(map[string]any)
params["brand"] = strings.ToLower(os.Args[1])

action := "soc"
Expand Down Expand Up @@ -65,7 +66,7 @@ func main() {
log.Fatal("unexpected number of parameters")
}

v, err := vehicle.NewCloudFromConfig(params)
v, err := vehicle.NewCloudFromConfig(context.Background(), params)
if err != nil {
log.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion core/site/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (
type API interface {
Healthy() bool
Loadpoints() []loadpoint.API
Vehicles() Vehicles
// Vehicles() Vehicles

// Meta
GetTitle() string
Expand Down
61 changes: 29 additions & 32 deletions core/site_vehicles.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ import (

"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/core/keys"
"github.com/evcc-io/evcc/core/site"
"github.com/evcc-io/evcc/core/vehicle"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/util/config"
"github.com/samber/lo"
)
Expand Down Expand Up @@ -49,8 +46,8 @@ func (site *Site) publishVehicles() {
ac := instance.OnIdentified()

res[v.Name()] = vehicleStruct{
Title: instance.GetTitle(),
Icon: instance.Icon(),
Title: instance.GetTitle(),
// Icon: instance.Icon(),
Capacity: instance.Capacity(),
Phases: instance.Phases(),
MinSoc: v.GetMinSoc(),
Expand Down Expand Up @@ -87,39 +84,39 @@ func (site *Site) updateVehicles(op config.Operation, dev config.Device[api.Vehi
site.publishVehicles()
}

var _ site.Vehicles = (*vehicles)(nil)
// var _ site.Vehicles = (*vehicles)(nil)

type vehicles struct {
log *util.Logger
}
// type vehicles struct {
// log *util.Logger
// }

func (vv *vehicles) Instances() []api.Vehicle {
devs := config.Vehicles().Devices()
// func (vv *vehicles) Instances() []api.Vehicle {
// devs := config.Vehicles().Devices()

res := make([]api.Vehicle, 0, len(devs))
for _, dev := range devs {
res = append(res, dev.Instance())
}
// res := make([]api.Vehicle, 0, len(devs))
// for _, dev := range devs {
// res = append(res, dev.Instance())
// }

return res
}
// return res
// }

func (vv *vehicles) Settings() []vehicle.API {
devs := config.Vehicles().Devices()
// func (vv *vehicles) Settings() []vehicle.API {
// devs := config.Vehicles().Devices()

res := make([]vehicle.API, 0, len(devs))
for _, dev := range devs {
res = append(res, vehicle.Adapter(vv.log, dev))
}
// res := make([]vehicle.API, 0, len(devs))
// for _, dev := range devs {
// res = append(res, vehicle.Adapter(vv.log, dev))
// }

return res
}
// return res
// }

func (vv *vehicles) ByName(name string) (vehicle.API, error) {
dev, err := config.Vehicles().ByName(name)
if err != nil {
return nil, err
}
// func (vv *vehicles) ByName(name string) (vehicle.API, error) {
// dev, err := config.Vehicles().ByName(name)
// if err != nil {
// return nil, err
// }

return vehicle.Adapter(vv.log, dev), nil
}
// return vehicle.Adapter(vv.log, dev), nil
// }
1 change: 0 additions & 1 deletion push/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ func (h *Hub) apply(ev Event, tmpl string) (string, error) {

instance := v.Instance()
attr["vehicleTitle"] = instance.GetTitle()
attr["vehicleIcon"] = instance.Icon()
attr["vehicleCapacity"] = instance.Capacity()
}
}
Expand Down
4 changes: 2 additions & 2 deletions util/templates/defaults.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -485,9 +485,9 @@ presets:
vehicle-common:
params:
- name: title
deprecated: true
- name: icon
default: car
advanced: true
deprecated: true
- name: capacity
- name: phases
advanced: true
Expand Down
6 changes: 0 additions & 6 deletions util/templates/includes/vehicle-common.tpl
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
{{ define "vehicle-common" }}
{{- if .title }}
title: {{ .title }}
{{- end }}
{{- if .icon }}
icon: {{ .icon }}
{{- end }}
{{- if .capacity }}
capacity: {{ .capacity }}
{{- end }}
Expand Down
7 changes: 4 additions & 3 deletions vehicle/aiways.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vehicle

import (
"context"
"strconv"
"time"

Expand All @@ -20,11 +21,11 @@ type Aiways struct {
}

func init() {
registry.Add("aiways", NewAiwaysFromConfig)
registry.AddCtx("aiways", NewAiwaysFromConfig)
}

// NewAiwaysFromConfig creates a new vehicle
func NewAiwaysFromConfig(other map[string]interface{}) (api.Vehicle, error) {
func NewAiwaysFromConfig(ctx context.Context, other map[string]interface{}) (api.Vehicle, error) {
cc := struct {
embed `mapstructure:",squash"`
User, Password, VIN string
Expand All @@ -44,7 +45,7 @@ func NewAiwaysFromConfig(other map[string]interface{}) (api.Vehicle, error) {
}

v := &Aiways{
embed: &cc.embed,
embed: cc.embed.withContext(ctx),
}

log := util.NewLogger("aiways").Redact(cc.User, cc.Password, cc.VIN)
Expand Down
8 changes: 3 additions & 5 deletions vehicle/audi.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,11 @@ type Audi struct {
}

func init() {
registry.Add("audi", NewAudiFromConfig)
registry.Add("etron", NewAudiFromConfig)
registry.AddCtx("audi", NewAudiFromConfig)
}

// NewAudiFromConfig creates a new vehicle
func NewAudiFromConfig(other map[string]interface{}) (api.Vehicle, error) {
func NewAudiFromConfig(ctx context.Context, other map[string]interface{}) (api.Vehicle, error) {
cc := struct {
embed `mapstructure:",squash"`
User, Password, VIN string
Expand All @@ -49,7 +48,7 @@ func NewAudiFromConfig(other map[string]interface{}) (api.Vehicle, error) {
}

v := &Audi{
embed: &cc.embed,
embed: cc.embed.withContext(ctx),
}

log := util.NewLogger("audi").Redact(cc.User, cc.Password, cc.VIN)
Expand Down Expand Up @@ -85,7 +84,6 @@ func NewAudiFromConfig(other map[string]interface{}) (api.Vehicle, error) {
api := id.NewAPI(log, its)
api.Client.Timeout = cc.Timeout

v.fromVehicle(vehicle.Nickname, 0)
v.Provider = id.NewProvider(api, vehicle.VIN, cc.Cache)
}

Expand Down
17 changes: 9 additions & 8 deletions vehicle/bluelink.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vehicle

import (
"context"
"time"

"github.com/evcc-io/evcc/api"
Expand All @@ -18,12 +19,12 @@ type Bluelink struct {
}

func init() {
registry.Add("kia", NewKiaFromConfig)
registry.Add("hyundai", NewHyundaiFromConfig)
registry.AddCtx("kia", NewKiaFromConfig)
registry.AddCtx("hyundai", NewHyundaiFromConfig)
}

// NewHyundaiFromConfig creates a new vehicle
func NewHyundaiFromConfig(other map[string]interface{}) (api.Vehicle, error) {
func NewHyundaiFromConfig(ctx context.Context, other map[string]interface{}) (api.Vehicle, error) {
settings := bluelink.Config{
URI: "https://prd.eu-ccapi.hyundai.com:8080",
BasicToken: "NmQ0NzdjMzgtM2NhNC00Y2YzLTk1NTctMmExOTI5YTk0NjU0OktVeTQ5WHhQekxwTHVvSzB4aEJDNzdXNlZYaG10UVI5aVFobUlGampvWTRJcHhzVg==",
Expand All @@ -40,11 +41,11 @@ func NewHyundaiFromConfig(other map[string]interface{}) (api.Vehicle, error) {
// BrandAuthUrl: "%s/auth/api/v2/user/oauth2/authorize?response_type=code&client_id=%s&redirect_uri=%s/api/v1/user/oauth2/redirect&lang=%s&state=ccsp",
}

return newBluelinkFromConfig("hyundai", other, settings)
return newBluelinkFromConfig(ctx, "hyundai", other, settings)
}

// NewKiaFromConfig creates a new vehicle
func NewKiaFromConfig(other map[string]interface{}) (api.Vehicle, error) {
func NewKiaFromConfig(ctx context.Context, other map[string]interface{}) (api.Vehicle, error) {
settings := bluelink.Config{
URI: "https://prd.eu-ccapi.kia.com:8080",
BasicToken: "ZmRjODVjMDAtMGEyZi00YzY0LWJjYjQtMmNmYjE1MDA3MzBhOnNlY3JldA==",
Expand All @@ -58,11 +59,11 @@ func NewKiaFromConfig(other map[string]interface{}) (api.Vehicle, error) {
Brand: "kia",
}

return newBluelinkFromConfig("kia", other, settings)
return newBluelinkFromConfig(ctx, "kia", other, settings)
}

// newBluelinkFromConfig creates a new Vehicle
func newBluelinkFromConfig(brand string, other map[string]interface{}, settings bluelink.Config) (api.Vehicle, error) {
func newBluelinkFromConfig(ctx context.Context, brand string, other map[string]interface{}, settings bluelink.Config) (api.Vehicle, error) {
cc := struct {
embed `mapstructure:",squash"`
User, Password string
Expand Down Expand Up @@ -100,7 +101,7 @@ func newBluelinkFromConfig(brand string, other map[string]interface{}, settings
}

v := &Bluelink{
embed: &cc.embed,
embed: cc.embed.withContext(ctx),
Provider: bluelink.NewProvider(api, vehicle, cc.Expiry, cc.Cache),
}

Expand Down
17 changes: 9 additions & 8 deletions vehicle/bmw.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vehicle

import (
"context"
"time"

"github.com/evcc-io/evcc/api"
Expand All @@ -15,22 +16,22 @@ type BMW struct {
}

func init() {
registry.Add("bmw", NewBMWFromConfig)
registry.Add("mini", NewMiniFromConfig)
registry.AddCtx("bmw", NewBMWFromConfig)
registry.AddCtx("mini", NewMiniFromConfig)
}

// NewBMWFromConfig creates a new vehicle
func NewBMWFromConfig(other map[string]interface{}) (api.Vehicle, error) {
return NewBMWMiniFromConfig("bmw", other)
func NewBMWFromConfig(ctx context.Context, other map[string]interface{}) (api.Vehicle, error) {
return NewBMWMiniFromConfig(ctx, "bmw", other)
}

// NewMiniFromConfig creates a new vehicle
func NewMiniFromConfig(other map[string]interface{}) (api.Vehicle, error) {
return NewBMWMiniFromConfig("mini", other)
func NewMiniFromConfig(ctx context.Context, other map[string]interface{}) (api.Vehicle, error) {
return NewBMWMiniFromConfig(ctx, "mini", other)
}

// NewBMWMiniFromConfig creates a new vehicle
func NewBMWMiniFromConfig(brand string, other map[string]interface{}) (api.Vehicle, error) {
func NewBMWMiniFromConfig(ctx context.Context, brand string, other map[string]interface{}) (api.Vehicle, error) {
cc := struct {
embed `mapstructure:",squash"`
User, Password, VIN string
Expand All @@ -51,7 +52,7 @@ func NewBMWMiniFromConfig(brand string, other map[string]interface{}) (api.Vehic
}

v := &BMW{
embed: &cc.embed,
embed: cc.embed.withContext(ctx),
}

log := util.NewLogger(brand).Redact(cc.User, cc.Password, cc.VIN)
Expand Down
2 changes: 1 addition & 1 deletion vehicle/cardata.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func NewCardataFromConfig(ctx context.Context, other map[string]interface{}) (ap
}

v := &Cardata{
embed: &cc.embed,
embed: cc.embed.withContext(ctx),
}

oc := cardata.Config
Expand Down
7 changes: 4 additions & 3 deletions vehicle/carwings.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vehicle

import (
"context"
"errors"
"fmt"
"net"
Expand Down Expand Up @@ -31,11 +32,11 @@ type CarWings struct {
}

func init() {
registry.Add("carwings", NewCarWingsFromConfig)
registry.AddCtx("carwings", NewCarWingsFromConfig)
}

// NewCarWingsFromConfig creates a new vehicle
func NewCarWingsFromConfig(other map[string]interface{}) (api.Vehicle, error) {
func NewCarWingsFromConfig(ctx context.Context, other map[string]interface{}) (api.Vehicle, error) {
cc := struct {
embed `mapstructure:",squash"`
User, Password, Region, VIN string
Expand Down Expand Up @@ -75,7 +76,7 @@ func NewCarWingsFromConfig(other map[string]interface{}) (api.Vehicle, error) {
}

v := &CarWings{
embed: &cc.embed,
embed: cc.embed.withContext(ctx),
user: cc.User,
password: cc.Password,
session: &carwings.Session{
Expand Down
Loading
Loading