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 Mercedes #2259

Merged
merged 46 commits into from
Jan 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
46 commits
Select commit Hold shift + click to select a range
cc9b8c9
Add Mercedes api
andig Apr 28, 2021
1295b38
wip
andig Apr 28, 2021
4644a07
wip
andig Apr 28, 2021
e90e910
fix authorization code flow
Jan 10, 2022
4303b74
style
Jan 10, 2022
38168c7
style
Jan 10, 2022
7f52bdf
style
Jan 10, 2022
f085335
update
Jan 10, 2022
276a9d4
add comment
Jan 10, 2022
f8f8097
provide alogout
Jan 11, 2022
4bc60c7
style
Jan 11, 2022
e4d13e4
refactor
Jan 11, 2022
0c5441e
make ui
Jan 11, 2022
0213d46
Merge branch 'master' into feature/mercedes2
Jan 11, 2022
33a4aff
Merge branch 'master' into feature/mercedes2
Jan 11, 2022
72cd57b
go mod update
Jan 11, 2022
517f91c
cleanup
Jan 11, 2022
8a20b01
cleanup
Jan 11, 2022
d7f182c
make ui
Jan 11, 2022
103a372
Conditional login and language
Jan 11, 2022
39c3a14
cleanup
Jan 11, 2022
46ddff8
cleanup
Jan 11, 2022
3c6ac2b
revert observation_id_enumer
Jan 11, 2022
165cbfd
...
Jan 11, 2022
418b0c5
add site config
Jan 12, 2022
dd0fbf3
Merge branch 'master' into feature/mercedes2
Jan 13, 2022
dc6b07b
fix
Jan 13, 2022
82b1b43
fix
Jan 13, 2022
5a84ade
add missing identity
Jan 13, 2022
a74edd5
rm mux dependency
Jan 14, 2022
8db7ef4
Update .dockerignore
xantalor Jan 14, 2022
195eaca
Update dacia.yaml
xantalor Jan 14, 2022
131298d
axios update
Jan 15, 2022
267efb7
Merge branch 'feature/mercedes2' of github.com:evcc-io/evcc into feat…
Jan 15, 2022
cceccdf
rename
Jan 15, 2022
55a4551
update error message
Jan 15, 2022
985e5b8
build ui and move authapi
Jan 15, 2022
fd38394
lint
Jan 15, 2022
eb346a4
ling2
Jan 15, 2022
55356e5
update
Jan 17, 2022
6321099
introduce login menu
Jan 21, 2022
e34f14a
build production ui
Jan 21, 2022
71e32a1
small ui change
Jan 21, 2022
c7c344a
fix comments
Jan 21, 2022
65f12a6
refactor
Jan 21, 2022
3573df3
refactor
Jan 21, 2022
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
Prev Previous commit
Next Next commit
cleanup
  • Loading branch information
xantalor committed Jan 11, 2022
commit 46ddff8df84747e2f9c8425caad39ba07bae6416
4 changes: 2 additions & 2 deletions dist/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!DOCTYPE html><html lang="de"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="description" content="EV Charge Controller"><meta name="author" content="andig"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black"><link rel="apple-touch-icon" sizes="180x180" href="ico/apple-touch-icon.png?[[.Version]]"><link rel="icon" type="image/png" sizes="32x32" href="ico/favicon-32x32.png?[[.Version]]"><link rel="icon" type="image/png" sizes="16x16" href="ico/favicon-16x16.png?[[.Version]]"><link rel="manifest" href="ico/site.webmanifest"><link rel="mask-icon" href="ico/safari-pinned-tab.svg?[[.Version]]" color="#18191a"><link rel="shortcut icon" href="ico/favicon.ico?[[.Version]]"><meta name="apple-mobile-web-app-title" content="evcc"><meta name="application-name" content="evcc"><meta name="msapplication-TileColor" content="#18191a"><meta name="msapplication-config" content="ico/browserconfig.xml"><meta name="theme-color" content="#18191a"><title>evcc</title><link href="css/chunk-vendors.4692b1e2.css" rel="preload" as="style"><link href="css/index.def25fd4.css" rel="preload" as="style"><link href="js/chunk-vendors.323cc329.js" rel="preload" as="script"><link href="js/index.c40fd326.js" rel="preload" as="script"><link href="css/chunk-vendors.4692b1e2.css" rel="stylesheet"><link href="css/index.def25fd4.css" rel="stylesheet"></head><body><script>window.evcc = {
<!DOCTYPE html><html lang="de"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="description" content="EV Charge Controller"><meta name="author" content="andig"><meta name="apple-mobile-web-app-capable" content="yes"><meta name="apple-mobile-web-app-status-bar-style" content="black"><link rel="apple-touch-icon" sizes="180x180" href="ico/apple-touch-icon.png?[[.Version]]"><link rel="icon" type="image/png" sizes="32x32" href="ico/favicon-32x32.png?[[.Version]]"><link rel="icon" type="image/png" sizes="16x16" href="ico/favicon-16x16.png?[[.Version]]"><link rel="manifest" href="ico/site.webmanifest"><link rel="mask-icon" href="ico/safari-pinned-tab.svg?[[.Version]]" color="#18191a"><link rel="shortcut icon" href="ico/favicon.ico?[[.Version]]"><meta name="apple-mobile-web-app-title" content="evcc"><meta name="application-name" content="evcc"><meta name="msapplication-TileColor" content="#18191a"><meta name="msapplication-config" content="ico/browserconfig.xml"><meta name="theme-color" content="#18191a"><title>evcc</title><link href="css/chunk-vendors.4692b1e2.css" rel="preload" as="style"><link href="css/index.def25fd4.css" rel="preload" as="style"><link href="js/chunk-vendors.323cc329.js" rel="preload" as="script"><link href="js/index.9a8e8b56.js" rel="preload" as="script"><link href="css/chunk-vendors.4692b1e2.css" rel="stylesheet"><link href="css/index.def25fd4.css" rel="stylesheet"></head><body><script>window.evcc = {
version: "[[.Version]]",
configured: "[[.Configured]]",
commit: "[[.Commit]]",
};</script><div id="app"></div><script src="js/chunk-vendors.323cc329.js"></script><script src="js/index.c40fd326.js"></script></body></html>
};</script><div id="app"></div><script src="js/chunk-vendors.323cc329.js"></script><script src="js/index.9a8e8b56.js"></script></body></html>
2 changes: 1 addition & 1 deletion dist/js/index.c40fd326.js → dist/js/index.9a8e8b56.js

