Cardata: reduce logging (#24205)
This commit is contained in:
parent
cb53716b48
commit
3206fd6a20
2 changed files with 19 additions and 12 deletions
|
|
@ -12,7 +12,6 @@ import (
|
|||
mqtt "github.com/eclipse/paho.mqtt.golang"
|
||||
"github.com/eclipse/paho.mqtt.golang/packets"
|
||||
"github.com/evcc-io/evcc/util"
|
||||
"github.com/golang-jwt/jwt/v5"
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
|
|
@ -57,6 +56,16 @@ func (v *MqttConnector) Subscribe(vin string) <-chan StreamingMessage {
|
|||
return ch
|
||||
}
|
||||
|
||||
func (v *MqttConnector) Unsubscribe(vin string) {
|
||||
v.mu.Lock()
|
||||
defer v.mu.Unlock()
|
||||
|
||||
if ch, ok := v.subscriptions[vin]; ok {
|
||||
delete(v.subscriptions, vin)
|
||||
close(ch)
|
||||
}
|
||||
}
|
||||
|
||||
func (v *MqttConnector) run(ctx context.Context, ts oauth2.TokenSource) {
|
||||
bo := backoff.NewExponentialBackOff(backoff.WithMaxInterval(time.Minute))
|
||||
|
||||
|
|
@ -76,7 +85,7 @@ func (v *MqttConnector) run(ctx context.Context, ts oauth2.TokenSource) {
|
|||
v.log.ERROR.Println(err)
|
||||
|
||||
// don't reset backoff
|
||||
if errors.Is(err, packets.ErrorRefusedBadUsernameOrPassword) {
|
||||
if errors.Is(err, packets.ErrorRefusedBadUsernameOrPassword) || errors.Is(err, packets.ErrorRefusedNotAuthorised) {
|
||||
continue
|
||||
}
|
||||
}
|
||||
|
|
@ -89,14 +98,7 @@ func (v *MqttConnector) runMqtt(ctx context.Context, token *oauth2.Token) error
|
|||
gcid := TokenExtra(token, "gcid")
|
||||
idToken := TokenExtra(token, "id_token")
|
||||
|
||||
var claims jwt.RegisteredClaims
|
||||
parsed, err := jwt.ParseWithClaims(idToken, &claims, nil)
|
||||
if err != nil && !errors.Is(err, jwt.ErrTokenUnverifiable) {
|
||||
return fmt.Errorf("get %w for %s", err, idToken)
|
||||
}
|
||||
idExpiry, _ := parsed.Claims.GetExpirationTime()
|
||||
|
||||
v.log.DEBUG.Printf("connect streaming (using gcid %s/ id_token %s, IDT valid: %v, AT valid: %v)", gcid, idToken, idExpiry.Round(time.Second), token.Expiry.Round(time.Second))
|
||||
v.log.DEBUG.Printf("connect streaming (using gcid %s, id_token %s, valid: %v)", gcid, idToken, token.Expiry.Round(time.Second))
|
||||
|
||||
paho := mqtt.NewClient(
|
||||
mqtt.NewClientOptions().
|
||||
|
|
|
|||
|
|
@ -39,9 +39,14 @@ func NewProvider(ctx context.Context, log *util.Logger, api *API, ts oauth2.Toke
|
|||
streaming: make(map[string]StreamingData),
|
||||
}
|
||||
|
||||
go func() {
|
||||
mqtt := NewMqttConnector(ctx, log, clientID, ts)
|
||||
mqtt := NewMqttConnector(context.Background(), log, clientID, ts)
|
||||
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
mqtt.Unsubscribe(vin)
|
||||
}()
|
||||
|
||||
go func() {
|
||||
for msg := range mqtt.Subscribe(vin) {
|
||||
v.mu.Lock()
|
||||
maps.Copy(v.streaming, msg.Data)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue