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

Fix logbook keeps loading #24351

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft

Conversation

silamon
Copy link
Contributor

@silamon silamon commented Feb 22, 2025

Proposed change

2 bug fixes for #24212 introduced after #23853. It's a bit the logic how it is handled that makes it hard to not break anything here along the line.

So, some sensors are continuous, and there's a short circuit in the backend that will provide an empty event straight away after subscription. But the event and the subscription are message wise sent together.
First bug appears that the event is pushed through before the subscription is finalized, and the event is being throw away for being too early according to the comment. I've added the promise to a temporary variable to ensure we know that events that come with the subscription are not being handled as too "early". The subscription promise will resolve shortly after.
Second bug appears on unsubscribing (whenever you change entities for example). The unsubscribe has already happened and the subscription is gone. Giving an error and failing to clean the UI state, resulting in the need to hard refresh.

The demo integration provides a "number.temperature_setting", which you can add on the logbook page.

  • Go to the logbook page
  • Add the "number.temperature_setting" => First bug
  • Remove the "number.temperature_setting" => Second bug

Type of change

  • Dependency upgrade
  • Bugfix (non-breaking change which fixes an issue)
  • New feature (thank you!)
  • Breaking change (fix/feature causing existing functionality to break)
  • Code quality improvements to existing code or addition of tests

Example configuration

Additional information

Checklist

  • The code change is tested and works locally.
  • There is no commented out code in this PR.
  • Tests have been added to verify that the new code works.

If user exposed functionality or configuration variables are added/changed:

this.hass,
(streamMessage) => {
// "recent" means start time is a sliding window
// so we need to calculate an expireTime to
// purge old events
if (!this._subscribed) {
if (!subscribePromise) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This will never evaluate to true. It looks like it was put there to handle the case where the component is unloading but events keep coming in. I don't think it did it properly though as it would only work after unsubscribe and at that point there shouldn't be any more events coming.
In any case, we should figure out another condition here or remove it if it is not needed.

@@ -305,6 +306,7 @@ export class HaLogbook extends LitElement {
this.entityIds,
this.deviceIds
);
this._subscribed = await subscribePromise;
Copy link
Member

Choose a reason for hiding this comment

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

_subscribed is typed as promise, and it also awaited in the code, we now no longer save a promise in _subscribed.

Also now _subscribed is set later, so that when _unsubscribe is called, _subscribed might not be set yet and we never unsubscribe.

@@ -288,13 +289,13 @@ export class HaLogbook extends LitElement {
return;
}
try {
this._subscribed = await subscribeLogbook(
Copy link
Member

Choose a reason for hiding this comment

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

Seems like we already awaited the promise, which is wrong.

@silamon silamon marked this pull request as draft February 24, 2025 19:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Logbook not working for number entities
3 participants