Skip to content

Use update entities for showing updates on configuration panel#12100

Merged
balloob merged 6 commits intodevfrom
config_update_entities
Mar 23, 2022
Merged

Use update entities for showing updates on configuration panel#12100
balloob merged 6 commits intodevfrom
config_update_entities

Conversation

@ludeeus
Copy link
Copy Markdown
Member

@ludeeus ludeeus commented Mar 22, 2022

Breaking change

Proposed change

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

  • This PR fixes or closes issue: fixes #
  • This PR is related to issue or discussion:
  • Link to documentation pull request:

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:


protected render(): TemplateResult {
const canInstallUpdates = updateEntities(this.hass.states).filter(
(entity) => updateCanInstall(entity)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why not do this filtering inside the memoized call ?

Should that filter also sort it by state name ?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

It's better to hit a memoized call here and do an extra filter in the _handleAction, because when handling an action there is nothing else going on. We want to do as little as possible when rendering.

import { showToast } from "../../../util/toast";
import { documentationUrl } from "../../../util/documentation-url";

const updateEntities = memoizeOne(
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Put the memoized functions on the class instances such that running this class doesn't change any module variables.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We might not run the dashboard twice, but people might copy the pattern from here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Also it's slightly faster when the dashboard is not shown, as memoizeOne is only executed when class is instantiated if set as instance var.

balloob
balloob previously approved these changes Mar 22, 2022
Copy link
Copy Markdown
Member

@balloob balloob left a comment

Choose a reason for hiding this comment

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

Very nice!

@balloob balloob merged commit 7b6d3c0 into dev Mar 23, 2022
@balloob balloob deleted the config_update_entities branch March 23, 2022 20:04
@github-actions github-actions bot locked and limited conversation to collaborators Mar 24, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants