Faster History Rendering - #205
Open
breakthestatic wants to merge 2 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The primary purpose of this PR is to improve the initial rendering delay when subscribing to the history websocket endpoint. The prior (existing) implementation received new entity history information almost immediately from the websocket and recorded the info internally. However, it still waited for the next Lit render cycle to actually put those coordinates on the map. Depending on when the last render occurred, this could defer the history rendering up to 10 seconds in my experience; I'm guessing that's the rate that the
hassobject emits changes.To address this, I've added an immediate, debounced update call to the
EntityHistoryManager’sreact()method. This allows the history to appear as soon as data starts coming in from the websocket while avoiding excessive renders. Since the history is now decoupled from the full Lit render cycle, I needed to manually update theEntity’s current marker position to ensure the marker remains “synced” with the most recent history coordinate (hence refactoring theEntitymarker logic into a separate function).Lastly, I found quite a few errors when trying to use this custom card within a parent “template” card (both
decluttering-cardandstreamline-card) and have made some adjustments to the map/view initialization logic to address them:firstUpdated()is initially called before Home Assistant has injected thehassproperty. Added a guard to ensure it exists before callingsetup().Removed a redundant
render()call within thesetup()function. Lit will automatically queue up another render due to changes insidesetup().Moved/updated the
setup()call within therender()function to outside theif (this.map)guard. The oldsetup()call was inside theif (this.map)guard, creating a deadlock in template cards. After teardown,this.mapis undefined sosetup()never runs, butsetup()is what createsthis.map. Moving it outside with its own guards lets the card re-bootstrap itself regardless of prior map state.Previously
connectedCallback()calledthis.setup()directly if the#mapDOM element existed. But after a disconnect/reconnect cycle (i.e. template cards), the shadow DOM may not be fully ready yet. CallingrequestUpdate()instead defers toLitElement’s update cycle, which will callrender(), and the newsetup()guard there handles bootstrapping once the DOM andhassare actually available.Removed the
this.initialViewRenderService?.setup()call in the resize observer. This was resetting the user's zoom/pan on every resize event, overriding any manual map interaction.Added a single, one-shot resize observer in the
InitialViewRenderServiceto handle setting the view after the parent DOM has size.