Large diffs are not rendered by default.

Large diffs are not rendered by default.

28 changes: 12 additions & 16 deletions vehicle/mercedes.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,11 @@ import (
"github.com/evcc-io/evcc/api"
"github.com/evcc-io/evcc/util"
"github.com/evcc-io/evcc/vehicle/mercedes"
"golang.org/x/oauth2"
)

// Mercedes is an api.Vehicle implementation for Mercedes cars
type Mercedes struct {
*embed
*mercedes.Identity
*mercedes.Provider
}

Expand All @@ -27,7 +25,6 @@ func NewMercedesFromConfig(other map[string]interface{}) (api.Vehicle, error) {
cc := struct {
embed `mapstructure:",squash"`
ClientID, ClientSecret string
Tokens Tokens
VIN string
Cache time.Duration
}{
Expand All @@ -38,21 +35,21 @@ func NewMercedesFromConfig(other map[string]interface{}) (api.Vehicle, error) {
return nil, err
}

// TODO: cc.Tokens should be moved to a persistence storage
// e.g. persistence.Load("key")

if cc.ClientID == "" && cc.Tokens.Refresh == "" {
if cc.ClientID == "" && cc.ClientSecret == "" {
return nil, errors.New("missing credentials")
}

var options []mercedes.ClientOption
if cc.Tokens.Refresh != "" {
options = append(options, mercedes.WithToken(&oauth2.Token{
AccessToken: cc.Tokens.Access,
RefreshToken: cc.Tokens.Refresh,
Expiry: time.Now(),
}))
}
var options []mercedes.IdentityOptions

// TODO: Load tokens from a persistence storage and use those during startup
// e.g. persistence.Load("key")
// if tokens != nil {
// options = append(options, mercedes.WithToken(&oauth2.Token{
// AccessToken: tokens.Access,
// RefreshToken: tokens.Refresh,
// Expiry: tokens.Expiry,
// }))
// }

log := util.NewLogger("mercedes")

Expand All @@ -68,7 +65,6 @@ func NewMercedesFromConfig(other map[string]interface{}) (api.Vehicle, error) {

v := &Mercedes{
embed: &cc.embed,
Identity: identity,
Provider: mercedes.NewProvider(api, strings.ToUpper(cc.VIN), cc.Cache),
}

Expand Down
6 changes: 3 additions & 3 deletions vehicle/mercedes/identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ import (
"golang.org/x/oauth2"
)

type ClientOption func(c *Identity) error
type IdentityOptions func(c *Identity) error

// WithToken provides an oauth2.Token to the client for auth.
func WithToken(t *oauth2.Token) ClientOption {
func WithToken(t *oauth2.Token) IdentityOptions {
return func(c *Identity) error {
c.token = t
return nil
Expand All @@ -41,7 +41,7 @@ type Identity struct {
}

// TODO: SessionSecret from config/persistence
func NewIdentity(log *util.Logger, id, secret string, loginUpdateC chan struct{}, options ...ClientOption) (*Identity, error) {
func NewIdentity(log *util.Logger, id, secret string, loginUpdateC chan struct{}, options ...IdentityOptions) (*Identity, error) {
var err error
provider, err := oidc.NewProvider(context.Background(), "https://id.mercedes-benz.com")
xantalor marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
Expand Down