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

Tibber: resubscribe on clean disconnect #18643

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

GrimmiMeloni
Copy link
Collaborator

fix #17925

Resubscribes in case of a clean exit.

@GrimmiMeloni
Copy link
Collaborator Author

@andig I refactored the existing subscription logic into a function (subscribe), and added an optional unsubscribe to it (in case we have a subscriptionId from a previous subscribe).

For the reconnect loop, I am using the presence of an error to decide wether to just restart Run() or also additionally re-subscribe. Maybe we can also get rid of that decision by simply always resubscribing? WDYT?

@GrimmiMeloni GrimmiMeloni self-assigned this Feb 6, 2025
@GrimmiMeloni GrimmiMeloni added the bug Something isn't working label Feb 6, 2025
@GrimmiMeloni GrimmiMeloni requested a review from andig February 6, 2025 21:10
@@ -133,18 +122,56 @@ func NewTibberFromConfig(ctx context.Context, other map[string]interface{}) (api
case <-ctx.Done():
return
}

if err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we do this above in the first if?

}
}()

return t, nil
}

func subscribe(t *Tibber, client *graphql.SubscriptionClient, cc struct {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we should use the actual parameters instead of anonymous struct type.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

und kann das nicht eine Methode vom Pulse sein?

}) error {
if t.subscriptionId != "" {
if err := client.Unsubscribe(t.subscriptionId); err != nil {
return err
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log statt return? Die mag ja schon stale sein?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ich wäre sogar dafür, das im ersten Schritte einfach weg zu lassen. In allen Fehlern die wir kennen hat uns ja der Server schon die Subscription entzogen.

}
case <-time.After(cc.Timeout):
return nil, api.ErrTimeout
if err := subscribe(t, client, cc); err != nil {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Den Begriff "subscribe" haben wir jetzt 2x

@andig
Copy link
Member

andig commented Feb 7, 2025

Ich habs nicht versucht im Detail zu verstehen, aber die Idee ist klar- bin gespannt...

@andig
Copy link
Member

andig commented Feb 9, 2025

ping @GrimmiMeloni

@GrimmiMeloni
Copy link
Collaborator Author

Sorry. Gerade unpässlich 🤒

@andig
Copy link
Member

andig commented Feb 9, 2025

Ohje- gute Besserung!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Tibber: evcc hängt nach kurzzeitigem Ausfall von Tibber
2 participants