mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-27 11:16:35 +00:00
Rename entity filter to entity domain filter (#24587)
This commit is contained in:
parent
e8805be561
commit
616c1fda81
@ -1,27 +1,27 @@
|
|||||||
import { computeDomain } from "./compute_domain";
|
import { computeDomain } from "./compute_domain";
|
||||||
|
|
||||||
export type FilterFunc = (entityId: string) => boolean;
|
export type EntityDomainFilterFunc = (entityId: string) => boolean;
|
||||||
|
|
||||||
export interface EntityFilter {
|
export interface EntityDomainFilter {
|
||||||
include_domains: string[];
|
include_domains: string[];
|
||||||
include_entities: string[];
|
include_entities: string[];
|
||||||
exclude_domains: string[];
|
exclude_domains: string[];
|
||||||
exclude_entities: string[];
|
exclude_entities: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export const isEmptyFilter = (filter: EntityFilter) =>
|
export const isEmptyEntityDomainFilter = (filter: EntityDomainFilter) =>
|
||||||
filter.include_domains.length +
|
filter.include_domains.length +
|
||||||
filter.include_entities.length +
|
filter.include_entities.length +
|
||||||
filter.exclude_domains.length +
|
filter.exclude_domains.length +
|
||||||
filter.exclude_entities.length ===
|
filter.exclude_entities.length ===
|
||||||
0;
|
0;
|
||||||
|
|
||||||
export const generateFilter = (
|
export const generateEntityDomainFilter = (
|
||||||
includeDomains?: string[],
|
includeDomains?: string[],
|
||||||
includeEntities?: string[],
|
includeEntities?: string[],
|
||||||
excludeDomains?: string[],
|
excludeDomains?: string[],
|
||||||
excludeEntities?: string[]
|
excludeEntities?: string[]
|
||||||
): FilterFunc => {
|
): EntityDomainFilterFunc => {
|
||||||
const includeDomainsSet = new Set(includeDomains);
|
const includeDomainsSet = new Set(includeDomains);
|
||||||
const includeEntitiesSet = new Set(includeEntities);
|
const includeEntitiesSet = new Set(includeEntities);
|
||||||
const excludeDomainsSet = new Set(excludeDomains);
|
const excludeDomainsSet = new Set(excludeDomains);
|
@ -1,4 +1,4 @@
|
|||||||
import type { EntityFilter } from "../common/entity/entity_filter";
|
import type { EntityDomainFilter } from "../common/entity/entity_domain_filter";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
|
|
||||||
type StrictConnectionMode = "disabled" | "guard_page" | "drop_connection";
|
type StrictConnectionMode = "disabled" | "guard_page" | "drop_connection";
|
||||||
@ -36,10 +36,10 @@ export interface CloudStatusLoggedIn {
|
|||||||
cloud_last_disconnect_reason: { clean: boolean; reason: string } | null;
|
cloud_last_disconnect_reason: { clean: boolean; reason: string } | null;
|
||||||
email: string;
|
email: string;
|
||||||
google_registered: boolean;
|
google_registered: boolean;
|
||||||
google_entities: EntityFilter;
|
google_entities: EntityDomainFilter;
|
||||||
google_domains: string[];
|
google_domains: string[];
|
||||||
alexa_registered: boolean;
|
alexa_registered: boolean;
|
||||||
alexa_entities: EntityFilter;
|
alexa_entities: EntityDomainFilter;
|
||||||
prefs: CloudPreferences;
|
prefs: CloudPreferences;
|
||||||
remote_domain: string | undefined;
|
remote_domain: string | undefined;
|
||||||
remote_connected: boolean;
|
remote_connected: boolean;
|
||||||
|
@ -4,7 +4,7 @@ import { css, html, LitElement, nothing } from "lit";
|
|||||||
import { property, state } from "lit/decorators";
|
import { property, state } from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import { isEmptyFilter } from "../../../common/entity/entity_filter";
|
import { isEmptyEntityDomainFilter } from "../../../common/entity/entity_domain_filter";
|
||||||
import "../../../components/ha-alert";
|
import "../../../components/ha-alert";
|
||||||
import "../../../components/ha-card";
|
import "../../../components/ha-card";
|
||||||
import "../../../components/ha-settings-row";
|
import "../../../components/ha-settings-row";
|
||||||
@ -56,7 +56,9 @@ export class CloudAlexaPref extends LitElement {
|
|||||||
const alexa_registered = this.cloudStatus.alexa_registered;
|
const alexa_registered = this.cloudStatus.alexa_registered;
|
||||||
const { alexa_enabled, alexa_report_state } = this.cloudStatus!.prefs;
|
const { alexa_enabled, alexa_report_state } = this.cloudStatus!.prefs;
|
||||||
|
|
||||||
const manualConfig = !isEmptyFilter(this.cloudStatus.alexa_entities);
|
const manualConfig = !isEmptyEntityDomainFilter(
|
||||||
|
this.cloudStatus.alexa_entities
|
||||||
|
);
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-card outlined>
|
<ha-card outlined>
|
||||||
|
@ -4,7 +4,7 @@ import { css, html, LitElement, nothing } from "lit";
|
|||||||
import { property, state } from "lit/decorators";
|
import { property, state } from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import { isEmptyFilter } from "../../../common/entity/entity_filter";
|
import { isEmptyEntityDomainFilter } from "../../../common/entity/entity_domain_filter";
|
||||||
import "../../../components/ha-alert";
|
import "../../../components/ha-alert";
|
||||||
import "../../../components/ha-card";
|
import "../../../components/ha-card";
|
||||||
import "../../../components/ha-settings-row";
|
import "../../../components/ha-settings-row";
|
||||||
@ -62,7 +62,9 @@ export class CloudGooglePref extends LitElement {
|
|||||||
const { google_enabled, google_report_state, google_secure_devices_pin } =
|
const { google_enabled, google_report_state, google_secure_devices_pin } =
|
||||||
this.cloudStatus.prefs;
|
this.cloudStatus.prefs;
|
||||||
|
|
||||||
const manualConfig = !isEmptyFilter(this.cloudStatus.google_entities);
|
const manualConfig = !isEmptyEntityDomainFilter(
|
||||||
|
this.cloudStatus.google_entities
|
||||||
|
);
|
||||||
|
|
||||||
return html`
|
return html`
|
||||||
<ha-card outlined>
|
<ha-card outlined>
|
||||||
|
@ -6,13 +6,13 @@ import memoizeOne from "memoize-one";
|
|||||||
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
|
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import type {
|
import type {
|
||||||
EntityFilter,
|
EntityDomainFilter,
|
||||||
FilterFunc,
|
EntityDomainFilterFunc,
|
||||||
} from "../../../common/entity/entity_filter";
|
} from "../../../common/entity/entity_domain_filter";
|
||||||
import {
|
import {
|
||||||
generateFilter,
|
generateEntityDomainFilter,
|
||||||
isEmptyFilter,
|
isEmptyEntityDomainFilter,
|
||||||
} from "../../../common/entity/entity_filter";
|
} from "../../../common/entity/entity_domain_filter";
|
||||||
import "../../../components/ha-aliases-editor";
|
import "../../../components/ha-aliases-editor";
|
||||||
import "../../../components/ha-settings-row";
|
import "../../../components/ha-settings-row";
|
||||||
import "../../../components/ha-switch";
|
import "../../../components/ha-switch";
|
||||||
@ -101,14 +101,14 @@ export class EntityVoiceSettings extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _getEntityFilterFuncs = memoizeOne(
|
private _getEntityFilterFuncs = memoizeOne(
|
||||||
(googleFilter: EntityFilter, alexaFilter: EntityFilter) => ({
|
(googleFilter: EntityDomainFilter, alexaFilter: EntityDomainFilter) => ({
|
||||||
google: generateFilter(
|
google: generateEntityDomainFilter(
|
||||||
googleFilter.include_domains,
|
googleFilter.include_domains,
|
||||||
googleFilter.include_entities,
|
googleFilter.include_entities,
|
||||||
googleFilter.exclude_domains,
|
googleFilter.exclude_domains,
|
||||||
googleFilter.exclude_entities
|
googleFilter.exclude_entities
|
||||||
),
|
),
|
||||||
alexa: generateFilter(
|
alexa: generateEntityDomainFilter(
|
||||||
alexaFilter.include_domains,
|
alexaFilter.include_domains,
|
||||||
alexaFilter.include_entities,
|
alexaFilter.include_entities,
|
||||||
alexaFilter.exclude_domains,
|
alexaFilter.exclude_domains,
|
||||||
@ -131,10 +131,12 @@ export class EntityVoiceSettings extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
const alexaManual =
|
const alexaManual =
|
||||||
alexaEnabled &&
|
alexaEnabled &&
|
||||||
!isEmptyFilter((this._cloudStatus as CloudStatusLoggedIn).alexa_entities);
|
!isEmptyEntityDomainFilter(
|
||||||
|
(this._cloudStatus as CloudStatusLoggedIn).alexa_entities
|
||||||
|
);
|
||||||
const googleManual =
|
const googleManual =
|
||||||
googleEnabled &&
|
googleEnabled &&
|
||||||
!isEmptyFilter(
|
!isEmptyEntityDomainFilter(
|
||||||
(this._cloudStatus as CloudStatusLoggedIn).google_entities
|
(this._cloudStatus as CloudStatusLoggedIn).google_entities
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -159,8 +161,8 @@ export class EntityVoiceSettings extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
let manFilterFuncs:
|
let manFilterFuncs:
|
||||||
| {
|
| {
|
||||||
google: FilterFunc;
|
google: EntityDomainFilterFunc;
|
||||||
alexa: FilterFunc;
|
alexa: EntityDomainFilterFunc;
|
||||||
}
|
}
|
||||||
| undefined;
|
| undefined;
|
||||||
|
|
||||||
|
@ -13,11 +13,11 @@ import memoize from "memoize-one";
|
|||||||
import type { HASSDomEvent } from "../../../common/dom/fire_event";
|
import type { HASSDomEvent } from "../../../common/dom/fire_event";
|
||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import { computeStateName } from "../../../common/entity/compute_state_name";
|
import { computeStateName } from "../../../common/entity/compute_state_name";
|
||||||
import type { EntityFilter } from "../../../common/entity/entity_filter";
|
import type { EntityDomainFilter } from "../../../common/entity/entity_domain_filter";
|
||||||
import {
|
import {
|
||||||
generateFilter,
|
generateEntityDomainFilter,
|
||||||
isEmptyFilter,
|
isEmptyEntityDomainFilter,
|
||||||
} from "../../../common/entity/entity_filter";
|
} from "../../../common/entity/entity_domain_filter";
|
||||||
import { navigate } from "../../../common/navigate";
|
import { navigate } from "../../../common/navigate";
|
||||||
import type {
|
import type {
|
||||||
DataTableColumnContainer,
|
DataTableColumnContainer,
|
||||||
@ -257,14 +257,14 @@ export class VoiceAssistantsExpose extends LitElement {
|
|||||||
);
|
);
|
||||||
|
|
||||||
private _getEntityFilterFuncs = memoize(
|
private _getEntityFilterFuncs = memoize(
|
||||||
(googleFilter: EntityFilter, alexaFilter: EntityFilter) => ({
|
(googleFilter: EntityDomainFilter, alexaFilter: EntityDomainFilter) => ({
|
||||||
google: generateFilter(
|
google: generateEntityDomainFilter(
|
||||||
googleFilter.include_domains,
|
googleFilter.include_domains,
|
||||||
googleFilter.include_entities,
|
googleFilter.include_entities,
|
||||||
googleFilter.exclude_domains,
|
googleFilter.exclude_domains,
|
||||||
googleFilter.exclude_entities
|
googleFilter.exclude_entities
|
||||||
),
|
),
|
||||||
amazon: generateFilter(
|
amazon: generateEntityDomainFilter(
|
||||||
alexaFilter.include_domains,
|
alexaFilter.include_domains,
|
||||||
alexaFilter.include_entities,
|
alexaFilter.include_entities,
|
||||||
alexaFilter.exclude_domains,
|
alexaFilter.exclude_domains,
|
||||||
@ -320,12 +320,12 @@ export class VoiceAssistantsExpose extends LitElement {
|
|||||||
|
|
||||||
const alexaManual =
|
const alexaManual =
|
||||||
alexaEnabled &&
|
alexaEnabled &&
|
||||||
!isEmptyFilter(
|
!isEmptyEntityDomainFilter(
|
||||||
(this.cloudStatus as CloudStatusLoggedIn).alexa_entities
|
(this.cloudStatus as CloudStatusLoggedIn).alexa_entities
|
||||||
);
|
);
|
||||||
const googleManual =
|
const googleManual =
|
||||||
googleEnabled &&
|
googleEnabled &&
|
||||||
!isEmptyFilter(
|
!isEmptyEntityDomainFilter(
|
||||||
(this.cloudStatus as CloudStatusLoggedIn).google_entities
|
(this.cloudStatus as CloudStatusLoggedIn).google_entities
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -1,11 +1,11 @@
|
|||||||
import { assert, describe, it } from "vitest";
|
import { assert, describe, it } from "vitest";
|
||||||
|
|
||||||
import { generateFilter } from "../../../src/common/entity/entity_filter";
|
import { generateEntityDomainFilter } from "../../../src/common/entity/entity_domain_filter";
|
||||||
|
|
||||||
describe("EntityFilter", () => {
|
describe("EntityFilter", () => {
|
||||||
// case 1
|
// case 1
|
||||||
it("passes all when no filters passed in", () => {
|
it("passes all when no filters passed in", () => {
|
||||||
const filter = generateFilter();
|
const filter = generateEntityDomainFilter();
|
||||||
|
|
||||||
assert(filter("sensor.test"));
|
assert(filter("sensor.test"));
|
||||||
assert(filter("sun.sun"));
|
assert(filter("sun.sun"));
|
||||||
@ -14,14 +14,14 @@ describe("EntityFilter", () => {
|
|||||||
|
|
||||||
// case 2
|
// case 2
|
||||||
it("allows entities by entity id", () => {
|
it("allows entities by entity id", () => {
|
||||||
const filter = generateFilter(undefined, ["light.kitchen"]);
|
const filter = generateEntityDomainFilter(undefined, ["light.kitchen"]);
|
||||||
|
|
||||||
assert(filter("light.kitchen"));
|
assert(filter("light.kitchen"));
|
||||||
assert(!filter("light.living_room"));
|
assert(!filter("light.living_room"));
|
||||||
});
|
});
|
||||||
|
|
||||||
it("allows entities by domain", () => {
|
it("allows entities by domain", () => {
|
||||||
const filter = generateFilter(["switch"]);
|
const filter = generateEntityDomainFilter(["switch"]);
|
||||||
|
|
||||||
assert(filter("switch.bla"));
|
assert(filter("switch.bla"));
|
||||||
assert(!filter("light.kitchen"));
|
assert(!filter("light.kitchen"));
|
||||||
@ -29,7 +29,7 @@ describe("EntityFilter", () => {
|
|||||||
|
|
||||||
// case 3
|
// case 3
|
||||||
it("excluding entities by entity id", () => {
|
it("excluding entities by entity id", () => {
|
||||||
const filter = generateFilter(undefined, undefined, undefined, [
|
const filter = generateEntityDomainFilter(undefined, undefined, undefined, [
|
||||||
"light.kitchen",
|
"light.kitchen",
|
||||||
]);
|
]);
|
||||||
|
|
||||||
@ -38,7 +38,7 @@ describe("EntityFilter", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("excluding entities by domain", () => {
|
it("excluding entities by domain", () => {
|
||||||
const filter = generateFilter(undefined, undefined, ["switch"]);
|
const filter = generateEntityDomainFilter(undefined, undefined, ["switch"]);
|
||||||
|
|
||||||
assert(!filter("switch.bla"));
|
assert(!filter("switch.bla"));
|
||||||
assert(filter("light.kitchen"));
|
assert(filter("light.kitchen"));
|
||||||
@ -46,9 +46,12 @@ describe("EntityFilter", () => {
|
|||||||
|
|
||||||
// case 4a
|
// case 4a
|
||||||
it("allows domain and excluding entity", () => {
|
it("allows domain and excluding entity", () => {
|
||||||
const filter = generateFilter(["switch"], undefined, undefined, [
|
const filter = generateEntityDomainFilter(
|
||||||
"switch.kitchen",
|
["switch"],
|
||||||
]);
|
undefined,
|
||||||
|
undefined,
|
||||||
|
["switch.kitchen"]
|
||||||
|
);
|
||||||
|
|
||||||
assert(filter("switch.living_room"));
|
assert(filter("switch.living_room"));
|
||||||
assert(!filter("switch.kitchen"));
|
assert(!filter("switch.kitchen"));
|
||||||
@ -56,7 +59,7 @@ describe("EntityFilter", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("allows entity while other domains", () => {
|
it("allows entity while other domains", () => {
|
||||||
const filter = generateFilter(["switch"], ["light.kitchen"]);
|
const filter = generateEntityDomainFilter(["switch"], ["light.kitchen"]);
|
||||||
|
|
||||||
assert(filter("switch.living_room"));
|
assert(filter("switch.living_room"));
|
||||||
assert(filter("light.kitchen"));
|
assert(filter("light.kitchen"));
|
||||||
@ -65,7 +68,11 @@ describe("EntityFilter", () => {
|
|||||||
|
|
||||||
// case 4b
|
// case 4b
|
||||||
it("excluding domain and entity", () => {
|
it("excluding domain and entity", () => {
|
||||||
const filter = generateFilter(undefined, ["switch.kitchen"], ["switch"]);
|
const filter = generateEntityDomainFilter(
|
||||||
|
undefined,
|
||||||
|
["switch.kitchen"],
|
||||||
|
["switch"]
|
||||||
|
);
|
||||||
|
|
||||||
assert(filter("switch.kitchen"));
|
assert(filter("switch.kitchen"));
|
||||||
assert(!filter("switch.living_room"));
|
assert(!filter("switch.living_room"));
|
||||||
@ -73,7 +80,7 @@ describe("EntityFilter", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("excluding domain and excluding entities", () => {
|
it("excluding domain and excluding entities", () => {
|
||||||
const filter = generateFilter(
|
const filter = generateEntityDomainFilter(
|
||||||
undefined,
|
undefined,
|
||||||
undefined,
|
undefined,
|
||||||
["switch"],
|
["switch"],
|
||||||
@ -87,7 +94,7 @@ describe("EntityFilter", () => {
|
|||||||
|
|
||||||
// case 4c
|
// case 4c
|
||||||
it("allows entities", () => {
|
it("allows entities", () => {
|
||||||
const filter = generateFilter(undefined, ["light.kitchen"]);
|
const filter = generateEntityDomainFilter(undefined, ["light.kitchen"]);
|
||||||
|
|
||||||
assert(filter("light.kitchen"));
|
assert(filter("light.kitchen"));
|
||||||
assert(!filter("switch.living_room"));
|
assert(!filter("switch.living_room"));
|
Loading…
x
Reference in New Issue
Block a user