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

Subscriptions to triggers do not work anymore after reconnect #555

Open
FlorianLoch opened this issue Dec 4, 2024 · 1 comment
Open

Comments

@FlorianLoch
Copy link

I have some code that connects to my local HA instance via (which actually results in an odd error when the instance is not reachable, but that's another issue):

  const connection = await createConnection({
    auth: createLongLivedTokenAuth(cfg.homeAssistantURL, cfg.longLivedToken),
  });

Then, I register to some triggers:

connection.subscribeMessage(
          (_) => {
            ...
          },
          {
            type: "subscribe_trigger",
            trigger: {
              ...button.on.trigger,
            },
          },
          { resubscribe: true },
        ),
      );

This works fine until I, for whatever reason, restart my HA instance. I added some logging to the disconnected and ready callbacks and it appears to me, that the reconnect is working. But I do not get any further messages for my subscriptions.

So I am wondering, whether they do not get re-subscribed after the reconnect? Or that HA isn't ready to handle these subscribe_trigger messages correctly while still starting up?

I would appreciate some ideas on this.

@FlorianLoch
Copy link
Author

I did some more research, requesting the /api/config continuously while restarting Home Assistant. Connecting via websocket while state is still NOT_RUNNING or STARTING works - but then the callbacks registered to some triggers are never called. Subscribing when state is RUNNING works as expected. But, and that is really unfortunate, it does not work when state just switched to RUNNING...

Otherwise, not using the the reconnect mechanism and instead polling the /api/config endpoint and waiting for "the right time" to connect would have been a feasible workaround - but adding "wait for 30s after state became RUNNING" does feel really hacky...

Any insights that might confirm or reject my obervations?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant