Skip to content

Add filter options to entity and device selectors#15302

Merged
bramkragten merged 17 commits into
devfrom
entity_filter_selector
Feb 20, 2023
Merged

Add filter options to entity and device selectors#15302
bramkragten merged 17 commits into
devfrom
entity_filter_selector

Conversation

@piitaya
Copy link
Copy Markdown
Member

@piitaya piitaya commented Feb 1, 2023

Breaking changes

Entity filters are now inside filter property but we can add backward compatibility.

Proposed change

  • Add filter config for entity selector to allow array of filter.
  • Add filter config for device selector to allow array of filter.
  • Allow device_class list for entity filter config

It fixes somes issues :

New schemas

interface EntitySelectorFilter {
  integration?: string;
  domain?: string | string[];
  device_class?: string | string[];
}

interface DeviceSelectorFilter {
  integration?: string;
  manufacturer?: string;
  model?: string;
}

export interface DeviceSelector {
  device: {
    filter?: DeviceSelectorFilter | DeviceSelectorFilter[];
    entity?: EntitySelectorFilter | EntitySelectorFilter[];
    multiple?: boolean;
     /** For backward compatilibity **/
    integration?: DeviceSelectorFilter["integration"];
    manufacturer?: DeviceSelectorFilter["manufacturer"];
    model?: DeviceSelectorFilter["model"];
  } | null;
}

export interface EntitySelector {
  entity: {
    multiple?: boolean;
    include_entities?: string[];
    exclude_entities?: string[];
    filter?: EntitySelectorFilter | EntitySelectorFilter[];
    /** For backward compatilibity **/
    integration?: EntitySelectorFilter["integration"];
    domain?: EntitySelectorFilter["domain"];
    device_class?: EntitySelectorFilter["device_class"];
  } | null;
}

Example

{
  entity: {
    filter: [
      { domain: "input_datetime" },
      { domain: "sensor", device_class: "timestamp" },
    ]
  }
}

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:

@piitaya piitaya force-pushed the entity_filter_selector branch from 2d2e838 to 2858519 Compare February 1, 2023 14:21
@piitaya piitaya force-pushed the entity_filter_selector branch from 2858519 to c727998 Compare February 3, 2023 15:18
@piitaya piitaya changed the title Allow arrays of filter for entity selector Allow arrays of filter for entity and device selector Feb 6, 2023
@piitaya piitaya changed the title Allow arrays of filter for entity and device selector Add filter options to entity and device selectors Feb 6, 2023
@piitaya piitaya marked this pull request as ready for review February 6, 2023 17:22
@bramkragten
Copy link
Copy Markdown
Member

@bramkragten
Copy link
Copy Markdown
Member

Can we rewrite the old schema to new schema instead, so the code only needs to handle the new config and not care about the old config.

So when we get

entity:
    domain: hue

We create

entity:
  filter:
    domain: hue

Comment thread src/data/selector.ts Outdated
@piitaya piitaya force-pushed the entity_filter_selector branch from d1f1e0d to f64366e Compare February 7, 2023 10:19
@piitaya piitaya marked this pull request as draft February 7, 2023 11:31
@piitaya piitaya marked this pull request as ready for review February 7, 2023 13:57
@piitaya piitaya requested a review from bramkragten February 15, 2023 10:18
@piitaya piitaya added this to the 2023.3 milestone Feb 20, 2023
@piitaya piitaya force-pushed the entity_filter_selector branch from 119e171 to a6c81fc Compare February 20, 2023 11:18
@bramkragten bramkragten merged commit c4160e8 into dev Feb 20, 2023
@bramkragten bramkragten deleted the entity_filter_selector branch February 20, 2023 13:30
@github-actions github-actions Bot locked and limited conversation to collaborators Feb 20, 2024
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.

2 participants