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

Show all disabled helpers in config/helpers #23377

Merged
merged 3 commits into from
Dec 22, 2024

Conversation

karwosts
Copy link
Contributor

@karwosts karwosts commented Dec 21, 2024

Proposed change

Fix inconsistent behavior for disabled helpers; current behavior is that disabled helpers created in UI are shown, but disabled helpers created in YAML are not shown.

This change makes it so that all disabled helpers are shown.

Also for the disabled entities that are currently shown, they don't work right for filtering. They can have labels & categories, but if you apply any label/category filter, they never pass the filter even when they should. This change fixes the filtering on disabled helpers.

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:

@karwosts
Copy link
Contributor Author

karwosts commented Dec 22, 2024

Adding some more elaboration on the theory here:

Current behavior I see is this:

Disabled Input-Number Helper (YAML originated): Not Shown
Disabled Input-Number Helper (UI originated): Not Shown
Disabled HistoryStats Helper (YAML originated): Not Shown
Disabled HistoryStats Helper (UI originated): Shown

This is because when we subscribe to configEntries, only the last category of disabled entities is returned in the response.

So instead of relying on what is returned by configEntries, to find all the disabled items I iterate at all the entries of the entityRegistry.

    if (
      (changedProps.has("_helperManifests") ||
        changedProps.has("_entityEntries") ||
        changedProps.has("_configEntries")) &&
      this._helperManifests
    ) {
      this._disabledEntries = Object.values(this._entityEntries).filter(
        (e) =>
          e.disabled_by &&
          (e.platform in this._helperManifests! ||
            (e.config_entry_id && e.config_entry_id in this._configEntries!))
      );
    }

Any entry in the entityRegistry that is disabled, and has a platform which the manifest lists as a helper type, gets added to a separate list of disabledEntries that we show separately.

The above almost gets everything, except for switch_as_x, which does not have an integration manifest?

But for switch_as_x, I notice that disabled entities of switch_as_x are present in the configEntries return. So make sure those are included in the disabled list by the last line here: (e.config_entry_id && e.config_entry_id in this._configEntries!))

With the above, we now have a comprehensive list of disabled entities, which can be referenced by the applyFilters function.

And now we have added to _getItems a separate loop of iterating the list of disabled entries. Because we do this, we no longer want to include disabled items when we are iterating configEntriesCopy, or else some entities would be shown twice. So the iterator of configEntriesCopy was changed such that any disabled entities in that list are filtered out from that loop.

type: e.platform,
configEntry: undefined,
entity: undefined,
selectable: true,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
selectable: true,
selectable: true,
disabled: true,

@@ -191,6 +192,8 @@ export class HaConfigHelpers extends SubscribeMixin(LitElement) {

@state() private _stateItems: HassEntity[] = [];

@state() private _disabledEntries?: EntityRegistryEntry[];
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
@state() private _disabledEntries?: EntityRegistryEntry[];
@state() private _disabledEntityEntries?: EntityRegistryEntry[];

bramkragten
bramkragten previously approved these changes Dec 22, 2024
@bramkragten bramkragten merged commit 5ccc336 into home-assistant:dev Dec 22, 2024
15 checks passed
@karwosts karwosts deleted the helpers-disabled branch December 22, 2024 17:13
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.

2 participants