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

Save attribute checkbox state #8010

Merged
merged 4 commits into from
Feb 24, 2021
Merged

Conversation

KTibow
Copy link
Contributor

@KTibow KTibow commented Dec 18, 2020

Proposed change

Save whether or not the attribute checkbox is checked in localStorage. This can help if you have a lot of entities, so you don't have to wait forever to load the attributes.

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

# Go into the states tab of devtools

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:

Copy link
Member

@spacegaier spacegaier left a comment

Choose a reason for hiding this comment

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

Two points:

  1. I propose to rename the storage parameter, so that the area/topic comes first: "devToolsShowAttributes". That would more closely match existing stored parameters such as "sidebarPanelOrder".
  2. There is already coding in HA how to handle local storage parameters. That should perhaps be reused. See
    @LocalStorage("sidebarPanelOrder", true, {
    attribute: false,
    })
    private _panelOrder: string[] = [];

@KTibow
Copy link
Contributor Author

KTibow commented Dec 18, 2020

@spacegaier Could you point me how to use the localStorage decorator? I skimmed through the code, but I couldn't figure out the parameter order.

@spacegaier
Copy link
Member

@spacegaier Could you point me how to use the localStorage decorator? I skimmed through the code, but I couldn't figure out the parameter order.

What do you mean by "property order"? Never used local storage in HA myself.

@KTibow
Copy link
Contributor Author

KTibow commented Dec 18, 2020

I mean how to use it. I can see that the first thing you pass to @LocalStorage is the name of the property, but I don't know what everything else is.

@spacegaier
Copy link
Member

It's all defined in the HA coding:

export const LocalStorage = (
storageKey?: string,
property?: boolean,
propertyOptions?: PropertyDeclaration
): any => {

Second parameter seems to indicate whether it's a property and if it is, then the value is automatically read from it by the looks of it. So it is basically subscribing to value changes (changes introduced here #6776).

@bramkragten
Copy link
Member

This is not a typescript file and not a Lit element, so you cant use that decorator without converting it first.

@bramkragten bramkragten merged commit 782b941 into home-assistant:dev Feb 24, 2021
@bramkragten bramkragten mentioned this pull request Feb 24, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Feb 25, 2021
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.

4 participants