mirror of
https://github.com/home-assistant/frontend.git
synced 2025-12-15 04:27:28 +00:00
Compare commits
43 Commits
show-proto
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dfc7116819 | ||
|
|
685c642bfc | ||
|
|
2e547937b8 | ||
|
|
e3e01c327a | ||
|
|
abd706fed0 | ||
|
|
3bd45dd29b | ||
|
|
206f067d2b | ||
|
|
caefa7530a | ||
|
|
de142e33a1 | ||
|
|
5d4c3ebfcd | ||
|
|
eb910c5ac5 | ||
|
|
72726a2e0f | ||
|
|
253b49871e | ||
|
|
6306890922 | ||
|
|
fee16ed4e4 | ||
|
|
055f6c82fb | ||
|
|
0c1627c69a | ||
|
|
780c03ece8 | ||
|
|
62dc66abd8 | ||
|
|
08aaee754e | ||
|
|
bba400443e | ||
|
|
a7a937e197 | ||
|
|
2a97913520 | ||
|
|
9f16ce7341 | ||
|
|
3e20e9b388 | ||
|
|
6891eb9ff8 | ||
|
|
f649b3783d | ||
|
|
c46f67d572 | ||
|
|
86acfa67dd | ||
|
|
3c5c19270f | ||
|
|
6db7817032 | ||
|
|
05ca8253f0 | ||
|
|
071161e82d | ||
|
|
9cd38c7128 | ||
|
|
6322c19a45 | ||
|
|
74b51b77fe | ||
|
|
b80481b53e | ||
|
|
2ce1eaf8c6 | ||
|
|
4030ce3f88 | ||
|
|
41cabde393 | ||
|
|
47d1fdf673 | ||
|
|
e59e83fffe | ||
|
|
b896b78876 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -56,4 +56,5 @@ test/coverage/
|
|||||||
|
|
||||||
# AI tooling
|
# AI tooling
|
||||||
.claude
|
.claude
|
||||||
|
.cursor
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { DeviceRegistryEntry } from "../../../src/data/device_registry";
|
import type { DeviceRegistryEntry } from "../../../src/data/device/device_registry";
|
||||||
import type { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
import type { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
||||||
|
|
||||||
export const mockDeviceRegistry = (
|
export const mockDeviceRegistry = (
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { EntityRegistryEntry } from "../../../src/data/entity_registry";
|
import type { EntityRegistryEntry } from "../../../src/data/entity/entity_registry";
|
||||||
import type { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
import type { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
||||||
|
|
||||||
export const mockEntityRegistry = (
|
export const mockEntityRegistry = (
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import type { LabelRegistryEntry } from "../../../src/data/label_registry";
|
import type { LabelRegistryEntry } from "../../../src/data/label/label_registry";
|
||||||
import type { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
import type { MockHomeAssistant } from "../../../src/fake_data/provide_hass";
|
||||||
|
|
||||||
export const mockLabelRegistry = (
|
export const mockLabelRegistry = (
|
||||||
|
|||||||
@@ -11,11 +11,11 @@ import { computeInitialHaFormData } from "../../../../src/components/ha-form/com
|
|||||||
import "../../../../src/components/ha-form/ha-form";
|
import "../../../../src/components/ha-form/ha-form";
|
||||||
import type { HaFormSchema } from "../../../../src/components/ha-form/types";
|
import type { HaFormSchema } from "../../../../src/components/ha-form/types";
|
||||||
import type { AreaRegistryEntry } from "../../../../src/data/area_registry";
|
import type { AreaRegistryEntry } from "../../../../src/data/area_registry";
|
||||||
|
import type { DeviceRegistryEntry } from "../../../../src/data/device/device_registry";
|
||||||
import { getEntity } from "../../../../src/fake_data/entity";
|
import { getEntity } from "../../../../src/fake_data/entity";
|
||||||
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
||||||
import type { HomeAssistant } from "../../../../src/types";
|
import type { HomeAssistant } from "../../../../src/types";
|
||||||
import "../../components/demo-black-white-row";
|
import "../../components/demo-black-white-row";
|
||||||
import type { DeviceRegistryEntry } from "../../../../src/data/device_registry";
|
|
||||||
|
|
||||||
const ENTITIES = [
|
const ENTITIES = [
|
||||||
getEntity("alarm_control_panel", "alarm", "disarmed", {
|
getEntity("alarm_control_panel", "alarm", "disarmed", {
|
||||||
|
|||||||
@@ -13,9 +13,9 @@ import "../../../../src/components/ha-selector/ha-selector";
|
|||||||
import "../../../../src/components/ha-settings-row";
|
import "../../../../src/components/ha-settings-row";
|
||||||
import type { AreaRegistryEntry } from "../../../../src/data/area_registry";
|
import type { AreaRegistryEntry } from "../../../../src/data/area_registry";
|
||||||
import type { BlueprintInput } from "../../../../src/data/blueprint";
|
import type { BlueprintInput } from "../../../../src/data/blueprint";
|
||||||
import type { DeviceRegistryEntry } from "../../../../src/data/device_registry";
|
import type { DeviceRegistryEntry } from "../../../../src/data/device/device_registry";
|
||||||
import type { FloorRegistryEntry } from "../../../../src/data/floor_registry";
|
import type { FloorRegistryEntry } from "../../../../src/data/floor_registry";
|
||||||
import type { LabelRegistryEntry } from "../../../../src/data/label_registry";
|
import type { LabelRegistryEntry } from "../../../../src/data/label/label_registry";
|
||||||
import { showDialog } from "../../../../src/dialogs/make-dialog-manager";
|
import { showDialog } from "../../../../src/dialogs/make-dialog-manager";
|
||||||
import { getEntity } from "../../../../src/fake_data/entity";
|
import { getEntity } from "../../../../src/fake_data/entity";
|
||||||
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import { customElement, property, state } from "lit/decorators";
|
|||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
import type { IntegrationManifest } from "../../../../src/data/integration";
|
import type { IntegrationManifest } from "../../../../src/data/integration";
|
||||||
|
|
||||||
import type { DeviceRegistryEntry } from "../../../../src/data/device_registry";
|
import type { DeviceRegistryEntry } from "../../../../src/data/device/device_registry";
|
||||||
import type { EntityRegistryEntry } from "../../../../src/data/entity_registry";
|
import type { EntityRegistryEntry } from "../../../../src/data/entity/entity_registry";
|
||||||
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
import { provideHass } from "../../../../src/fake_data/provide_hass";
|
||||||
import "../../../../src/panels/config/integrations/ha-config-flow-card";
|
import "../../../../src/panels/config/integrations/ha-config-flow-card";
|
||||||
import type {
|
import type {
|
||||||
|
|||||||
14
package.json
14
package.json
@@ -34,7 +34,7 @@
|
|||||||
"@codemirror/legacy-modes": "6.5.2",
|
"@codemirror/legacy-modes": "6.5.2",
|
||||||
"@codemirror/search": "6.5.11",
|
"@codemirror/search": "6.5.11",
|
||||||
"@codemirror/state": "6.5.2",
|
"@codemirror/state": "6.5.2",
|
||||||
"@codemirror/view": "6.38.8",
|
"@codemirror/view": "6.39.3",
|
||||||
"@date-fns/tz": "1.4.1",
|
"@date-fns/tz": "1.4.1",
|
||||||
"@egjs/hammerjs": "2.0.17",
|
"@egjs/hammerjs": "2.0.17",
|
||||||
"@formatjs/intl-datetimeformat": "6.18.2",
|
"@formatjs/intl-datetimeformat": "6.18.2",
|
||||||
@@ -52,7 +52,7 @@
|
|||||||
"@fullcalendar/list": "6.1.19",
|
"@fullcalendar/list": "6.1.19",
|
||||||
"@fullcalendar/luxon3": "6.1.19",
|
"@fullcalendar/luxon3": "6.1.19",
|
||||||
"@fullcalendar/timegrid": "6.1.19",
|
"@fullcalendar/timegrid": "6.1.19",
|
||||||
"@home-assistant/webawesome": "3.0.0-ha.1",
|
"@home-assistant/webawesome": "3.0.0-ha.2",
|
||||||
"@lezer/highlight": "1.2.3",
|
"@lezer/highlight": "1.2.3",
|
||||||
"@lit-labs/motion": "1.0.9",
|
"@lit-labs/motion": "1.0.9",
|
||||||
"@lit-labs/observers": "2.0.6",
|
"@lit-labs/observers": "2.0.6",
|
||||||
@@ -135,7 +135,7 @@
|
|||||||
"stacktrace-js": "2.0.2",
|
"stacktrace-js": "2.0.2",
|
||||||
"superstruct": "2.0.2",
|
"superstruct": "2.0.2",
|
||||||
"tinykeys": "3.0.0",
|
"tinykeys": "3.0.0",
|
||||||
"ua-parser-js": "2.0.6",
|
"ua-parser-js": "2.0.7",
|
||||||
"vue": "2.7.16",
|
"vue": "2.7.16",
|
||||||
"vue2-daterange-picker": "0.6.8",
|
"vue2-daterange-picker": "0.6.8",
|
||||||
"weekstart": "2.0.0",
|
"weekstart": "2.0.0",
|
||||||
@@ -157,8 +157,8 @@
|
|||||||
"@octokit/auth-oauth-device": "8.0.3",
|
"@octokit/auth-oauth-device": "8.0.3",
|
||||||
"@octokit/plugin-retry": "8.0.3",
|
"@octokit/plugin-retry": "8.0.3",
|
||||||
"@octokit/rest": "22.0.1",
|
"@octokit/rest": "22.0.1",
|
||||||
"@rsdoctor/rspack-plugin": "1.3.12",
|
"@rsdoctor/rspack-plugin": "1.3.13",
|
||||||
"@rspack/core": "1.6.6",
|
"@rspack/core": "1.6.7",
|
||||||
"@rspack/dev-server": "1.1.4",
|
"@rspack/dev-server": "1.1.4",
|
||||||
"@types/babel__plugin-transform-runtime": "7.9.5",
|
"@types/babel__plugin-transform-runtime": "7.9.5",
|
||||||
"@types/chromecast-caf-receiver": "6.0.22",
|
"@types/chromecast-caf-receiver": "6.0.22",
|
||||||
@@ -201,7 +201,7 @@
|
|||||||
"gulp-rename": "2.1.0",
|
"gulp-rename": "2.1.0",
|
||||||
"html-minifier-terser": "7.2.0",
|
"html-minifier-terser": "7.2.0",
|
||||||
"husky": "9.1.7",
|
"husky": "9.1.7",
|
||||||
"jsdom": "27.2.0",
|
"jsdom": "27.3.0",
|
||||||
"jszip": "3.10.1",
|
"jszip": "3.10.1",
|
||||||
"lint-staged": "16.2.7",
|
"lint-staged": "16.2.7",
|
||||||
"lit-analyzer": "2.0.3",
|
"lit-analyzer": "2.0.3",
|
||||||
@@ -217,7 +217,7 @@
|
|||||||
"terser-webpack-plugin": "5.3.15",
|
"terser-webpack-plugin": "5.3.15",
|
||||||
"ts-lit-plugin": "2.0.2",
|
"ts-lit-plugin": "2.0.2",
|
||||||
"typescript": "5.9.3",
|
"typescript": "5.9.3",
|
||||||
"typescript-eslint": "8.48.1",
|
"typescript-eslint": "8.49.0",
|
||||||
"vite-tsconfig-paths": "5.1.4",
|
"vite-tsconfig-paths": "5.1.4",
|
||||||
"vitest": "4.0.15",
|
"vitest": "4.0.15",
|
||||||
"webpack-stats-plugin": "1.1.3",
|
"webpack-stats-plugin": "1.1.3",
|
||||||
|
|||||||
@@ -3,8 +3,8 @@ import {
|
|||||||
DOMAIN_ATTRIBUTES_FORMATERS,
|
DOMAIN_ATTRIBUTES_FORMATERS,
|
||||||
DOMAIN_ATTRIBUTES_UNITS,
|
DOMAIN_ATTRIBUTES_UNITS,
|
||||||
TEMPERATURE_ATTRIBUTES,
|
TEMPERATURE_ATTRIBUTES,
|
||||||
} from "../../data/entity_attributes";
|
} from "../../data/entity/entity_attributes";
|
||||||
import type { EntityRegistryDisplayEntry } from "../../data/entity_registry";
|
import type { EntityRegistryDisplayEntry } from "../../data/entity/entity_registry";
|
||||||
import type { FrontendLocaleData } from "../../data/translation";
|
import type { FrontendLocaleData } from "../../data/translation";
|
||||||
import type { WeatherEntity } from "../../data/weather";
|
import type { WeatherEntity } from "../../data/weather";
|
||||||
import { getWeatherUnit } from "../../data/weather";
|
import { getWeatherUnit } from "../../data/weather";
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import type { DeviceRegistryEntry } from "../../data/device_registry";
|
import type { DeviceRegistryEntry } from "../../data/device/device_registry";
|
||||||
import type {
|
import type {
|
||||||
EntityRegistryDisplayEntry,
|
EntityRegistryDisplayEntry,
|
||||||
EntityRegistryEntry,
|
EntityRegistryEntry,
|
||||||
} from "../../data/entity_registry";
|
} from "../../data/entity/entity_registry";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import { computeStateName } from "./compute_state_name";
|
|
||||||
import { getDuplicates } from "../string/get_duplicates";
|
import { getDuplicates } from "../string/get_duplicates";
|
||||||
|
import { computeStateName } from "./compute_state_name";
|
||||||
|
|
||||||
export const computeDeviceName = (
|
export const computeDeviceName = (
|
||||||
device: DeviceRegistryEntry
|
device: DeviceRegistryEntry
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type { HassEntity } from "home-assistant-js-websocket";
|
|||||||
import type {
|
import type {
|
||||||
EntityRegistryDisplayEntry,
|
EntityRegistryDisplayEntry,
|
||||||
EntityRegistryEntry,
|
EntityRegistryEntry,
|
||||||
} from "../../data/entity_registry";
|
} from "../../data/entity/entity_registry";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import { computeDeviceName } from "./compute_device_name";
|
import { computeDeviceName } from "./compute_device_name";
|
||||||
import { computeStateName } from "./compute_state_name";
|
import { computeStateName } from "./compute_state_name";
|
||||||
|
|||||||
@@ -1,12 +1,12 @@
|
|||||||
import type { HassConfig, HassEntity } from "home-assistant-js-websocket";
|
import type { HassConfig, HassEntity } from "home-assistant-js-websocket";
|
||||||
import { UNAVAILABLE, UNKNOWN } from "../../data/entity";
|
import { UNAVAILABLE, UNKNOWN } from "../../data/entity/entity";
|
||||||
import type { EntityRegistryDisplayEntry } from "../../data/entity_registry";
|
import type { EntityRegistryDisplayEntry } from "../../data/entity/entity_registry";
|
||||||
import type { FrontendLocaleData } from "../../data/translation";
|
import type { FrontendLocaleData } from "../../data/translation";
|
||||||
import { TimeZone } from "../../data/translation";
|
import { TimeZone } from "../../data/translation";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import { DURATION_UNITS, formatDuration } from "../datetime/format_duration";
|
|
||||||
import { formatDate } from "../datetime/format_date";
|
import { formatDate } from "../datetime/format_date";
|
||||||
import { formatDateTime } from "../datetime/format_date_time";
|
import { formatDateTime } from "../datetime/format_date_time";
|
||||||
|
import { DURATION_UNITS, formatDuration } from "../datetime/format_duration";
|
||||||
import { formatTime } from "../datetime/format_time";
|
import { formatTime } from "../datetime/format_time";
|
||||||
import {
|
import {
|
||||||
formatNumber,
|
formatNumber,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { AreaRegistryEntry } from "../../../data/area_registry";
|
import type { AreaRegistryEntry } from "../../../data/area_registry";
|
||||||
import type { DeviceRegistryEntry } from "../../../data/device_registry";
|
import type { DeviceRegistryEntry } from "../../../data/device/device_registry";
|
||||||
import type { FloorRegistryEntry } from "../../../data/floor_registry";
|
import type { FloorRegistryEntry } from "../../../data/floor_registry";
|
||||||
import type { HomeAssistant } from "../../../types";
|
import type { HomeAssistant } from "../../../types";
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,11 @@
|
|||||||
import type { HassEntity } from "home-assistant-js-websocket";
|
import type { HassEntity } from "home-assistant-js-websocket";
|
||||||
import type { AreaRegistryEntry } from "../../../data/area_registry";
|
import type { AreaRegistryEntry } from "../../../data/area_registry";
|
||||||
import type { DeviceRegistryEntry } from "../../../data/device_registry";
|
import type { DeviceRegistryEntry } from "../../../data/device/device_registry";
|
||||||
import type {
|
import type {
|
||||||
EntityRegistryDisplayEntry,
|
EntityRegistryDisplayEntry,
|
||||||
EntityRegistryEntry,
|
EntityRegistryEntry,
|
||||||
ExtEntityRegistryEntry,
|
ExtEntityRegistryEntry,
|
||||||
} from "../../../data/entity_registry";
|
} from "../../../data/entity/entity_registry";
|
||||||
import type { FloorRegistryEntry } from "../../../data/floor_registry";
|
import type { FloorRegistryEntry } from "../../../data/floor_registry";
|
||||||
import type { HomeAssistant } from "../../../types";
|
import type { HomeAssistant } from "../../../types";
|
||||||
|
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import type { HomeAssistant } from "../../types";
|
|
||||||
import type { IntegrationManifest } from "../../data/integration";
|
|
||||||
import { computeDomain } from "./compute_domain";
|
|
||||||
import { HELPERS_CRUD } from "../../data/helpers_crud";
|
|
||||||
import type { Helper } from "../../panels/config/helpers/const";
|
|
||||||
import { isHelperDomain } from "../../panels/config/helpers/const";
|
|
||||||
import { isComponentLoaded } from "../config/is_component_loaded";
|
|
||||||
import type { EntityRegistryEntry } from "../../data/entity_registry";
|
|
||||||
import { removeEntityRegistryEntry } from "../../data/entity_registry";
|
|
||||||
import type { ConfigEntry } from "../../data/config_entries";
|
import type { ConfigEntry } from "../../data/config_entries";
|
||||||
import { deleteConfigEntry } from "../../data/config_entries";
|
import { deleteConfigEntry } from "../../data/config_entries";
|
||||||
|
import type { EntityRegistryEntry } from "../../data/entity/entity_registry";
|
||||||
|
import { removeEntityRegistryEntry } from "../../data/entity/entity_registry";
|
||||||
|
import { HELPERS_CRUD } from "../../data/helpers_crud";
|
||||||
|
import type { IntegrationManifest } from "../../data/integration";
|
||||||
|
import type { Helper } from "../../panels/config/helpers/const";
|
||||||
|
import { isHelperDomain } from "../../panels/config/helpers/const";
|
||||||
|
import type { HomeAssistant } from "../../types";
|
||||||
|
import { isComponentLoaded } from "../config/is_component_loaded";
|
||||||
|
import { computeDomain } from "./compute_domain";
|
||||||
|
|
||||||
export const isDeletableEntity = (
|
export const isDeletableEntity = (
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import type { HassEntity } from "home-assistant-js-websocket";
|
import type { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { computeStateDomain } from "./compute_state_domain";
|
import { UNAVAILABLE_STATES } from "../../data/entity/entity";
|
||||||
import { UNAVAILABLE_STATES } from "../../data/entity";
|
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import { computeDomain } from "./compute_domain";
|
|
||||||
import { stringCompare } from "../string/compare";
|
import { stringCompare } from "../string/compare";
|
||||||
|
import { computeDomain } from "./compute_domain";
|
||||||
|
import { computeStateDomain } from "./compute_state_domain";
|
||||||
|
|
||||||
export const FIXED_DOMAIN_STATES = {
|
export const FIXED_DOMAIN_STATES = {
|
||||||
alarm_control_panel: [
|
alarm_control_panel: [
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { HassEntity } from "home-assistant-js-websocket";
|
import type { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { computeStateDomain } from "./compute_state_domain";
|
import { isUnavailableState, UNAVAILABLE } from "../../data/entity/entity";
|
||||||
import { isUnavailableState, UNAVAILABLE } from "../../data/entity";
|
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
|
import { computeStateDomain } from "./compute_state_domain";
|
||||||
|
|
||||||
export const computeGroupEntitiesState = (states: HassEntity[]): string => {
|
export const computeGroupEntitiesState = (states: HassEntity[]): string => {
|
||||||
if (!states.length) {
|
if (!states.length) {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { HassEntity } from "home-assistant-js-websocket";
|
import type { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { isUnavailableState, OFF, UNAVAILABLE } from "../../data/entity";
|
import { isUnavailableState, OFF, UNAVAILABLE } from "../../data/entity/entity";
|
||||||
import { computeDomain } from "./compute_domain";
|
import { computeDomain } from "./compute_domain";
|
||||||
|
|
||||||
export function stateActive(stateObj: HassEntity, state?: string): boolean {
|
export function stateActive(stateObj: HassEntity, state?: string): boolean {
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { HassEntity } from "home-assistant-js-websocket";
|
import type { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { UNAVAILABLE } from "../../data/entity";
|
import { UNAVAILABLE } from "../../data/entity/entity";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import { DOMAINS_WITH_CARD } from "../const";
|
import { DOMAINS_WITH_CARD } from "../const";
|
||||||
import { canToggleState } from "./can_toggle_state";
|
import { canToggleState } from "./can_toggle_state";
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
/** Return a color representing a state. */
|
/** Return a color representing a state. */
|
||||||
import type { HassEntity } from "home-assistant-js-websocket";
|
import type { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { UNAVAILABLE } from "../../data/entity";
|
import { UNAVAILABLE } from "../../data/entity/entity";
|
||||||
import type { GroupEntity } from "../../data/group";
|
import type { GroupEntity } from "../../data/group";
|
||||||
import { computeGroupDomain } from "../../data/group";
|
import { computeGroupDomain } from "../../data/group";
|
||||||
import { computeCssVariable } from "../../resources/css-variables";
|
import { computeCssVariable } from "../../resources/css-variables";
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import type {
|
|||||||
HassEntity,
|
HassEntity,
|
||||||
HassEntityAttributeBase,
|
HassEntityAttributeBase,
|
||||||
} from "home-assistant-js-websocket";
|
} from "home-assistant-js-websocket";
|
||||||
import type { EntityRegistryDisplayEntry } from "../../data/entity_registry";
|
import type { EntityRegistryDisplayEntry } from "../../data/entity/entity_registry";
|
||||||
import type { FrontendLocaleData } from "../../data/translation";
|
import type { FrontendLocaleData } from "../../data/translation";
|
||||||
import { NumberFormat } from "../../data/translation";
|
import { NumberFormat } from "../../data/translation";
|
||||||
import { round } from "./round";
|
import { round } from "./round";
|
||||||
|
|||||||
@@ -3,11 +3,11 @@ import { getGraphColorByIndex } from "../../common/color/colors";
|
|||||||
import { hex2rgb, lab2hex, rgb2lab } from "../../common/color/convert-color";
|
import { hex2rgb, lab2hex, rgb2lab } from "../../common/color/convert-color";
|
||||||
import { labBrighten } from "../../common/color/lab";
|
import { labBrighten } from "../../common/color/lab";
|
||||||
import { computeDomain } from "../../common/entity/compute_domain";
|
import { computeDomain } from "../../common/entity/compute_domain";
|
||||||
import { stateColorProperties } from "../../common/entity/state_color";
|
|
||||||
import { UNAVAILABLE, UNKNOWN } from "../../data/entity";
|
|
||||||
import { computeCssValue } from "../../resources/css-variables";
|
|
||||||
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
||||||
import { FIXED_DOMAIN_STATES } from "../../common/entity/get_states";
|
import { FIXED_DOMAIN_STATES } from "../../common/entity/get_states";
|
||||||
|
import { stateColorProperties } from "../../common/entity/state_color";
|
||||||
|
import { UNAVAILABLE, UNKNOWN } from "../../data/entity/entity";
|
||||||
|
import { computeCssValue } from "../../resources/css-variables";
|
||||||
|
|
||||||
const DOMAIN_STATE_SHADES: Record<string, Record<string, number>> = {
|
const DOMAIN_STATE_SHADES: Record<string, Record<string, number>> = {
|
||||||
media_player: {
|
media_player: {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { computeCssColor } from "../../common/color/compute-color";
|
|||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
import { stopPropagation } from "../../common/dom/stop_propagation";
|
import { stopPropagation } from "../../common/dom/stop_propagation";
|
||||||
import { stringCompare } from "../../common/string/compare";
|
import { stringCompare } from "../../common/string/compare";
|
||||||
import type { LabelRegistryEntry } from "../../data/label_registry";
|
import type { LabelRegistryEntry } from "../../data/label/label_registry";
|
||||||
import "../chips/ha-chip-set";
|
import "../chips/ha-chip-set";
|
||||||
import "../ha-dropdown";
|
import "../ha-dropdown";
|
||||||
import "../ha-dropdown-item";
|
import "../ha-dropdown-item";
|
||||||
|
|||||||
@@ -16,8 +16,10 @@ import memoizeOne from "memoize-one";
|
|||||||
import { restoreScroll } from "../../common/decorators/restore-scroll";
|
import { restoreScroll } from "../../common/decorators/restore-scroll";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
import { stringCompare } from "../../common/string/compare";
|
import { stringCompare } from "../../common/string/compare";
|
||||||
|
import type { LocalizeFunc } from "../../common/translations/localize";
|
||||||
import { debounce } from "../../common/util/debounce";
|
import { debounce } from "../../common/util/debounce";
|
||||||
import { groupBy } from "../../common/util/group-by";
|
import { groupBy } from "../../common/util/group-by";
|
||||||
|
import { nextRender } from "../../common/util/render-status";
|
||||||
import { haStyleScrollbar } from "../../resources/styles";
|
import { haStyleScrollbar } from "../../resources/styles";
|
||||||
import { loadVirtualizer } from "../../resources/virtualizer";
|
import { loadVirtualizer } from "../../resources/virtualizer";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
@@ -26,8 +28,6 @@ import type { HaCheckbox } from "../ha-checkbox";
|
|||||||
import "../ha-svg-icon";
|
import "../ha-svg-icon";
|
||||||
import "../search-input";
|
import "../search-input";
|
||||||
import { filterData, sortData } from "./sort-filter";
|
import { filterData, sortData } from "./sort-filter";
|
||||||
import type { LocalizeFunc } from "../../common/translations/localize";
|
|
||||||
import { nextRender } from "../../common/util/render-status";
|
|
||||||
|
|
||||||
export interface RowClickedEvent {
|
export interface RowClickedEvent {
|
||||||
id: string;
|
id: string;
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { expose } from "comlink";
|
import { expose } from "comlink";
|
||||||
import Fuse from "fuse.js";
|
import Fuse, { type FuseOptionKey } from "fuse.js";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { ipCompare, stringCompare } from "../../common/string/compare";
|
import { ipCompare, stringCompare } from "../../common/string/compare";
|
||||||
import { stripDiacritics } from "../../common/string/strip-diacritics";
|
import { stripDiacritics } from "../../common/string/strip-diacritics";
|
||||||
import { HaFuse } from "../../resources/fuse";
|
import { multiTermSearch } from "../../resources/fuseMultiTerm";
|
||||||
import type {
|
import type {
|
||||||
ClonedDataTableColumnData,
|
ClonedDataTableColumnData,
|
||||||
DataTableRowData,
|
DataTableRowData,
|
||||||
@@ -11,9 +11,10 @@ import type {
|
|||||||
SortingDirection,
|
SortingDirection,
|
||||||
} from "./ha-data-table";
|
} from "./ha-data-table";
|
||||||
|
|
||||||
const fuseIndex = memoizeOne(
|
const getSearchKeys = memoizeOne(
|
||||||
(data: DataTableRowData[], columns: SortableColumnContainer) => {
|
(columns: SortableColumnContainer): FuseOptionKey<DataTableRowData>[] => {
|
||||||
const searchKeys = new Set<string>();
|
const searchKeys = new Set<string>();
|
||||||
|
|
||||||
Object.entries(columns).forEach(([key, column]) => {
|
Object.entries(columns).forEach(([key, column]) => {
|
||||||
if (column.filterable) {
|
if (column.filterable) {
|
||||||
searchKeys.add(
|
searchKeys.add(
|
||||||
@@ -23,10 +24,15 @@ const fuseIndex = memoizeOne(
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return Fuse.createIndex([...searchKeys], data);
|
return Array.from(searchKeys);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const fuseIndex = memoizeOne(
|
||||||
|
(data: DataTableRowData[], keys: FuseOptionKey<DataTableRowData>[]) =>
|
||||||
|
Fuse.createIndex(keys, data)
|
||||||
|
);
|
||||||
|
|
||||||
const filterData = (
|
const filterData = (
|
||||||
data: DataTableRowData[],
|
data: DataTableRowData[],
|
||||||
columns: SortableColumnContainer,
|
columns: SortableColumnContainer,
|
||||||
@@ -38,21 +44,13 @@ const filterData = (
|
|||||||
return data;
|
return data;
|
||||||
}
|
}
|
||||||
|
|
||||||
const index = fuseIndex(data, columns);
|
const keys = getSearchKeys(columns);
|
||||||
|
|
||||||
const fuse = new HaFuse(
|
const index = fuseIndex(data, keys);
|
||||||
data,
|
|
||||||
{ shouldSort: false, minMatchCharLength: 1 },
|
|
||||||
index
|
|
||||||
);
|
|
||||||
|
|
||||||
const searchResults = fuse.multiTermsSearch(filter);
|
return multiTermSearch<DataTableRowData>(data, filter, keys, index, {
|
||||||
|
threshold: 0.2, // reduce fuzzy matches in data tables
|
||||||
if (searchResults) {
|
});
|
||||||
return searchResults.map((result) => result.item);
|
|
||||||
}
|
|
||||||
|
|
||||||
return data;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const sortData = (
|
const sortData = (
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { customElement } from "lit/decorators";
|
import { customElement } from "lit/decorators";
|
||||||
import type { DeviceAction } from "../../data/device_automation";
|
import type { DeviceAction } from "../../data/device/device_automation";
|
||||||
import {
|
import {
|
||||||
fetchDeviceActions,
|
fetchDeviceActions,
|
||||||
localizeDeviceAutomationAction,
|
localizeDeviceAutomationAction,
|
||||||
} from "../../data/device_automation";
|
} from "../../data/device/device_automation";
|
||||||
import { HaDeviceAutomationPicker } from "./ha-device-automation-picker";
|
import { HaDeviceAutomationPicker } from "./ha-device-automation-picker";
|
||||||
|
|
||||||
@customElement("ha-device-action-picker")
|
@customElement("ha-device-action-picker")
|
||||||
|
|||||||
@@ -2,17 +2,17 @@ import { consume } from "@lit/context";
|
|||||||
import { css, html, LitElement, nothing } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
import { property, state } from "lit/decorators";
|
import { property, state } from "lit/decorators";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
|
import { stopPropagation } from "../../common/dom/stop_propagation";
|
||||||
import { fullEntitiesContext } from "../../data/context";
|
import { fullEntitiesContext } from "../../data/context";
|
||||||
import type { DeviceAutomation } from "../../data/device_automation";
|
import type { DeviceAutomation } from "../../data/device/device_automation";
|
||||||
import {
|
import {
|
||||||
deviceAutomationsEqual,
|
deviceAutomationsEqual,
|
||||||
sortDeviceAutomations,
|
sortDeviceAutomations,
|
||||||
} from "../../data/device_automation";
|
} from "../../data/device/device_automation";
|
||||||
import type { EntityRegistryEntry } from "../../data/entity_registry";
|
import type { EntityRegistryEntry } from "../../data/entity/entity_registry";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import "../ha-md-select-option";
|
|
||||||
import "../ha-md-select";
|
import "../ha-md-select";
|
||||||
import { stopPropagation } from "../../common/dom/stop_propagation";
|
import "../ha-md-select-option";
|
||||||
|
|
||||||
const NO_AUTOMATION_KEY = "NO_AUTOMATION";
|
const NO_AUTOMATION_KEY = "NO_AUTOMATION";
|
||||||
const UNKNOWN_AUTOMATION_KEY = "UNKNOWN_AUTOMATION";
|
const UNKNOWN_AUTOMATION_KEY = "UNKNOWN_AUTOMATION";
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { customElement } from "lit/decorators";
|
import { customElement } from "lit/decorators";
|
||||||
import type { DeviceCondition } from "../../data/device_automation";
|
import type { DeviceCondition } from "../../data/device/device_automation";
|
||||||
import {
|
import {
|
||||||
fetchDeviceConditions,
|
fetchDeviceConditions,
|
||||||
localizeDeviceAutomationCondition,
|
localizeDeviceAutomationCondition,
|
||||||
} from "../../data/device_automation";
|
} from "../../data/device/device_automation";
|
||||||
import { HaDeviceAutomationPicker } from "./ha-device-automation-picker";
|
import { HaDeviceAutomationPicker } from "./ha-device-automation-picker";
|
||||||
|
|
||||||
@customElement("ha-device-condition-picker")
|
@customElement("ha-device-condition-picker")
|
||||||
|
|||||||
@@ -9,10 +9,11 @@ import { computeDeviceName } from "../../common/entity/compute_device_name";
|
|||||||
import { getDeviceContext } from "../../common/entity/context/get_device_context";
|
import { getDeviceContext } from "../../common/entity/context/get_device_context";
|
||||||
import { getConfigEntries, type ConfigEntry } from "../../data/config_entries";
|
import { getConfigEntries, type ConfigEntry } from "../../data/config_entries";
|
||||||
import {
|
import {
|
||||||
|
deviceComboBoxKeys,
|
||||||
getDevices,
|
getDevices,
|
||||||
type DevicePickerItem,
|
type DevicePickerItem,
|
||||||
type DeviceRegistryEntry,
|
} from "../../data/device/device_picker";
|
||||||
} from "../../data/device_registry";
|
import type { DeviceRegistryEntry } from "../../data/device/device_registry";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import { brandsUrl } from "../../util/brands-url";
|
import { brandsUrl } from "../../util/brands-url";
|
||||||
import "../ha-generic-picker";
|
import "../ha-generic-picker";
|
||||||
@@ -216,6 +217,10 @@ export class HaDevicePicker extends LitElement {
|
|||||||
.getItems=${this._getItems}
|
.getItems=${this._getItems}
|
||||||
.hideClearIcon=${this.hideClearIcon}
|
.hideClearIcon=${this.hideClearIcon}
|
||||||
.valueRenderer=${valueRenderer}
|
.valueRenderer=${valueRenderer}
|
||||||
|
.searchKeys=${deviceComboBoxKeys}
|
||||||
|
.unknownItemText=${this.hass.localize(
|
||||||
|
"ui.components.device-picker.unknown"
|
||||||
|
)}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
>
|
>
|
||||||
</ha-generic-picker>
|
</ha-generic-picker>
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { customElement } from "lit/decorators";
|
import { customElement } from "lit/decorators";
|
||||||
import type { DeviceTrigger } from "../../data/device_automation";
|
import type { DeviceTrigger } from "../../data/device/device_automation";
|
||||||
import {
|
import {
|
||||||
fetchDeviceTriggers,
|
fetchDeviceTriggers,
|
||||||
localizeDeviceAutomationTrigger,
|
localizeDeviceAutomationTrigger,
|
||||||
} from "../../data/device_automation";
|
} from "../../data/device/device_automation";
|
||||||
import { HaDeviceAutomationPicker } from "./ha-device-automation-picker";
|
import { HaDeviceAutomationPicker } from "./ha-device-automation-picker";
|
||||||
|
|
||||||
@customElement("ha-device-trigger-picker")
|
@customElement("ha-device-trigger-picker")
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import { customElement, property } 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 { isValidEntityId } from "../../common/entity/valid_entity_id";
|
import { isValidEntityId } from "../../common/entity/valid_entity_id";
|
||||||
import type { HaEntityPickerEntityFilterFunc } from "../../data/entity";
|
import type { HaEntityPickerEntityFilterFunc } from "../../data/entity/entity";
|
||||||
import type { HomeAssistant, ValueChangedEvent } from "../../types";
|
import type { HomeAssistant, ValueChangedEvent } from "../../types";
|
||||||
import "../ha-sortable";
|
import "../ha-sortable";
|
||||||
import "./ha-entity-picker";
|
import "./ha-entity-picker";
|
||||||
|
|||||||
@@ -7,11 +7,12 @@ import { fireEvent } from "../../common/dom/fire_event";
|
|||||||
import { computeEntityNameList } from "../../common/entity/compute_entity_name_display";
|
import { computeEntityNameList } from "../../common/entity/compute_entity_name_display";
|
||||||
import { isValidEntityId } from "../../common/entity/valid_entity_id";
|
import { isValidEntityId } from "../../common/entity/valid_entity_id";
|
||||||
import { computeRTL } from "../../common/util/compute_rtl";
|
import { computeRTL } from "../../common/util/compute_rtl";
|
||||||
import type { HaEntityPickerEntityFilterFunc } from "../../data/entity";
|
import type { HaEntityPickerEntityFilterFunc } from "../../data/entity/entity";
|
||||||
import {
|
import {
|
||||||
|
entityComboBoxKeys,
|
||||||
getEntities,
|
getEntities,
|
||||||
type EntityComboBoxItem,
|
type EntityComboBoxItem,
|
||||||
} from "../../data/entity_registry";
|
} from "../../data/entity/entity_picker";
|
||||||
import { domainToName } from "../../data/integration";
|
import { domainToName } from "../../data/integration";
|
||||||
import {
|
import {
|
||||||
isHelperDomain,
|
isHelperDomain,
|
||||||
@@ -227,7 +228,7 @@ export class HaEntityPicker extends LitElement {
|
|||||||
if (!createDomains?.length) {
|
if (!createDomains?.length) {
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
this.hass.loadFragmentTranslation("config");
|
||||||
return createDomains.map((domain) => {
|
return createDomains.map((domain) => {
|
||||||
const primary = localize(
|
const primary = localize(
|
||||||
"ui.components.entity.entity-picker.create_helper",
|
"ui.components.entity.entity-picker.create_helper",
|
||||||
@@ -235,7 +236,7 @@ export class HaEntityPicker extends LitElement {
|
|||||||
domain: isHelperDomain(domain)
|
domain: isHelperDomain(domain)
|
||||||
? localize(
|
? localize(
|
||||||
`ui.panel.config.helpers.types.${domain as HelperDomain}`
|
`ui.panel.config.helpers.types.${domain as HelperDomain}`
|
||||||
)
|
) || domain
|
||||||
: domainToName(localize, domain),
|
: domainToName(localize, domain),
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -288,10 +289,14 @@ export class HaEntityPicker extends LitElement {
|
|||||||
.hideClearIcon=${this.hideClearIcon}
|
.hideClearIcon=${this.hideClearIcon}
|
||||||
.searchFn=${this._searchFn}
|
.searchFn=${this._searchFn}
|
||||||
.valueRenderer=${this._valueRenderer}
|
.valueRenderer=${this._valueRenderer}
|
||||||
@value-changed=${this._valueChanged}
|
.searchKeys=${entityComboBoxKeys}
|
||||||
.addButtonLabel=${this.addButton
|
.addButtonLabel=${this.addButton
|
||||||
? this.hass.localize("ui.components.entity.entity-picker.add")
|
? this.hass.localize("ui.components.entity.entity-picker.add")
|
||||||
: undefined}
|
: undefined}
|
||||||
|
.unknownItemText=${this.hass.localize(
|
||||||
|
"ui.components.entity.entity-picker.unknown"
|
||||||
|
)}
|
||||||
|
@value-changed=${this._valueChanged}
|
||||||
>
|
>
|
||||||
</ha-generic-picker>
|
</ha-generic-picker>
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -6,7 +6,11 @@ import { customElement, property, state } from "lit/decorators";
|
|||||||
import { STATES_OFF } from "../../common/const";
|
import { STATES_OFF } from "../../common/const";
|
||||||
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
import { computeStateDomain } from "../../common/entity/compute_state_domain";
|
||||||
import { computeStateName } from "../../common/entity/compute_state_name";
|
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||||
import { UNAVAILABLE, UNKNOWN, isUnavailableState } from "../../data/entity";
|
import {
|
||||||
|
UNAVAILABLE,
|
||||||
|
UNKNOWN,
|
||||||
|
isUnavailableState,
|
||||||
|
} from "../../data/entity/entity";
|
||||||
import { forwardHaptic } from "../../data/haptics";
|
import { forwardHaptic } from "../../data/haptics";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import "../ha-formfield";
|
import "../ha-formfield";
|
||||||
|
|||||||
@@ -14,8 +14,12 @@ import {
|
|||||||
getNumberFormatOptions,
|
getNumberFormatOptions,
|
||||||
isNumericState,
|
isNumericState,
|
||||||
} from "../../common/number/format_number";
|
} from "../../common/number/format_number";
|
||||||
import { isUnavailableState, UNAVAILABLE, UNKNOWN } from "../../data/entity";
|
import {
|
||||||
import type { EntityRegistryDisplayEntry } from "../../data/entity_registry";
|
isUnavailableState,
|
||||||
|
UNAVAILABLE,
|
||||||
|
UNKNOWN,
|
||||||
|
} from "../../data/entity/entity";
|
||||||
|
import type { EntityRegistryDisplayEntry } from "../../data/entity/entity_registry";
|
||||||
import { timerTimeRemaining } from "../../data/timer";
|
import { timerTimeRemaining } from "../../data/timer";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import "../ha-label-badge";
|
import "../ha-label-badge";
|
||||||
|
|||||||
@@ -38,9 +38,21 @@ type StatisticItemType = "entity" | "external" | "no_state";
|
|||||||
interface StatisticComboBoxItem extends PickerComboBoxItem {
|
interface StatisticComboBoxItem extends PickerComboBoxItem {
|
||||||
statistic_id?: string;
|
statistic_id?: string;
|
||||||
stateObj?: HassEntity;
|
stateObj?: HassEntity;
|
||||||
|
domainName?: string;
|
||||||
type?: StatisticItemType;
|
type?: StatisticItemType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SEARCH_KEYS = [
|
||||||
|
{ name: "label", weight: 10 },
|
||||||
|
{ name: "search_labels.entityName", weight: 10 },
|
||||||
|
{ name: "search_labels.friendlyName", weight: 9 },
|
||||||
|
{ name: "search_labels.deviceName", weight: 8 },
|
||||||
|
{ name: "search_labels.areaName", weight: 6 },
|
||||||
|
{ name: "search_labels.domainName", weight: 4 },
|
||||||
|
{ name: "statisticId", weight: 3 },
|
||||||
|
{ name: "id", weight: 2 },
|
||||||
|
];
|
||||||
|
|
||||||
@customElement("ha-statistic-picker")
|
@customElement("ha-statistic-picker")
|
||||||
export class HaStatisticPicker extends LitElement {
|
export class HaStatisticPicker extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
@@ -233,7 +245,6 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
),
|
),
|
||||||
type,
|
type,
|
||||||
sorting_label: [sortingPrefix, label].join("_"),
|
sorting_label: [sortingPrefix, label].join("_"),
|
||||||
search_labels: [label, id],
|
|
||||||
icon_path: mdiShape,
|
icon_path: mdiShape,
|
||||||
});
|
});
|
||||||
} else if (type === "external") {
|
} else if (type === "external") {
|
||||||
@@ -246,7 +257,7 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
secondary: domainName,
|
secondary: domainName,
|
||||||
type,
|
type,
|
||||||
sorting_label: [sortingPrefix, label].join("_"),
|
sorting_label: [sortingPrefix, label].join("_"),
|
||||||
search_labels: [label, domainName, id],
|
search_labels: { label, domainName },
|
||||||
icon_path: mdiChartLine,
|
icon_path: mdiChartLine,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -280,13 +291,12 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
stateObj: stateObj,
|
stateObj: stateObj,
|
||||||
type: "entity",
|
type: "entity",
|
||||||
sorting_label: [sortingPrefix, deviceName, entityName].join("_"),
|
sorting_label: [sortingPrefix, deviceName, entityName].join("_"),
|
||||||
search_labels: [
|
search_labels: {
|
||||||
entityName,
|
entityName: entityName || null,
|
||||||
deviceName,
|
deviceName: deviceName || null,
|
||||||
areaName,
|
areaName: areaName || null,
|
||||||
friendlyName,
|
friendlyName,
|
||||||
id,
|
},
|
||||||
].filter(Boolean) as string[],
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -361,13 +371,13 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
stateObj: stateObj,
|
stateObj: stateObj,
|
||||||
type: "entity",
|
type: "entity",
|
||||||
sorting_label: [sortingPrefix, deviceName, entityName].join("_"),
|
sorting_label: [sortingPrefix, deviceName, entityName].join("_"),
|
||||||
search_labels: [
|
search_labels: {
|
||||||
entityName,
|
entityName: entityName || null,
|
||||||
deviceName,
|
deviceName: deviceName || null,
|
||||||
areaName,
|
areaName: areaName || null,
|
||||||
friendlyName,
|
friendlyName,
|
||||||
statisticId,
|
statisticId,
|
||||||
].filter(Boolean) as string[],
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -394,7 +404,7 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
secondary: domainName,
|
secondary: domainName,
|
||||||
type: "external",
|
type: "external",
|
||||||
sorting_label: [sortingPrefix, label].join("_"),
|
sorting_label: [sortingPrefix, label].join("_"),
|
||||||
search_labels: [label, domainName, statisticId],
|
search_labels: { label, domainName, statisticId },
|
||||||
icon_path: mdiChartLine,
|
icon_path: mdiChartLine,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -409,7 +419,7 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
secondary: this.hass.localize("ui.components.statistic-picker.no_state"),
|
secondary: this.hass.localize("ui.components.statistic-picker.no_state"),
|
||||||
type: "no_state",
|
type: "no_state",
|
||||||
sorting_label: [sortingPrefix, label].join("_"),
|
sorting_label: [sortingPrefix, label].join("_"),
|
||||||
search_labels: [label, statisticId],
|
search_labels: { label, statisticId },
|
||||||
icon_path: mdiShape,
|
icon_path: mdiShape,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -475,6 +485,10 @@ export class HaStatisticPicker extends LitElement {
|
|||||||
.searchFn=${this._searchFn}
|
.searchFn=${this._searchFn}
|
||||||
.valueRenderer=${this._valueRenderer}
|
.valueRenderer=${this._valueRenderer}
|
||||||
.helper=${this.helper}
|
.helper=${this.helper}
|
||||||
|
.searchKeys=${SEARCH_KEYS}
|
||||||
|
.unknownItemText=${this.hass.localize(
|
||||||
|
"ui.components.statistic-picker.unknown"
|
||||||
|
)}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
>
|
>
|
||||||
</ha-generic-picker>
|
</ha-generic-picker>
|
||||||
|
|||||||
@@ -1,270 +0,0 @@
|
|||||||
import { mdiTextureBox } from "@mdi/js";
|
|
||||||
import type { ComboBoxLitRenderer } from "@vaadin/combo-box/lit";
|
|
||||||
import type { HassEntity } from "home-assistant-js-websocket";
|
|
||||||
import type { TemplateResult } from "lit";
|
|
||||||
import { LitElement, html, nothing } from "lit";
|
|
||||||
import { customElement, property, query } from "lit/decorators";
|
|
||||||
import { styleMap } from "lit/directives/style-map";
|
|
||||||
import memoizeOne from "memoize-one";
|
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
|
||||||
import { computeAreaName } from "../common/entity/compute_area_name";
|
|
||||||
import { computeFloorName } from "../common/entity/compute_floor_name";
|
|
||||||
import { computeRTL } from "../common/util/compute_rtl";
|
|
||||||
import {
|
|
||||||
getAreasAndFloors,
|
|
||||||
type AreaFloorValue,
|
|
||||||
type FloorComboBoxItem,
|
|
||||||
} from "../data/area_floor";
|
|
||||||
import type { HomeAssistant, ValueChangedEvent } from "../types";
|
|
||||||
import type { HaDevicePickerDeviceFilterFunc } from "./device/ha-device-picker";
|
|
||||||
import "./ha-combo-box-item";
|
|
||||||
import "./ha-floor-icon";
|
|
||||||
import "./ha-generic-picker";
|
|
||||||
import type { HaGenericPicker } from "./ha-generic-picker";
|
|
||||||
import "./ha-icon-button";
|
|
||||||
import type { PickerValueRenderer } from "./ha-picker-field";
|
|
||||||
import "./ha-svg-icon";
|
|
||||||
import "./ha-tree-indicator";
|
|
||||||
|
|
||||||
const SEPARATOR = "________";
|
|
||||||
|
|
||||||
@customElement("ha-area-floor-picker")
|
|
||||||
export class HaAreaFloorPicker extends LitElement {
|
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
|
||||||
|
|
||||||
@property() public label?: string;
|
|
||||||
|
|
||||||
@property({ attribute: false }) public value?: AreaFloorValue;
|
|
||||||
|
|
||||||
@property() public helper?: string;
|
|
||||||
|
|
||||||
@property() public placeholder?: string;
|
|
||||||
|
|
||||||
@property({ type: String, attribute: "search-label" })
|
|
||||||
public searchLabel?: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show only areas with entities from specific domains.
|
|
||||||
* @type {Array}
|
|
||||||
* @attr include-domains
|
|
||||||
*/
|
|
||||||
@property({ type: Array, attribute: "include-domains" })
|
|
||||||
public includeDomains?: string[];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show no areas with entities of these domains.
|
|
||||||
* @type {Array}
|
|
||||||
* @attr exclude-domains
|
|
||||||
*/
|
|
||||||
@property({ type: Array, attribute: "exclude-domains" })
|
|
||||||
public excludeDomains?: string[];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show only areas with entities of these device classes.
|
|
||||||
* @type {Array}
|
|
||||||
* @attr include-device-classes
|
|
||||||
*/
|
|
||||||
@property({ type: Array, attribute: "include-device-classes" })
|
|
||||||
public includeDeviceClasses?: string[];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of areas to be excluded.
|
|
||||||
* @type {Array}
|
|
||||||
* @attr exclude-areas
|
|
||||||
*/
|
|
||||||
@property({ type: Array, attribute: "exclude-areas" })
|
|
||||||
public excludeAreas?: string[];
|
|
||||||
|
|
||||||
/**
|
|
||||||
* List of floors to be excluded.
|
|
||||||
* @type {Array}
|
|
||||||
* @attr exclude-floors
|
|
||||||
*/
|
|
||||||
@property({ type: Array, attribute: "exclude-floors" })
|
|
||||||
public excludeFloors?: string[];
|
|
||||||
|
|
||||||
@property({ attribute: false })
|
|
||||||
public deviceFilter?: HaDevicePickerDeviceFilterFunc;
|
|
||||||
|
|
||||||
@property({ attribute: false })
|
|
||||||
public entityFilter?: (entity: HassEntity) => boolean;
|
|
||||||
|
|
||||||
@property({ type: Boolean }) public disabled = false;
|
|
||||||
|
|
||||||
@property({ type: Boolean }) public required = false;
|
|
||||||
|
|
||||||
@query("ha-generic-picker") private _picker?: HaGenericPicker;
|
|
||||||
|
|
||||||
public async open() {
|
|
||||||
await this.updateComplete;
|
|
||||||
await this._picker?.open();
|
|
||||||
}
|
|
||||||
|
|
||||||
private _valueRenderer: PickerValueRenderer = (value: string) => {
|
|
||||||
const item = this._parseValue(value);
|
|
||||||
|
|
||||||
const area = item.type === "area" && this.hass.areas[value];
|
|
||||||
|
|
||||||
if (area) {
|
|
||||||
const areaName = computeAreaName(area);
|
|
||||||
return html`
|
|
||||||
${area.icon
|
|
||||||
? html`<ha-icon slot="start" .icon=${area.icon}></ha-icon>`
|
|
||||||
: html`<ha-svg-icon
|
|
||||||
slot="start"
|
|
||||||
.path=${mdiTextureBox}
|
|
||||||
></ha-svg-icon>`}
|
|
||||||
<slot name="headline">${areaName}</slot>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
const floor = item.type === "floor" && this.hass.floors[value];
|
|
||||||
|
|
||||||
if (floor) {
|
|
||||||
const floorName = computeFloorName(floor);
|
|
||||||
return html`
|
|
||||||
<ha-floor-icon slot="start" .floor=${floor}></ha-floor-icon>
|
|
||||||
<span slot="headline">${floorName}</span>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
return html`
|
|
||||||
<ha-svg-icon slot="start" .path=${mdiTextureBox}></ha-svg-icon>
|
|
||||||
<span slot="headline">${value}</span>
|
|
||||||
`;
|
|
||||||
};
|
|
||||||
|
|
||||||
private _rowRenderer: ComboBoxLitRenderer<FloorComboBoxItem> = (
|
|
||||||
item,
|
|
||||||
{ index },
|
|
||||||
combobox
|
|
||||||
) => {
|
|
||||||
const nextItem = combobox.filteredItems?.[index + 1];
|
|
||||||
const isLastArea =
|
|
||||||
!nextItem ||
|
|
||||||
nextItem.type === "floor" ||
|
|
||||||
(nextItem.type === "area" && !nextItem.area?.floor_id);
|
|
||||||
|
|
||||||
const rtl = computeRTL(this.hass);
|
|
||||||
|
|
||||||
const hasFloor = item.type === "area" && item.area?.floor_id;
|
|
||||||
|
|
||||||
return html`
|
|
||||||
<ha-combo-box-item
|
|
||||||
type="button"
|
|
||||||
style=${item.type === "area" && hasFloor
|
|
||||||
? "--md-list-item-leading-space: 48px;"
|
|
||||||
: ""}
|
|
||||||
>
|
|
||||||
${item.type === "area" && hasFloor
|
|
||||||
? html`
|
|
||||||
<ha-tree-indicator
|
|
||||||
style=${styleMap({
|
|
||||||
width: "48px",
|
|
||||||
position: "absolute",
|
|
||||||
top: "0px",
|
|
||||||
left: rtl ? undefined : "4px",
|
|
||||||
right: rtl ? "4px" : undefined,
|
|
||||||
transform: rtl ? "scaleX(-1)" : "",
|
|
||||||
})}
|
|
||||||
.end=${isLastArea}
|
|
||||||
slot="start"
|
|
||||||
></ha-tree-indicator>
|
|
||||||
`
|
|
||||||
: nothing}
|
|
||||||
${item.type === "floor" && item.floor
|
|
||||||
? html`<ha-floor-icon
|
|
||||||
slot="start"
|
|
||||||
.floor=${item.floor}
|
|
||||||
></ha-floor-icon>`
|
|
||||||
: item.icon
|
|
||||||
? html`<ha-icon slot="start" .icon=${item.icon}></ha-icon>`
|
|
||||||
: html`<ha-svg-icon
|
|
||||||
slot="start"
|
|
||||||
.path=${item.icon_path || mdiTextureBox}
|
|
||||||
></ha-svg-icon>`}
|
|
||||||
${item.primary}
|
|
||||||
</ha-combo-box-item>
|
|
||||||
`;
|
|
||||||
};
|
|
||||||
|
|
||||||
private _getAreasAndFloorsMemoized = memoizeOne(getAreasAndFloors);
|
|
||||||
|
|
||||||
private _getItems = () =>
|
|
||||||
this._getAreasAndFloorsMemoized(
|
|
||||||
this.hass.states,
|
|
||||||
this.hass.floors,
|
|
||||||
this.hass.areas,
|
|
||||||
this.hass.devices,
|
|
||||||
this.hass.entities,
|
|
||||||
this._formatValue,
|
|
||||||
this.includeDomains,
|
|
||||||
this.excludeDomains,
|
|
||||||
this.includeDeviceClasses,
|
|
||||||
this.deviceFilter,
|
|
||||||
this.entityFilter,
|
|
||||||
this.excludeAreas,
|
|
||||||
this.excludeFloors
|
|
||||||
);
|
|
||||||
|
|
||||||
private _formatValue = memoizeOne((value: AreaFloorValue): string =>
|
|
||||||
[value.type, value.id].join(SEPARATOR)
|
|
||||||
);
|
|
||||||
|
|
||||||
private _parseValue = memoizeOne((value: string): AreaFloorValue => {
|
|
||||||
const [type, id] = value.split(SEPARATOR);
|
|
||||||
|
|
||||||
return { id, type: type as "floor" | "area" };
|
|
||||||
});
|
|
||||||
|
|
||||||
protected render(): TemplateResult {
|
|
||||||
const placeholder =
|
|
||||||
this.placeholder ?? this.hass.localize("ui.components.area-picker.area");
|
|
||||||
|
|
||||||
const value = this.value ? this._formatValue(this.value) : undefined;
|
|
||||||
|
|
||||||
return html`
|
|
||||||
<ha-generic-picker
|
|
||||||
.hass=${this.hass}
|
|
||||||
.autofocus=${this.autofocus}
|
|
||||||
.label=${this.label}
|
|
||||||
.searchLabel=${this.searchLabel}
|
|
||||||
.notFoundLabel=${this.hass.localize(
|
|
||||||
"ui.components.area-picker.no_match"
|
|
||||||
)}
|
|
||||||
.placeholder=${placeholder}
|
|
||||||
.value=${value}
|
|
||||||
.getItems=${this._getItems}
|
|
||||||
.valueRenderer=${this._valueRenderer}
|
|
||||||
.rowRenderer=${this._rowRenderer}
|
|
||||||
@value-changed=${this._valueChanged}
|
|
||||||
>
|
|
||||||
</ha-generic-picker>
|
|
||||||
`;
|
|
||||||
}
|
|
||||||
|
|
||||||
private _valueChanged(ev: ValueChangedEvent<string>) {
|
|
||||||
ev.stopPropagation();
|
|
||||||
const value = ev.detail.value;
|
|
||||||
|
|
||||||
if (!value) {
|
|
||||||
this._setValue(undefined);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const selected = this._parseValue(value);
|
|
||||||
this._setValue(selected);
|
|
||||||
}
|
|
||||||
|
|
||||||
private _setValue(value?: AreaFloorValue) {
|
|
||||||
this.value = value;
|
|
||||||
fireEvent(this, "value-changed", { value });
|
|
||||||
fireEvent(this, "change");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
declare global {
|
|
||||||
interface HTMLElementTagNameMap {
|
|
||||||
"ha-area-floor-picker": HaAreaFloorPicker;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -13,9 +13,9 @@ import { createAreaRegistryEntry } from "../data/area_registry";
|
|||||||
import type {
|
import type {
|
||||||
DeviceEntityDisplayLookup,
|
DeviceEntityDisplayLookup,
|
||||||
DeviceRegistryEntry,
|
DeviceRegistryEntry,
|
||||||
} from "../data/device_registry";
|
} from "../data/device/device_registry";
|
||||||
import { getDeviceEntityDisplayLookup } from "../data/device_registry";
|
import { getDeviceEntityDisplayLookup } from "../data/device/device_registry";
|
||||||
import type { EntityRegistryDisplayEntry } from "../data/entity_registry";
|
import type { EntityRegistryDisplayEntry } from "../data/entity/entity_registry";
|
||||||
import { showAlertDialog } from "../dialogs/generic/show-dialog-box";
|
import { showAlertDialog } from "../dialogs/generic/show-dialog-box";
|
||||||
import { showAreaRegistryDetailDialog } from "../panels/config/areas/show-dialog-area-registry-detail";
|
import { showAreaRegistryDetailDialog } from "../panels/config/areas/show-dialog-area-registry-detail";
|
||||||
import type { HomeAssistant, ValueChangedEvent } from "../types";
|
import type { HomeAssistant, ValueChangedEvent } from "../types";
|
||||||
@@ -30,6 +30,12 @@ import "./ha-svg-icon";
|
|||||||
|
|
||||||
const ADD_NEW_ID = "___ADD_NEW___";
|
const ADD_NEW_ID = "___ADD_NEW___";
|
||||||
|
|
||||||
|
const SEARCH_KEYS = [
|
||||||
|
{ name: "search_labels.areaName", weight: 10 },
|
||||||
|
{ name: "search_labels.aliases", weight: 8 },
|
||||||
|
{ name: "search_labels.floorName", weight: 6 },
|
||||||
|
{ name: "search_labels.id", weight: 3 },
|
||||||
|
];
|
||||||
@customElement("ha-area-picker")
|
@customElement("ha-area-picker")
|
||||||
export class HaAreaPicker extends LitElement {
|
export class HaAreaPicker extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
@@ -290,13 +296,12 @@ export class HaAreaPicker extends LitElement {
|
|||||||
secondary: floorName,
|
secondary: floorName,
|
||||||
icon: area.icon || undefined,
|
icon: area.icon || undefined,
|
||||||
icon_path: area.icon ? undefined : mdiTextureBox,
|
icon_path: area.icon ? undefined : mdiTextureBox,
|
||||||
sorting_label: areaName,
|
search_labels: {
|
||||||
search_labels: [
|
areaName: areaName || null,
|
||||||
areaName,
|
floorName: floorName || null,
|
||||||
floorName,
|
id: area.area_id,
|
||||||
area.area_id,
|
aliases: area.aliases.join(" "),
|
||||||
...area.aliases,
|
},
|
||||||
].filter((v): v is string => Boolean(v)),
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -379,6 +384,10 @@ export class HaAreaPicker extends LitElement {
|
|||||||
.getAdditionalItems=${this._getAdditionalItems}
|
.getAdditionalItems=${this._getAdditionalItems}
|
||||||
.valueRenderer=${valueRenderer}
|
.valueRenderer=${valueRenderer}
|
||||||
.addButtonLabel=${this.addButtonLabel}
|
.addButtonLabel=${this.addButtonLabel}
|
||||||
|
.searchKeys=${SEARCH_KEYS}
|
||||||
|
.unknownItemText=${this.hass.localize(
|
||||||
|
"ui.components.area-picker.unknown"
|
||||||
|
)}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
>
|
>
|
||||||
</ha-generic-picker>
|
</ha-generic-picker>
|
||||||
|
|||||||
@@ -659,7 +659,7 @@ export class HaAssistChat extends LitElement {
|
|||||||
--markdown-table-border-color: var(--divider-color);
|
--markdown-table-border-color: var(--divider-color);
|
||||||
--markdown-code-background-color: var(--primary-background-color);
|
--markdown-code-background-color: var(--primary-background-color);
|
||||||
--markdown-code-text-color: var(--primary-text-color);
|
--markdown-code-text-color: var(--primary-text-color);
|
||||||
--markdown-list-indent: 1rem;
|
--markdown-list-indent: 1.15em;
|
||||||
&:not(:has(ha-markdown-element)) {
|
&:not(:has(ha-markdown-element)) {
|
||||||
min-height: 1lh;
|
min-height: 1lh;
|
||||||
min-width: 1lh;
|
min-width: 1lh;
|
||||||
|
|||||||
@@ -3,15 +3,15 @@ import type { CSSResultGroup, PropertyValues } from "lit";
|
|||||||
import { css, html, LitElement, nothing } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { computeAttributeNameDisplay } from "../common/entity/compute_attribute_display";
|
import { computeAttributeNameDisplay } from "../common/entity/compute_attribute_display";
|
||||||
|
import { computeStateDomain } from "../common/entity/compute_state_domain";
|
||||||
import {
|
import {
|
||||||
STATE_ATTRIBUTES,
|
STATE_ATTRIBUTES,
|
||||||
STATE_ATTRIBUTES_DOMAIN_CLASS,
|
STATE_ATTRIBUTES_DOMAIN_CLASS,
|
||||||
} from "../data/entity_attributes";
|
} from "../data/entity/entity_attributes";
|
||||||
import { haStyle } from "../resources/styles";
|
import { haStyle } from "../resources/styles";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
import "./ha-attribute-value";
|
import "./ha-attribute-value";
|
||||||
import "./ha-expansion-panel";
|
import "./ha-expansion-panel";
|
||||||
import { computeStateDomain } from "../common/entity/compute_state_domain";
|
|
||||||
|
|
||||||
@customElement("ha-attributes")
|
@customElement("ha-attributes")
|
||||||
class HaAttributes extends LitElement {
|
class HaAttributes extends LitElement {
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ import { css, html, LitElement, nothing } from "lit";
|
|||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import type { ClimateEntity } from "../data/climate";
|
import type { ClimateEntity } from "../data/climate";
|
||||||
import { CLIMATE_PRESET_NONE } from "../data/climate";
|
import { CLIMATE_PRESET_NONE } from "../data/climate";
|
||||||
import { isUnavailableState, OFF } from "../data/entity";
|
import { isUnavailableState, OFF } from "../data/entity/entity";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
|
|
||||||
@customElement("ha-climate-state")
|
@customElement("ha-climate-state")
|
||||||
|
|||||||
@@ -9,14 +9,14 @@ import type { ConfigEntry, SubEntry } from "../data/config_entries";
|
|||||||
import { getConfigEntry, getSubEntries } from "../data/config_entries";
|
import { getConfigEntry, getSubEntries } from "../data/config_entries";
|
||||||
import type { Agent } from "../data/conversation";
|
import type { Agent } from "../data/conversation";
|
||||||
import { listAgents } from "../data/conversation";
|
import { listAgents } from "../data/conversation";
|
||||||
|
import { getExtendedEntityRegistryEntry } from "../data/entity/entity_registry";
|
||||||
import { fetchIntegrationManifest } from "../data/integration";
|
import { fetchIntegrationManifest } from "../data/integration";
|
||||||
import { showOptionsFlowDialog } from "../dialogs/config-flow/show-dialog-options-flow";
|
import { showOptionsFlowDialog } from "../dialogs/config-flow/show-dialog-options-flow";
|
||||||
|
import { showSubConfigFlowDialog } from "../dialogs/config-flow/show-dialog-sub-config-flow";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
import "./ha-list-item";
|
import "./ha-list-item";
|
||||||
import "./ha-select";
|
import "./ha-select";
|
||||||
import type { HaSelect } from "./ha-select";
|
import type { HaSelect } from "./ha-select";
|
||||||
import { getExtendedEntityRegistryEntry } from "../data/entity_registry";
|
|
||||||
import { showSubConfigFlowDialog } from "../dialogs/config-flow/show-dialog-sub-config-flow";
|
|
||||||
|
|
||||||
const NONE = "__NONE_OPTION__";
|
const NONE = "__NONE_OPTION__";
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,9 @@
|
|||||||
import DropdownItem from "@home-assistant/webawesome/dist/components/dropdown-item/dropdown-item";
|
import DropdownItem from "@home-assistant/webawesome/dist/components/dropdown-item/dropdown-item";
|
||||||
import { css, type CSSResultGroup } from "lit";
|
import "@home-assistant/webawesome/dist/components/icon/icon";
|
||||||
|
import { css, type CSSResultGroup, html } from "lit";
|
||||||
import { customElement } from "lit/decorators";
|
import { customElement } from "lit/decorators";
|
||||||
|
import "./ha-svg-icon";
|
||||||
|
import { mdiCheckboxBlankOutline, mdiCheckboxMarked } from "@mdi/js";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Home Assistant dropdown item component
|
* Home Assistant dropdown item component
|
||||||
@@ -14,6 +17,16 @@ import { customElement } from "lit/decorators";
|
|||||||
*/
|
*/
|
||||||
@customElement("ha-dropdown-item")
|
@customElement("ha-dropdown-item")
|
||||||
export class HaDropdownItem extends DropdownItem {
|
export class HaDropdownItem extends DropdownItem {
|
||||||
|
protected renderCheckboxIcon() {
|
||||||
|
return html`
|
||||||
|
<ha-svg-icon
|
||||||
|
id="check"
|
||||||
|
part="checkmark"
|
||||||
|
.path=${this.checked ? mdiCheckboxMarked : mdiCheckboxBlankOutline}
|
||||||
|
></ha-svg-icon>
|
||||||
|
`;
|
||||||
|
}
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return [
|
return [
|
||||||
DropdownItem.styles,
|
DropdownItem.styles,
|
||||||
@@ -22,6 +35,10 @@ export class HaDropdownItem extends DropdownItem {
|
|||||||
min-height: var(--ha-space-10);
|
min-height: var(--ha-space-10);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#check {
|
||||||
|
visibility: visible;
|
||||||
|
}
|
||||||
|
|
||||||
#icon ::slotted(*) {
|
#icon ::slotted(*) {
|
||||||
color: var(--ha-color-on-neutral-normal);
|
color: var(--ha-color-on-neutral-normal);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,8 +10,8 @@ import { computeCssColor } from "../common/color/compute-color";
|
|||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { navigate } from "../common/navigate";
|
import { navigate } from "../common/navigate";
|
||||||
import { stringCompare } from "../common/string/compare";
|
import { stringCompare } from "../common/string/compare";
|
||||||
import type { LabelRegistryEntry } from "../data/label_registry";
|
import type { LabelRegistryEntry } from "../data/label/label_registry";
|
||||||
import { subscribeLabelRegistry } from "../data/label_registry";
|
import { subscribeLabelRegistry } from "../data/label/label_registry";
|
||||||
import { SubscribeMixin } from "../mixins/subscribe-mixin";
|
import { SubscribeMixin } from "../mixins/subscribe-mixin";
|
||||||
import { haStyleScrollbar } from "../resources/styles";
|
import { haStyleScrollbar } from "../resources/styles";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
|
|||||||
@@ -12,9 +12,9 @@ import { updateAreaRegistryEntry } from "../data/area_registry";
|
|||||||
import type {
|
import type {
|
||||||
DeviceEntityDisplayLookup,
|
DeviceEntityDisplayLookup,
|
||||||
DeviceRegistryEntry,
|
DeviceRegistryEntry,
|
||||||
} from "../data/device_registry";
|
} from "../data/device/device_registry";
|
||||||
import { getDeviceEntityDisplayLookup } from "../data/device_registry";
|
import { getDeviceEntityDisplayLookup } from "../data/device/device_registry";
|
||||||
import type { EntityRegistryDisplayEntry } from "../data/entity_registry";
|
import type { EntityRegistryDisplayEntry } from "../data/entity/entity_registry";
|
||||||
import {
|
import {
|
||||||
createFloorRegistryEntry,
|
createFloorRegistryEntry,
|
||||||
getFloorAreaLookup,
|
getFloorAreaLookup,
|
||||||
@@ -35,6 +35,12 @@ import "./ha-svg-icon";
|
|||||||
|
|
||||||
const ADD_NEW_ID = "___ADD_NEW___";
|
const ADD_NEW_ID = "___ADD_NEW___";
|
||||||
|
|
||||||
|
const SEARCH_KEYS = [
|
||||||
|
{ name: "search_labels.floorName", weight: 10 },
|
||||||
|
{ name: "search_labels.aliases", weight: 8 },
|
||||||
|
{ name: "search_labels.floor_id", weight: 3 },
|
||||||
|
];
|
||||||
|
|
||||||
interface FloorComboBoxItem extends PickerComboBoxItem {
|
interface FloorComboBoxItem extends PickerComboBoxItem {
|
||||||
floor?: FloorRegistryEntry;
|
floor?: FloorRegistryEntry;
|
||||||
}
|
}
|
||||||
@@ -285,10 +291,11 @@ export class HaFloorPicker extends LitElement {
|
|||||||
id: floor.floor_id,
|
id: floor.floor_id,
|
||||||
primary: floorName,
|
primary: floorName,
|
||||||
floor: floor,
|
floor: floor,
|
||||||
sorting_label: floor.level?.toString() || "zzzzz",
|
search_labels: {
|
||||||
search_labels: [floorName, floor.floor_id, ...floor.aliases].filter(
|
floorName,
|
||||||
(v): v is string => Boolean(v)
|
floor_id: floor.floor_id,
|
||||||
),
|
aliases: floor.aliases.join(" "),
|
||||||
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -393,6 +400,10 @@ export class HaFloorPicker extends LitElement {
|
|||||||
.getAdditionalItems=${this._getAdditionalItems}
|
.getAdditionalItems=${this._getAdditionalItems}
|
||||||
.valueRenderer=${valueRenderer}
|
.valueRenderer=${valueRenderer}
|
||||||
.rowRenderer=${this._rowRenderer}
|
.rowRenderer=${this._rowRenderer}
|
||||||
|
.searchKeys=${SEARCH_KEYS}
|
||||||
|
.unknownItemText=${this.hass.localize(
|
||||||
|
"ui.components.floor-picker.unknown"
|
||||||
|
)}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
>
|
>
|
||||||
</ha-generic-picker>
|
</ha-generic-picker>
|
||||||
|
|||||||
@@ -4,8 +4,10 @@ import { mdiPlaylistPlus } from "@mdi/js";
|
|||||||
import { css, html, LitElement, nothing, type CSSResultGroup } from "lit";
|
import { css, html, LitElement, nothing, type CSSResultGroup } from "lit";
|
||||||
import { customElement, property, query, state } from "lit/decorators";
|
import { customElement, property, query, state } from "lit/decorators";
|
||||||
import { ifDefined } from "lit/directives/if-defined";
|
import { ifDefined } from "lit/directives/if-defined";
|
||||||
|
import memoizeOne from "memoize-one";
|
||||||
import { tinykeys } from "tinykeys";
|
import { tinykeys } from "tinykeys";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
|
import type { FuseWeightedKey } from "../resources/fuseMultiTerm";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
import "./ha-bottom-sheet";
|
import "./ha-bottom-sheet";
|
||||||
import "./ha-button";
|
import "./ha-button";
|
||||||
@@ -46,8 +48,9 @@ export class HaGenericPicker extends LitElement {
|
|||||||
@property({ attribute: "hide-clear-icon", type: Boolean })
|
@property({ attribute: "hide-clear-icon", type: Boolean })
|
||||||
public hideClearIcon = false;
|
public hideClearIcon = false;
|
||||||
|
|
||||||
|
/** To prevent lags, getItems needs to be memoized */
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public getItems?: (
|
public getItems!: (
|
||||||
searchString?: string,
|
searchString?: string,
|
||||||
section?: string
|
section?: string
|
||||||
) => (PickerComboBoxItem | string)[];
|
) => (PickerComboBoxItem | string)[];
|
||||||
@@ -64,6 +67,9 @@ export class HaGenericPicker extends LitElement {
|
|||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public searchFn?: PickerComboBoxSearchFn<PickerComboBoxItem>;
|
public searchFn?: PickerComboBoxSearchFn<PickerComboBoxItem>;
|
||||||
|
|
||||||
|
@property({ attribute: false })
|
||||||
|
public searchKeys?: FuseWeightedKey[];
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public notFoundLabel?: string | ((search: string) => string);
|
public notFoundLabel?: string | ((search: string) => string);
|
||||||
|
|
||||||
@@ -107,6 +113,8 @@ export class HaGenericPicker extends LitElement {
|
|||||||
|
|
||||||
@property({ attribute: "selected-section" }) public selectedSection?: string;
|
@property({ attribute: "selected-section" }) public selectedSection?: string;
|
||||||
|
|
||||||
|
@property({ attribute: "unknown-item-text" }) public unknownItemText?: string;
|
||||||
|
|
||||||
@query(".container") private _containerElement?: HTMLDivElement;
|
@query(".container") private _containerElement?: HTMLDivElement;
|
||||||
|
|
||||||
@query("ha-picker-combo-box") private _comboBox?: HaPickerComboBox;
|
@query("ha-picker-combo-box") private _comboBox?: HaPickerComboBox;
|
||||||
@@ -156,6 +164,8 @@ export class HaGenericPicker extends LitElement {
|
|||||||
type="button"
|
type="button"
|
||||||
class=${this._opened ? "opened" : ""}
|
class=${this._opened ? "opened" : ""}
|
||||||
compact
|
compact
|
||||||
|
.unknown=${this._unknownValue(this.value, this.getItems())}
|
||||||
|
.unknownItemText=${this.unknownItemText}
|
||||||
aria-label=${ifDefined(this.label)}
|
aria-label=${ifDefined(this.label)}
|
||||||
@click=${this.open}
|
@click=${this.open}
|
||||||
@clear=${this._clear}
|
@clear=${this._clear}
|
||||||
@@ -229,10 +239,23 @@ export class HaGenericPicker extends LitElement {
|
|||||||
.sections=${this.sections}
|
.sections=${this.sections}
|
||||||
.sectionTitleFunction=${this.sectionTitleFunction}
|
.sectionTitleFunction=${this.sectionTitleFunction}
|
||||||
.selectedSection=${this.selectedSection}
|
.selectedSection=${this.selectedSection}
|
||||||
|
.searchKeys=${this.searchKeys}
|
||||||
></ha-picker-combo-box>
|
></ha-picker-combo-box>
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private _unknownValue = memoizeOne(
|
||||||
|
(value?: string, items?: (PickerComboBoxItem | string)[]) => {
|
||||||
|
if (value === undefined || value === null || value === "" || !items) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return !items.some(
|
||||||
|
(item) => typeof item !== "string" && item.id === value
|
||||||
|
);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
private _renderHelper() {
|
private _renderHelper() {
|
||||||
return this.helper
|
return this.helper
|
||||||
? html`<ha-input-helper-text .disabled=${this.disabled}
|
? html`<ha-input-helper-text .disabled=${this.disabled}
|
||||||
@@ -344,7 +367,10 @@ export class HaGenericPicker extends LitElement {
|
|||||||
|
|
||||||
wa-popover::part(body) {
|
wa-popover::part(body) {
|
||||||
width: max(var(--body-width), 250px);
|
width: max(var(--body-width), 250px);
|
||||||
max-width: max(var(--body-width), 250px);
|
max-width: var(
|
||||||
|
--ha-generic-picker-max-width,
|
||||||
|
max(var(--body-width), 250px)
|
||||||
|
);
|
||||||
max-height: 500px;
|
max-height: 500px;
|
||||||
height: 70vh;
|
height: 70vh;
|
||||||
overflow: hidden;
|
overflow: hidden;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { TemplateResult } from "lit";
|
import type { TemplateResult } from "lit";
|
||||||
import { css, html, LitElement } from "lit";
|
import { css, html, LitElement } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import { isUnavailableState, OFF } from "../data/entity";
|
import { isUnavailableState, OFF } from "../data/entity/entity";
|
||||||
import type { HumidifierEntity } from "../data/humidifier";
|
import type { HumidifierEntity } from "../data/humidifier";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
|
|
||||||
|
|||||||
@@ -11,12 +11,12 @@ import {
|
|||||||
} from "lit/decorators";
|
} 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 type { LabelRegistryEntry } from "../data/label_registry";
|
import { getLabels, labelComboBoxKeys } from "../data/label/label_picker";
|
||||||
import {
|
import {
|
||||||
createLabelRegistryEntry,
|
createLabelRegistryEntry,
|
||||||
getLabels,
|
|
||||||
subscribeLabelRegistry,
|
subscribeLabelRegistry,
|
||||||
} from "../data/label_registry";
|
type LabelRegistryEntry,
|
||||||
|
} from "../data/label/label_registry";
|
||||||
import { showAlertDialog } from "../dialogs/generic/show-dialog-box";
|
import { showAlertDialog } from "../dialogs/generic/show-dialog-box";
|
||||||
import { SubscribeMixin } from "../mixins/subscribe-mixin";
|
import { SubscribeMixin } from "../mixins/subscribe-mixin";
|
||||||
import { showLabelDetailDialog } from "../panels/config/labels/show-dialog-label-detail";
|
import { showLabelDetailDialog } from "../panels/config/labels/show-dialog-label-detail";
|
||||||
@@ -237,6 +237,7 @@ export class HaLabelPicker extends SubscribeMixin(LitElement) {
|
|||||||
.getItems=${this._getItems}
|
.getItems=${this._getItems}
|
||||||
.getAdditionalItems=${this._getAdditionalItems}
|
.getAdditionalItems=${this._getAdditionalItems}
|
||||||
.valueRenderer=${valueRenderer}
|
.valueRenderer=${valueRenderer}
|
||||||
|
.searchKeys=${labelComboBoxKeys}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
>
|
>
|
||||||
<slot .slot=${this._slotNodes?.length ? "field" : undefined}></slot>
|
<slot .slot=${this._slotNodes?.length ? "field" : undefined}></slot>
|
||||||
|
|||||||
@@ -8,11 +8,11 @@ import memoizeOne from "memoize-one";
|
|||||||
import { computeCssColor } from "../common/color/compute-color";
|
import { computeCssColor } from "../common/color/compute-color";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { stringCompare } from "../common/string/compare";
|
import { stringCompare } from "../common/string/compare";
|
||||||
import type { LabelRegistryEntry } from "../data/label_registry";
|
import type { LabelRegistryEntry } from "../data/label/label_registry";
|
||||||
import {
|
import {
|
||||||
subscribeLabelRegistry,
|
subscribeLabelRegistry,
|
||||||
updateLabelRegistryEntry,
|
updateLabelRegistryEntry,
|
||||||
} from "../data/label_registry";
|
} from "../data/label/label_registry";
|
||||||
import { SubscribeMixin } from "../mixins/subscribe-mixin";
|
import { SubscribeMixin } from "../mixins/subscribe-mixin";
|
||||||
import { showLabelDetailDialog } from "../panels/config/labels/show-dialog-label-detail";
|
import { showLabelDetailDialog } from "../panels/config/labels/show-dialog-label-detail";
|
||||||
import type { HomeAssistant, ValueChangedEvent } from "../types";
|
import type { HomeAssistant, ValueChangedEvent } from "../types";
|
||||||
|
|||||||
@@ -40,14 +40,12 @@ export const getLanguageOptions = (
|
|||||||
return {
|
return {
|
||||||
id: lang,
|
id: lang,
|
||||||
primary,
|
primary,
|
||||||
search_labels: [primary],
|
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
} else if (locale) {
|
} else if (locale) {
|
||||||
options = languages.map((lang) => ({
|
options = languages.map((lang) => ({
|
||||||
id: lang,
|
id: lang,
|
||||||
primary: formatLanguageCode(lang, locale),
|
primary: formatLanguageCode(lang, locale),
|
||||||
search_labels: [formatLanguageCode(lang, locale)],
|
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -74,9 +74,6 @@ export class HaMarkdown extends LitElement {
|
|||||||
background-color: var(--markdown-image-background-color);
|
background-color: var(--markdown-image-background-color);
|
||||||
border-radius: var(--markdown-image-border-radius);
|
border-radius: var(--markdown-image-border-radius);
|
||||||
max-width: 100%;
|
max-width: 100%;
|
||||||
height: auto;
|
|
||||||
width: auto;
|
|
||||||
transition: height 0.2s ease-in-out;
|
|
||||||
}
|
}
|
||||||
p:first-child > img:first-child {
|
p:first-child > img:first-child {
|
||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
@@ -84,8 +81,7 @@ export class HaMarkdown extends LitElement {
|
|||||||
p:first-child > img:last-child {
|
p:first-child > img:last-child {
|
||||||
vertical-align: top;
|
vertical-align: top;
|
||||||
}
|
}
|
||||||
:host > ul,
|
ha-markdown-element > :is(ol, ul) {
|
||||||
:host > ol {
|
|
||||||
padding-inline-start: var(--markdown-list-indent, revert);
|
padding-inline-start: var(--markdown-list-indent, revert);
|
||||||
}
|
}
|
||||||
li {
|
li {
|
||||||
@@ -136,6 +132,18 @@ export class HaMarkdown extends LitElement {
|
|||||||
border-bottom: none;
|
border-bottom: none;
|
||||||
margin: var(--ha-space-4) 0;
|
margin: var(--ha-space-4) 0;
|
||||||
}
|
}
|
||||||
|
table[role="presentation"] {
|
||||||
|
--markdown-table-border-collapse: separate;
|
||||||
|
--markdown-table-border-width: attr(border, 0);
|
||||||
|
--markdown-table-padding-inline: 0;
|
||||||
|
--markdown-table-padding-block: 0;
|
||||||
|
th {
|
||||||
|
vertical-align: attr(align, center);
|
||||||
|
}
|
||||||
|
td {
|
||||||
|
vertical-align: attr(align, left);
|
||||||
|
}
|
||||||
|
}
|
||||||
table {
|
table {
|
||||||
border-collapse: var(--markdown-table-border-collapse, collapse);
|
border-collapse: var(--markdown-table-border-collapse, collapse);
|
||||||
}
|
}
|
||||||
@@ -143,14 +151,15 @@ export class HaMarkdown extends LitElement {
|
|||||||
overflow: auto;
|
overflow: auto;
|
||||||
}
|
}
|
||||||
th {
|
th {
|
||||||
text-align: start;
|
text-align: var(--markdown-table-text-align, start);
|
||||||
}
|
}
|
||||||
td,
|
td,
|
||||||
th {
|
th {
|
||||||
border-width: var(--markdown-table-border-width, 1px);
|
border-width: var(--markdown-table-border-width, 1px);
|
||||||
border-style: var(--markdown-table-border-style, solid);
|
border-style: var(--markdown-table-border-style, solid);
|
||||||
border-color: var(--markdown-table-border-color, var(--divider-color));
|
border-color: var(--markdown-table-border-color, var(--divider-color));
|
||||||
padding: 0.25em 0.5em;
|
padding-inline: var(--markdown-table-padding-inline, 0.5em);
|
||||||
|
padding-block: var(--markdown-table-padding-block, 0.25em);
|
||||||
}
|
}
|
||||||
blockquote {
|
blockquote {
|
||||||
border-left: 4px solid var(--divider-color);
|
border-left: 4px solid var(--divider-color);
|
||||||
|
|||||||
@@ -15,7 +15,10 @@ import { tinykeys } from "tinykeys";
|
|||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { caseInsensitiveStringCompare } from "../common/string/compare";
|
import { caseInsensitiveStringCompare } from "../common/string/compare";
|
||||||
import { ScrollableFadeMixin } from "../mixins/scrollable-fade-mixin";
|
import { ScrollableFadeMixin } from "../mixins/scrollable-fade-mixin";
|
||||||
import { HaFuse } from "../resources/fuse";
|
import {
|
||||||
|
multiTermSortedSearch,
|
||||||
|
type FuseWeightedKey,
|
||||||
|
} from "../resources/fuseMultiTerm";
|
||||||
import { haStyleScrollbar } from "../resources/styles";
|
import { haStyleScrollbar } from "../resources/styles";
|
||||||
import { loadVirtualizer } from "../resources/virtualizer";
|
import { loadVirtualizer } from "../resources/virtualizer";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
@@ -26,11 +29,26 @@ import "./ha-icon";
|
|||||||
import "./ha-textfield";
|
import "./ha-textfield";
|
||||||
import type { HaTextField } from "./ha-textfield";
|
import type { HaTextField } from "./ha-textfield";
|
||||||
|
|
||||||
|
export const DEFAULT_SEARCH_KEYS: FuseWeightedKey[] = [
|
||||||
|
{
|
||||||
|
name: "primary",
|
||||||
|
weight: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "secondary",
|
||||||
|
weight: 7,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "id",
|
||||||
|
weight: 3,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
export interface PickerComboBoxItem {
|
export interface PickerComboBoxItem {
|
||||||
id: string;
|
id: string;
|
||||||
primary: string;
|
primary: string;
|
||||||
secondary?: string;
|
secondary?: string;
|
||||||
search_labels?: string[];
|
search_labels?: Record<string, string | null>;
|
||||||
sorting_label?: string;
|
sorting_label?: string;
|
||||||
icon_path?: string;
|
icon_path?: string;
|
||||||
icon?: string;
|
icon?: string;
|
||||||
@@ -77,10 +95,13 @@ export class HaPickerComboBox extends ScrollableFadeMixin(LitElement) {
|
|||||||
|
|
||||||
@property() public value?: string;
|
@property() public value?: string;
|
||||||
|
|
||||||
|
@property({ attribute: false })
|
||||||
|
public searchKeys?: FuseWeightedKey[];
|
||||||
|
|
||||||
@state() private _listScrolled = false;
|
@state() private _listScrolled = false;
|
||||||
|
|
||||||
@property({ attribute: false })
|
@property({ attribute: false })
|
||||||
public getItems?: (
|
public getItems!: (
|
||||||
searchString?: string,
|
searchString?: string,
|
||||||
section?: string
|
section?: string
|
||||||
) => (PickerComboBoxItem | string)[];
|
) => (PickerComboBoxItem | string)[];
|
||||||
@@ -133,6 +154,8 @@ export class HaPickerComboBox extends ScrollableFadeMixin(LitElement) {
|
|||||||
|
|
||||||
@state() private _sectionTitle?: string;
|
@state() private _sectionTitle?: string;
|
||||||
|
|
||||||
|
@state() private _valuePinned = true;
|
||||||
|
|
||||||
private _allItems: (PickerComboBoxItem | string)[] = [];
|
private _allItems: (PickerComboBoxItem | string)[] = [];
|
||||||
|
|
||||||
private _selectedItemIndex = -1;
|
private _selectedItemIndex = -1;
|
||||||
@@ -194,6 +217,15 @@ export class HaPickerComboBox extends ScrollableFadeMixin(LitElement) {
|
|||||||
.renderItem=${this._renderItem}
|
.renderItem=${this._renderItem}
|
||||||
style="min-height: 36px;"
|
style="min-height: 36px;"
|
||||||
class=${this._listScrolled ? "scrolled" : ""}
|
class=${this._listScrolled ? "scrolled" : ""}
|
||||||
|
.layout=${this.value && this._valuePinned
|
||||||
|
? {
|
||||||
|
pin: {
|
||||||
|
index: this._getInitialSelectedIndex(),
|
||||||
|
block: "center",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
: undefined}
|
||||||
|
@unpinned=${this._handleUnpinned}
|
||||||
@scroll=${this._onScrollList}
|
@scroll=${this._onScrollList}
|
||||||
@focus=${this._focusList}
|
@focus=${this._focusList}
|
||||||
@visibilityChanged=${this._visibilityChanged}
|
@visibilityChanged=${this._visibilityChanged}
|
||||||
@@ -244,24 +276,42 @@ export class HaPickerComboBox extends ScrollableFadeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@eventOptions({ passive: true })
|
||||||
|
private _handleUnpinned() {
|
||||||
|
this._valuePinned = false;
|
||||||
|
}
|
||||||
|
|
||||||
private _getAdditionalItems = (searchString?: string) =>
|
private _getAdditionalItems = (searchString?: string) =>
|
||||||
this.getAdditionalItems?.(searchString) || [];
|
this.getAdditionalItems?.(searchString) || [];
|
||||||
|
|
||||||
private _getItems = () => {
|
private _getItems = () => {
|
||||||
let items = [
|
let items = [...this.getItems(this._search, this.selectedSection)];
|
||||||
...(this.getItems
|
|
||||||
? this.getItems(this._search, this.selectedSection)
|
|
||||||
: []),
|
|
||||||
];
|
|
||||||
|
|
||||||
if (!this.sections?.length) {
|
if (!this.sections?.length) {
|
||||||
items = items.sort((entityA, entityB) =>
|
items = items.sort((entityA, entityB) => {
|
||||||
caseInsensitiveStringCompare(
|
const sortLabelA =
|
||||||
(entityA as PickerComboBoxItem).sorting_label!,
|
typeof entityA === "string" ? entityA : entityA.sorting_label;
|
||||||
(entityB as PickerComboBoxItem).sorting_label!,
|
const sortLabelB =
|
||||||
|
typeof entityB === "string" ? entityB : entityB.sorting_label;
|
||||||
|
|
||||||
|
if (!sortLabelA || !sortLabelB) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sortLabelB) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!sortLabelA) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return caseInsensitiveStringCompare(
|
||||||
|
sortLabelA,
|
||||||
|
sortLabelB,
|
||||||
this.hass?.locale.language ?? navigator.language
|
this.hass?.locale.language ?? navigator.language
|
||||||
)
|
);
|
||||||
);
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!items.length) {
|
if (!items.length) {
|
||||||
@@ -279,6 +329,9 @@ export class HaPickerComboBox extends ScrollableFadeMixin(LitElement) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
private _renderItem = (item: PickerComboBoxItem | string, index: number) => {
|
private _renderItem = (item: PickerComboBoxItem | string, index: number) => {
|
||||||
|
if (!item) {
|
||||||
|
return nothing;
|
||||||
|
}
|
||||||
if (item === "padding") {
|
if (item === "padding") {
|
||||||
return html`<div class="bottom-padding"></div>`;
|
return html`<div class="bottom-padding"></div>`;
|
||||||
}
|
}
|
||||||
@@ -339,8 +392,9 @@ export class HaPickerComboBox extends ScrollableFadeMixin(LitElement) {
|
|||||||
fireEvent(this, "value-changed", { value: newValue });
|
fireEvent(this, "value-changed", { value: newValue });
|
||||||
};
|
};
|
||||||
|
|
||||||
private _fuseIndex = memoizeOne((states: PickerComboBoxItem[]) =>
|
private _fuseIndex = memoizeOne(
|
||||||
Fuse.createIndex(["search_labels"], states)
|
(states: PickerComboBoxItem[], searchKeys?: FuseWeightedKey[]) =>
|
||||||
|
Fuse.createIndex(searchKeys || DEFAULT_SEARCH_KEYS, states)
|
||||||
);
|
);
|
||||||
|
|
||||||
private _filterChanged = (ev: Event) => {
|
private _filterChanged = (ev: Event) => {
|
||||||
@@ -356,34 +410,26 @@ export class HaPickerComboBox extends ScrollableFadeMixin(LitElement) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const index = this._fuseIndex(this._allItems as PickerComboBoxItem[]);
|
const index = this._fuseIndex(
|
||||||
const fuse = new HaFuse(
|
|
||||||
this._allItems as PickerComboBoxItem[],
|
this._allItems as PickerComboBoxItem[],
|
||||||
{
|
this.searchKeys
|
||||||
shouldSort: false,
|
|
||||||
minMatchCharLength: Math.min(searchString.length, 2),
|
|
||||||
},
|
|
||||||
index
|
|
||||||
);
|
);
|
||||||
|
|
||||||
const results = fuse.multiTermsSearch(searchString);
|
let filteredItems = multiTermSortedSearch<PickerComboBoxItem>(
|
||||||
let filteredItems = [...this._allItems];
|
this._allItems as PickerComboBoxItem[],
|
||||||
|
searchString,
|
||||||
|
this.searchKeys || DEFAULT_SEARCH_KEYS,
|
||||||
|
(item) => item.id,
|
||||||
|
index
|
||||||
|
) as (PickerComboBoxItem | string)[];
|
||||||
|
|
||||||
if (results) {
|
if (!filteredItems.length) {
|
||||||
const items: (PickerComboBoxItem | string)[] = results.map(
|
filteredItems.push(NO_ITEMS_AVAILABLE_ID);
|
||||||
(result) => result.item
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!items.length) {
|
|
||||||
filteredItems.push(NO_ITEMS_AVAILABLE_ID);
|
|
||||||
}
|
|
||||||
|
|
||||||
const additionalItems = this._getAdditionalItems();
|
|
||||||
items.push(...additionalItems);
|
|
||||||
|
|
||||||
filteredItems = items;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const additionalItems = this._getAdditionalItems();
|
||||||
|
filteredItems.push(...additionalItems);
|
||||||
|
|
||||||
if (this.searchFn) {
|
if (this.searchFn) {
|
||||||
filteredItems = this.searchFn(
|
filteredItems = this.searchFn(
|
||||||
searchString,
|
searchString,
|
||||||
@@ -590,7 +636,25 @@ export class HaPickerComboBox extends ScrollableFadeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private _keyFunction = (item: PickerComboBoxItem | string) =>
|
private _keyFunction = (item: PickerComboBoxItem | string) =>
|
||||||
typeof item === "string" ? item : item.id;
|
typeof item === "string" ? item : item?.id;
|
||||||
|
|
||||||
|
private _getInitialSelectedIndex() {
|
||||||
|
if (!this._virtualizerElement || !this.value) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
const index = this._virtualizerElement.items.findIndex(
|
||||||
|
(item) =>
|
||||||
|
typeof item !== "string" &&
|
||||||
|
(item as PickerComboBoxItem).id === this.value
|
||||||
|
);
|
||||||
|
|
||||||
|
if (index === -1) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
return index;
|
||||||
|
}
|
||||||
|
|
||||||
static get styles() {
|
static get styles() {
|
||||||
return [
|
return [
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { consume } from "@lit/context";
|
||||||
import { mdiClose, mdiMenuDown } from "@mdi/js";
|
import { mdiClose, mdiMenuDown } from "@mdi/js";
|
||||||
import {
|
import {
|
||||||
css,
|
css,
|
||||||
@@ -7,8 +8,10 @@ import {
|
|||||||
type CSSResultGroup,
|
type CSSResultGroup,
|
||||||
type TemplateResult,
|
type TemplateResult,
|
||||||
} from "lit";
|
} from "lit";
|
||||||
import { customElement, property, query } from "lit/decorators";
|
import { customElement, property, query, state } from "lit/decorators";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
|
import { localizeContext } from "../data/context";
|
||||||
|
import type { HomeAssistant } from "../types";
|
||||||
import "./ha-combo-box-item";
|
import "./ha-combo-box-item";
|
||||||
import type { HaComboBoxItem } from "./ha-combo-box-item";
|
import type { HaComboBoxItem } from "./ha-combo-box-item";
|
||||||
import "./ha-icon-button";
|
import "./ha-icon-button";
|
||||||
@@ -33,6 +36,10 @@ export class HaPickerField extends LitElement {
|
|||||||
|
|
||||||
@property() public placeholder?: string;
|
@property() public placeholder?: string;
|
||||||
|
|
||||||
|
@property({ type: Boolean, reflect: true }) public unknown = false;
|
||||||
|
|
||||||
|
@property({ attribute: "unknown-item-text" }) public unknownItemText?: string;
|
||||||
|
|
||||||
@property({ attribute: "hide-clear-icon", type: Boolean })
|
@property({ attribute: "hide-clear-icon", type: Boolean })
|
||||||
public hideClearIcon = false;
|
public hideClearIcon = false;
|
||||||
|
|
||||||
@@ -41,6 +48,10 @@ export class HaPickerField extends LitElement {
|
|||||||
|
|
||||||
@query("ha-combo-box-item", true) public item!: HaComboBoxItem;
|
@query("ha-combo-box-item", true) public item!: HaComboBoxItem;
|
||||||
|
|
||||||
|
@state()
|
||||||
|
@consume({ context: localizeContext, subscribe: true })
|
||||||
|
private localize!: HomeAssistant["localize"];
|
||||||
|
|
||||||
public async focus() {
|
public async focus() {
|
||||||
await this.updateComplete;
|
await this.updateComplete;
|
||||||
await this.item?.focus();
|
await this.item?.focus();
|
||||||
@@ -61,6 +72,12 @@ export class HaPickerField extends LitElement {
|
|||||||
${this.placeholder}
|
${this.placeholder}
|
||||||
</span>
|
</span>
|
||||||
`}
|
`}
|
||||||
|
${this.unknown
|
||||||
|
? html`<div slot="supporting-text" class="unknown">
|
||||||
|
${this.unknownItemText ||
|
||||||
|
this.localize("ui.components.combo-box.unknown_item")}
|
||||||
|
</div>`
|
||||||
|
: nothing}
|
||||||
${showClearIcon
|
${showClearIcon
|
||||||
? html`
|
? html`
|
||||||
<ha-icon-button
|
<ha-icon-button
|
||||||
@@ -142,6 +159,10 @@ export class HaPickerField extends LitElement {
|
|||||||
background-color: var(--mdc-theme-primary);
|
background-color: var(--mdc-theme-primary);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
:host([unknown]) ha-combo-box-item {
|
||||||
|
background-color: var(--ha-color-fill-warning-quiet-resting);
|
||||||
|
}
|
||||||
|
|
||||||
.clear {
|
.clear {
|
||||||
margin: 0 -8px;
|
margin: 0 -8px;
|
||||||
--mdc-icon-button-size: 32px;
|
--mdc-icon-button-size: 32px;
|
||||||
@@ -156,6 +177,10 @@ export class HaPickerField extends LitElement {
|
|||||||
color: var(--secondary-text-color);
|
color: var(--secondary-text-color);
|
||||||
padding: 0 8px;
|
padding: 0 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.unknown {
|
||||||
|
color: var(--ha-color-on-warning-normal);
|
||||||
|
}
|
||||||
`,
|
`,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { fullEntitiesContext } from "../../data/context";
|
|||||||
import {
|
import {
|
||||||
subscribeEntityRegistry,
|
subscribeEntityRegistry,
|
||||||
type EntityRegistryEntry,
|
type EntityRegistryEntry,
|
||||||
} from "../../data/entity_registry";
|
} from "../../data/entity/entity_registry";
|
||||||
import type { Action } from "../../data/script";
|
import type { Action } from "../../data/script";
|
||||||
import { migrateAutomationAction } from "../../data/script";
|
import { migrateAutomationAction } from "../../data/script";
|
||||||
import type { ActionSelector } from "../../data/selector";
|
import type { ActionSelector } from "../../data/selector";
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ import { html, LitElement, nothing } from "lit";
|
|||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { ensureArray } from "../../common/array/ensure-array";
|
import { ensureArray } from "../../common/array/ensure-array";
|
||||||
import type { DeviceRegistryEntry } from "../../data/device_registry";
|
|
||||||
import { getDeviceIntegrationLookup } from "../../data/device_registry";
|
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
import type { EntitySources } from "../../data/entity_sources";
|
|
||||||
import { fetchEntitySourcesWithCache } from "../../data/entity_sources";
|
|
||||||
import type { AreaSelector } from "../../data/selector";
|
|
||||||
import type { ConfigEntry } from "../../data/config_entries";
|
import type { ConfigEntry } from "../../data/config_entries";
|
||||||
import { getConfigEntries } from "../../data/config_entries";
|
import { getConfigEntries } from "../../data/config_entries";
|
||||||
|
import type { DeviceRegistryEntry } from "../../data/device/device_registry";
|
||||||
|
import { getDeviceIntegrationLookup } from "../../data/device/device_registry";
|
||||||
|
import type { EntitySources } from "../../data/entity/entity_sources";
|
||||||
|
import { fetchEntitySourcesWithCache } from "../../data/entity/entity_sources";
|
||||||
|
import type { AreaSelector } from "../../data/selector";
|
||||||
import {
|
import {
|
||||||
filterSelectorDevices,
|
filterSelectorDevices,
|
||||||
filterSelectorEntities,
|
filterSelectorEntities,
|
||||||
|
|||||||
@@ -5,13 +5,13 @@ import { customElement, property, state } from "lit/decorators";
|
|||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { ensureArray } from "../../common/array/ensure-array";
|
import { ensureArray } from "../../common/array/ensure-array";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
import type { DeviceRegistryEntry } from "../../data/device_registry";
|
|
||||||
import { getDeviceIntegrationLookup } from "../../data/device_registry";
|
|
||||||
import type { EntitySources } from "../../data/entity_sources";
|
|
||||||
import { fetchEntitySourcesWithCache } from "../../data/entity_sources";
|
|
||||||
import type { DeviceSelector } from "../../data/selector";
|
|
||||||
import type { ConfigEntry } from "../../data/config_entries";
|
import type { ConfigEntry } from "../../data/config_entries";
|
||||||
import { getConfigEntries } from "../../data/config_entries";
|
import { getConfigEntries } from "../../data/config_entries";
|
||||||
|
import type { DeviceRegistryEntry } from "../../data/device/device_registry";
|
||||||
|
import { getDeviceIntegrationLookup } from "../../data/device/device_registry";
|
||||||
|
import type { EntitySources } from "../../data/entity/entity_sources";
|
||||||
|
import { fetchEntitySourcesWithCache } from "../../data/entity/entity_sources";
|
||||||
|
import type { DeviceSelector } from "../../data/selector";
|
||||||
import {
|
import {
|
||||||
filterSelectorDevices,
|
filterSelectorDevices,
|
||||||
filterSelectorEntities,
|
filterSelectorEntities,
|
||||||
|
|||||||
@@ -4,12 +4,12 @@ import { html, LitElement, nothing } from "lit";
|
|||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { ensureArray } from "../../common/array/ensure-array";
|
import { ensureArray } from "../../common/array/ensure-array";
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
import type { EntitySources } from "../../data/entity_sources";
|
import type { EntitySources } from "../../data/entity/entity_sources";
|
||||||
import { fetchEntitySourcesWithCache } from "../../data/entity_sources";
|
import { fetchEntitySourcesWithCache } from "../../data/entity/entity_sources";
|
||||||
import type { EntitySelector } from "../../data/selector";
|
import type { EntitySelector } from "../../data/selector";
|
||||||
import {
|
import {
|
||||||
filterSelectorEntities,
|
|
||||||
computeCreateDomains,
|
computeCreateDomains,
|
||||||
|
filterSelectorEntities,
|
||||||
} from "../../data/selector";
|
} from "../../data/selector";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import "../entity/ha-entities-picker";
|
import "../entity/ha-entities-picker";
|
||||||
|
|||||||
@@ -4,14 +4,14 @@ import { html, LitElement, nothing } from "lit";
|
|||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { ensureArray } from "../../common/array/ensure-array";
|
import { ensureArray } from "../../common/array/ensure-array";
|
||||||
import type { DeviceRegistryEntry } from "../../data/device_registry";
|
|
||||||
import { getDeviceIntegrationLookup } from "../../data/device_registry";
|
|
||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
import type { EntitySources } from "../../data/entity_sources";
|
|
||||||
import { fetchEntitySourcesWithCache } from "../../data/entity_sources";
|
|
||||||
import type { FloorSelector } from "../../data/selector";
|
|
||||||
import type { ConfigEntry } from "../../data/config_entries";
|
import type { ConfigEntry } from "../../data/config_entries";
|
||||||
import { getConfigEntries } from "../../data/config_entries";
|
import { getConfigEntries } from "../../data/config_entries";
|
||||||
|
import type { DeviceRegistryEntry } from "../../data/device/device_registry";
|
||||||
|
import { getDeviceIntegrationLookup } from "../../data/device/device_registry";
|
||||||
|
import type { EntitySources } from "../../data/entity/entity_sources";
|
||||||
|
import { fetchEntitySourcesWithCache } from "../../data/entity/entity_sources";
|
||||||
|
import type { FloorSelector } from "../../data/selector";
|
||||||
import {
|
import {
|
||||||
filterSelectorDevices,
|
filterSelectorDevices,
|
||||||
filterSelectorEntities,
|
filterSelectorEntities,
|
||||||
|
|||||||
@@ -7,15 +7,15 @@ import { css, html, LitElement, nothing } from "lit";
|
|||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { ensureArray } from "../../common/array/ensure-array";
|
import { ensureArray } from "../../common/array/ensure-array";
|
||||||
import type { DeviceRegistryEntry } from "../../data/device_registry";
|
import type { DeviceRegistryEntry } from "../../data/device/device_registry";
|
||||||
import { getDeviceIntegrationLookup } from "../../data/device_registry";
|
import { getDeviceIntegrationLookup } from "../../data/device/device_registry";
|
||||||
import type { EntitySources } from "../../data/entity_sources";
|
import type { EntitySources } from "../../data/entity/entity_sources";
|
||||||
import { fetchEntitySourcesWithCache } from "../../data/entity_sources";
|
import { fetchEntitySourcesWithCache } from "../../data/entity/entity_sources";
|
||||||
import type { TargetSelector } from "../../data/selector";
|
import type { TargetSelector } from "../../data/selector";
|
||||||
import {
|
import {
|
||||||
|
computeCreateDomains,
|
||||||
filterSelectorDevices,
|
filterSelectorDevices,
|
||||||
filterSelectorEntities,
|
filterSelectorEntities,
|
||||||
computeCreateDomains,
|
|
||||||
} from "../../data/selector";
|
} from "../../data/selector";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import "../ha-target-picker";
|
import "../ha-target-picker";
|
||||||
|
|||||||
@@ -21,6 +21,13 @@ interface ServiceComboBoxItem extends PickerComboBoxItem {
|
|||||||
service_id?: string;
|
service_id?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SEARCH_KEYS = [
|
||||||
|
{ name: "search_labels.name", weight: 10 },
|
||||||
|
{ name: "search_labels.description", weight: 8 },
|
||||||
|
{ name: "search_labels.domainName", weight: 6 },
|
||||||
|
{ name: "search_labels.serviceId", weight: 3 },
|
||||||
|
];
|
||||||
|
|
||||||
@customElement("ha-service-picker")
|
@customElement("ha-service-picker")
|
||||||
class HaServicePicker extends LitElement {
|
class HaServicePicker extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
@@ -141,6 +148,10 @@ class HaServicePicker extends LitElement {
|
|||||||
this.hass.localize,
|
this.hass.localize,
|
||||||
this.hass.services
|
this.hass.services
|
||||||
)}
|
)}
|
||||||
|
.searchKeys=${SEARCH_KEYS}
|
||||||
|
.unknownItemText=${this.hass.localize(
|
||||||
|
"ui.components.service-picker.unknown"
|
||||||
|
)}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
>
|
>
|
||||||
</ha-generic-picker>
|
</ha-generic-picker>
|
||||||
@@ -194,9 +205,7 @@ class HaServicePicker extends LitElement {
|
|||||||
secondary: description,
|
secondary: description,
|
||||||
domain_name: domainName,
|
domain_name: domainName,
|
||||||
service_id: serviceId,
|
service_id: serviceId,
|
||||||
search_labels: [serviceId, domainName, name, description].filter(
|
search_labels: { serviceId, domainName, name, description },
|
||||||
Boolean
|
|
||||||
),
|
|
||||||
sorting_label: serviceId,
|
sorting_label: serviceId,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,19 +13,30 @@ import memoizeOne from "memoize-one";
|
|||||||
import { ensureArray } from "../common/array/ensure-array";
|
import { ensureArray } from "../common/array/ensure-array";
|
||||||
import { fireEvent } from "../common/dom/fire_event";
|
import { fireEvent } from "../common/dom/fire_event";
|
||||||
import { isValidEntityId } from "../common/entity/valid_entity_id";
|
import { isValidEntityId } from "../common/entity/valid_entity_id";
|
||||||
|
import { caseInsensitiveStringCompare } from "../common/string/compare";
|
||||||
import { computeRTL } from "../common/util/compute_rtl";
|
import { computeRTL } from "../common/util/compute_rtl";
|
||||||
import {
|
import {
|
||||||
|
areaFloorComboBoxKeys,
|
||||||
getAreasAndFloors,
|
getAreasAndFloors,
|
||||||
type AreaFloorValue,
|
type AreaFloorValue,
|
||||||
type FloorComboBoxItem,
|
type FloorComboBoxItem,
|
||||||
} from "../data/area_floor";
|
} from "../data/area_floor_picker";
|
||||||
import { getConfigEntries, type ConfigEntry } from "../data/config_entries";
|
import { getConfigEntries, type ConfigEntry } from "../data/config_entries";
|
||||||
import { labelsContext } from "../data/context";
|
import { labelsContext } from "../data/context";
|
||||||
import { getDevices, type DevicePickerItem } from "../data/device_registry";
|
import {
|
||||||
import type { HaEntityPickerEntityFilterFunc } from "../data/entity";
|
deviceComboBoxKeys,
|
||||||
import { getEntities, type EntityComboBoxItem } from "../data/entity_registry";
|
getDevices,
|
||||||
|
type DevicePickerItem,
|
||||||
|
} from "../data/device/device_picker";
|
||||||
|
import type { HaEntityPickerEntityFilterFunc } from "../data/entity/entity";
|
||||||
|
import {
|
||||||
|
entityComboBoxKeys,
|
||||||
|
getEntities,
|
||||||
|
type EntityComboBoxItem,
|
||||||
|
} from "../data/entity/entity_picker";
|
||||||
import { domainToName } from "../data/integration";
|
import { domainToName } from "../data/integration";
|
||||||
import { getLabels, type LabelRegistryEntry } from "../data/label_registry";
|
import { getLabels, labelComboBoxKeys } from "../data/label/label_picker";
|
||||||
|
import type { LabelRegistryEntry } from "../data/label/label_registry";
|
||||||
import {
|
import {
|
||||||
areaMeetsFilter,
|
areaMeetsFilter,
|
||||||
deviceMeetsFilter,
|
deviceMeetsFilter,
|
||||||
@@ -37,7 +48,11 @@ import {
|
|||||||
import { SubscribeMixin } from "../mixins/subscribe-mixin";
|
import { SubscribeMixin } from "../mixins/subscribe-mixin";
|
||||||
import { isHelperDomain } from "../panels/config/helpers/const";
|
import { isHelperDomain } from "../panels/config/helpers/const";
|
||||||
import { showHelperDetailDialog } from "../panels/config/helpers/show-dialog-helper-detail";
|
import { showHelperDetailDialog } from "../panels/config/helpers/show-dialog-helper-detail";
|
||||||
import { HaFuse } from "../resources/fuse";
|
import {
|
||||||
|
multiTermSearch,
|
||||||
|
multiTermSortedSearch,
|
||||||
|
type FuseWeightedKey,
|
||||||
|
} from "../resources/fuseMultiTerm";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
import { brandsUrl } from "../util/brands-url";
|
import { brandsUrl } from "../util/brands-url";
|
||||||
import type { HaDevicePickerDeviceFilterFunc } from "./device/ha-device-picker";
|
import type { HaDevicePickerDeviceFilterFunc } from "./device/ha-device-picker";
|
||||||
@@ -113,16 +128,16 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
|
|
||||||
private _fuseIndexes = {
|
private _fuseIndexes = {
|
||||||
area: memoizeOne((states: FloorComboBoxItem[]) =>
|
area: memoizeOne((states: FloorComboBoxItem[]) =>
|
||||||
this._createFuseIndex(states)
|
this._createFuseIndex(states, areaFloorComboBoxKeys)
|
||||||
),
|
),
|
||||||
entity: memoizeOne((states: EntityComboBoxItem[]) =>
|
entity: memoizeOne((states: EntityComboBoxItem[]) =>
|
||||||
this._createFuseIndex(states)
|
this._createFuseIndex(states, entityComboBoxKeys)
|
||||||
),
|
),
|
||||||
device: memoizeOne((states: DevicePickerItem[]) =>
|
device: memoizeOne((states: DevicePickerItem[]) =>
|
||||||
this._createFuseIndex(states)
|
this._createFuseIndex(states, deviceComboBoxKeys)
|
||||||
),
|
),
|
||||||
label: memoizeOne((states: PickerComboBoxItem[]) =>
|
label: memoizeOne((states: PickerComboBoxItem[]) =>
|
||||||
this._createFuseIndex(states)
|
this._createFuseIndex(states, labelComboBoxKeys)
|
||||||
),
|
),
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -134,8 +149,8 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private _createFuseIndex = (states) =>
|
private _createFuseIndex = (states, keys: FuseWeightedKey[]) =>
|
||||||
Fuse.createIndex(["search_labels"], states);
|
Fuse.createIndex(keys, states);
|
||||||
|
|
||||||
protected render() {
|
protected render() {
|
||||||
if (this.addOnTop) {
|
if (this.addOnTop) {
|
||||||
@@ -728,15 +743,14 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
: undefined,
|
: undefined,
|
||||||
undefined,
|
undefined,
|
||||||
`entity${SEPARATOR}`
|
`entity${SEPARATOR}`
|
||||||
);
|
).sort(this._sortBySortingLabel);
|
||||||
|
|
||||||
if (searchTerm) {
|
if (searchTerm) {
|
||||||
entityItems = this._filterGroup(
|
entityItems = this._filterGroup(
|
||||||
"entity",
|
"entity",
|
||||||
entityItems,
|
entityItems,
|
||||||
searchTerm,
|
searchTerm,
|
||||||
(item: EntityComboBoxItem) =>
|
entityComboBoxKeys
|
||||||
item.stateObj?.entity_id === searchTerm
|
|
||||||
) as EntityComboBoxItem[];
|
) as EntityComboBoxItem[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -762,10 +776,15 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
: undefined,
|
: undefined,
|
||||||
undefined,
|
undefined,
|
||||||
`device${SEPARATOR}`
|
`device${SEPARATOR}`
|
||||||
);
|
).sort(this._sortBySortingLabel);
|
||||||
|
|
||||||
if (searchTerm) {
|
if (searchTerm) {
|
||||||
deviceItems = this._filterGroup("device", deviceItems, searchTerm);
|
deviceItems = this._filterGroup(
|
||||||
|
"device",
|
||||||
|
deviceItems,
|
||||||
|
searchTerm,
|
||||||
|
deviceComboBoxKeys
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!filterType && deviceItems.length) {
|
if (!filterType && deviceItems.length) {
|
||||||
@@ -799,7 +818,9 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
areasAndFloors = this._filterGroup(
|
areasAndFloors = this._filterGroup(
|
||||||
"area",
|
"area",
|
||||||
areasAndFloors,
|
areasAndFloors,
|
||||||
searchTerm
|
searchTerm,
|
||||||
|
areaFloorComboBoxKeys,
|
||||||
|
false
|
||||||
) as FloorComboBoxItem[];
|
) as FloorComboBoxItem[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -841,10 +862,15 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
entityFilter,
|
entityFilter,
|
||||||
targetValue?.label_id ? ensureArray(targetValue.label_id) : undefined,
|
targetValue?.label_id ? ensureArray(targetValue.label_id) : undefined,
|
||||||
`label${SEPARATOR}`
|
`label${SEPARATOR}`
|
||||||
);
|
).sort(this._sortBySortingLabel);
|
||||||
|
|
||||||
if (searchTerm) {
|
if (searchTerm) {
|
||||||
labels = this._filterGroup("label", labels, searchTerm);
|
labels = this._filterGroup(
|
||||||
|
"label",
|
||||||
|
labels,
|
||||||
|
searchTerm,
|
||||||
|
labelComboBoxKeys
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!filterType && labels.length) {
|
if (!filterType && labels.length) {
|
||||||
@@ -863,40 +889,24 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
type: TargetType,
|
type: TargetType,
|
||||||
items: (FloorComboBoxItem | PickerComboBoxItem | EntityComboBoxItem)[],
|
items: (FloorComboBoxItem | PickerComboBoxItem | EntityComboBoxItem)[],
|
||||||
searchTerm: string,
|
searchTerm: string,
|
||||||
checkExact?: (
|
weightedKeys: FuseWeightedKey[],
|
||||||
item: FloorComboBoxItem | PickerComboBoxItem | EntityComboBoxItem
|
sort = true
|
||||||
) => boolean
|
|
||||||
) {
|
) {
|
||||||
const fuseIndex = this._fuseIndexes[type](items);
|
const fuseIndex = this._fuseIndexes[type](items);
|
||||||
const fuse = new HaFuse(
|
|
||||||
items,
|
|
||||||
{
|
|
||||||
shouldSort: false,
|
|
||||||
minMatchCharLength: Math.min(searchTerm.length, 2),
|
|
||||||
},
|
|
||||||
fuseIndex
|
|
||||||
);
|
|
||||||
|
|
||||||
const results = fuse.multiTermsSearch(searchTerm);
|
if (sort) {
|
||||||
let filteredItems = items;
|
return multiTermSortedSearch(
|
||||||
if (results) {
|
items,
|
||||||
filteredItems = results.map((result) => result.item);
|
searchTerm,
|
||||||
|
weightedKeys,
|
||||||
|
(item) => item.id,
|
||||||
|
fuseIndex
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!checkExact) {
|
return multiTermSearch(items, searchTerm, weightedKeys, fuseIndex, {
|
||||||
return filteredItems;
|
ignoreLocation: true,
|
||||||
}
|
});
|
||||||
|
|
||||||
// If there is exact match for entity id, put it first
|
|
||||||
const index = filteredItems.findIndex((item) => checkExact(item));
|
|
||||||
if (index === -1) {
|
|
||||||
return filteredItems;
|
|
||||||
}
|
|
||||||
|
|
||||||
const [exactMatch] = filteredItems.splice(index, 1);
|
|
||||||
filteredItems.unshift(exactMatch);
|
|
||||||
|
|
||||||
return filteredItems;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _getAdditionalItems = () => this._getCreateItems(this.createDomains);
|
private _getAdditionalItems = () => this._getCreateItems(this.createDomains);
|
||||||
@@ -952,10 +962,7 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
let hasFloor = false;
|
let hasFloor = false;
|
||||||
let rtl = false;
|
let rtl = false;
|
||||||
let showEntityId = false;
|
let showEntityId = false;
|
||||||
|
|
||||||
if (type === "area" || type === "floor") {
|
if (type === "area" || type === "floor") {
|
||||||
item.id = item[type]?.[`${type}_id`];
|
|
||||||
|
|
||||||
rtl = computeRTL(this.hass);
|
rtl = computeRTL(this.hass);
|
||||||
hasFloor =
|
hasFloor =
|
||||||
type === "area" && !!(item as FloorComboBoxItem).area?.floor_id;
|
type === "area" && !!(item as FloorComboBoxItem).area?.floor_id;
|
||||||
@@ -1061,6 +1068,13 @@ export class HaTargetPicker extends SubscribeMixin(LitElement) {
|
|||||||
term: html`<b>‘${search}’</b>`,
|
term: html`<b>‘${search}’</b>`,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
private _sortBySortingLabel = (entityA, entityB) =>
|
||||||
|
caseInsensitiveStringCompare(
|
||||||
|
(entityA as PickerComboBoxItem).sorting_label!,
|
||||||
|
(entityB as PickerComboBoxItem).sorting_label!,
|
||||||
|
this.hass?.locale.language ?? navigator.language
|
||||||
|
);
|
||||||
|
|
||||||
static get styles(): CSSResultGroup {
|
static get styles(): CSSResultGroup {
|
||||||
return css`
|
return css`
|
||||||
.add-target-wrapper {
|
.add-target-wrapper {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ export class HaToast extends Snackbar {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.mdc-snackbar {
|
.mdc-snackbar {
|
||||||
|
z-index: 10;
|
||||||
margin: 8px;
|
margin: 8px;
|
||||||
right: calc(8px + var(--safe-area-inset-right));
|
right: calc(8px + var(--safe-area-inset-right));
|
||||||
bottom: calc(8px + var(--safe-area-inset-bottom));
|
bottom: calc(8px + var(--safe-area-inset-bottom));
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ import { fireEvent } from "../../common/dom/fire_event";
|
|||||||
import { computeDomain } from "../../common/entity/compute_domain";
|
import { computeDomain } from "../../common/entity/compute_domain";
|
||||||
import { computeStateName } from "../../common/entity/compute_state_name";
|
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||||
import { supportsFeature } from "../../common/entity/supports-feature";
|
import { supportsFeature } from "../../common/entity/supports-feature";
|
||||||
import type { EntityRegistryDisplayEntry } from "../../data/entity_registry";
|
import type { EntityRegistryDisplayEntry } from "../../data/entity/entity_registry";
|
||||||
import { extractApiErrorMessage } from "../../data/hassio/common";
|
import { extractApiErrorMessage } from "../../data/hassio/common";
|
||||||
import {
|
import {
|
||||||
type MediaPlayerEntity,
|
type MediaPlayerEntity,
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ import { until } from "lit/directives/until";
|
|||||||
import { fireEvent } from "../../common/dom/fire_event";
|
import { fireEvent } from "../../common/dom/fire_event";
|
||||||
import { slugify } from "../../common/string/slugify";
|
import { slugify } from "../../common/string/slugify";
|
||||||
import { debounce } from "../../common/util/debounce";
|
import { debounce } from "../../common/util/debounce";
|
||||||
import { isUnavailableState } from "../../data/entity";
|
import { isUnavailableState } from "../../data/entity/entity";
|
||||||
import type {
|
import type {
|
||||||
MediaPickedEvent,
|
MediaPickedEvent,
|
||||||
MediaPlayerBrowseAction,
|
MediaPlayerBrowseAction,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { fireEvent } from "../../../common/dom/fire_event";
|
import { fireEvent } from "../../../common/dom/fire_event";
|
||||||
import type { HaEntityPickerEntityFilterFunc } from "../../../data/entity";
|
import type { HaEntityPickerEntityFilterFunc } from "../../../data/entity/entity";
|
||||||
import type { TargetType } from "../../../data/target";
|
import type { TargetType } from "../../../data/target";
|
||||||
import type { HaDevicePickerDeviceFilterFunc } from "../../device/ha-device-picker";
|
import type { HaDevicePickerDeviceFilterFunc } from "../../device/ha-device-picker";
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { css, html, LitElement, nothing } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property } from "lit/decorators";
|
import { customElement, property } from "lit/decorators";
|
||||||
import type { HaEntityPickerEntityFilterFunc } from "../../data/entity";
|
import type { HaEntityPickerEntityFilterFunc } from "../../data/entity/entity";
|
||||||
import type { TargetType, TargetTypeFloorless } from "../../data/target";
|
import type { TargetType, TargetTypeFloorless } from "../../data/target";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import type { HaDevicePickerDeviceFilterFunc } from "../device/ha-device-picker";
|
import type { HaDevicePickerDeviceFilterFunc } from "../device/ha-device-picker";
|
||||||
|
|||||||
@@ -23,11 +23,11 @@ import { computeRTL } from "../../common/util/compute_rtl";
|
|||||||
import type { AreaRegistryEntry } from "../../data/area_registry";
|
import type { AreaRegistryEntry } from "../../data/area_registry";
|
||||||
import { getConfigEntry } from "../../data/config_entries";
|
import { getConfigEntry } from "../../data/config_entries";
|
||||||
import { labelsContext } from "../../data/context";
|
import { labelsContext } from "../../data/context";
|
||||||
import type { DeviceRegistryEntry } from "../../data/device_registry";
|
import type { DeviceRegistryEntry } from "../../data/device/device_registry";
|
||||||
import type { HaEntityPickerEntityFilterFunc } from "../../data/entity";
|
import type { HaEntityPickerEntityFilterFunc } from "../../data/entity/entity";
|
||||||
import type { FloorRegistryEntry } from "../../data/floor_registry";
|
import type { FloorRegistryEntry } from "../../data/floor_registry";
|
||||||
import { domainToName } from "../../data/integration";
|
import { domainToName } from "../../data/integration";
|
||||||
import type { LabelRegistryEntry } from "../../data/label_registry";
|
import type { LabelRegistryEntry } from "../../data/label/label_registry";
|
||||||
import {
|
import {
|
||||||
areaMeetsFilter,
|
areaMeetsFilter,
|
||||||
deviceMeetsFilter,
|
deviceMeetsFilter,
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import { slugify } from "../../common/string/slugify";
|
|||||||
import { getConfigEntry } from "../../data/config_entries";
|
import { getConfigEntry } from "../../data/config_entries";
|
||||||
import { labelsContext } from "../../data/context";
|
import { labelsContext } from "../../data/context";
|
||||||
import { domainToName } from "../../data/integration";
|
import { domainToName } from "../../data/integration";
|
||||||
import type { LabelRegistryEntry } from "../../data/label_registry";
|
import type { LabelRegistryEntry } from "../../data/label/label_registry";
|
||||||
import type { TargetType } from "../../data/target";
|
import type { TargetType } from "../../data/target";
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import { brandsUrl } from "../../util/brands-url";
|
import { brandsUrl } from "../../util/brands-url";
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export class HaTraceBlueprintConfig extends LitElement {
|
|||||||
return html`
|
return html`
|
||||||
<ha-code-editor
|
<ha-code-editor
|
||||||
.value=${dump(this.trace.blueprint_inputs || "").trimRight()}
|
.value=${dump(this.trace.blueprint_inputs || "").trimRight()}
|
||||||
|
.hass=${this.hass}
|
||||||
read-only
|
read-only
|
||||||
dir="ltr"
|
dir="ltr"
|
||||||
></ha-code-editor>
|
></ha-code-editor>
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ export class HaTraceConfig extends LitElement {
|
|||||||
return html`
|
return html`
|
||||||
<ha-code-editor
|
<ha-code-editor
|
||||||
.value=${dump(this.trace.config).trimRight()}
|
.value=${dump(this.trace.config).trimRight()}
|
||||||
|
.hass=${this.hass}
|
||||||
read-only
|
read-only
|
||||||
dir="ltr"
|
dir="ltr"
|
||||||
></ha-code-editor>
|
></ha-code-editor>
|
||||||
|
|||||||
@@ -1,14 +1,21 @@
|
|||||||
import { dump } from "js-yaml";
|
|
||||||
import { consume } from "@lit/context";
|
import { consume } from "@lit/context";
|
||||||
|
import { dump } from "js-yaml";
|
||||||
import type { CSSResultGroup, TemplateResult } from "lit";
|
import type { CSSResultGroup, TemplateResult } from "lit";
|
||||||
import { css, html, LitElement, nothing } from "lit";
|
import { css, html, LitElement, nothing } from "lit";
|
||||||
import { customElement, property, state } from "lit/decorators";
|
import { customElement, property, state } from "lit/decorators";
|
||||||
import { classMap } from "lit/directives/class-map";
|
import { classMap } from "lit/directives/class-map";
|
||||||
import { formatDateTimeWithSeconds } from "../../common/datetime/format_date_time";
|
import { formatDateTimeWithSeconds } from "../../common/datetime/format_date_time";
|
||||||
import "../ha-code-editor";
|
import { describeCondition, describeTrigger } from "../../data/automation_i18n";
|
||||||
import "../ha-icon-button";
|
import {
|
||||||
import "./hat-logbook-note";
|
floorsContext,
|
||||||
|
fullEntitiesContext,
|
||||||
|
labelsContext,
|
||||||
|
} from "../../data/context";
|
||||||
|
import type { EntityRegistryEntry } from "../../data/entity/entity_registry";
|
||||||
|
import type { FloorRegistryEntry } from "../../data/floor_registry";
|
||||||
|
import type { LabelRegistryEntry } from "../../data/label/label_registry";
|
||||||
import type { LogbookEntry } from "../../data/logbook";
|
import type { LogbookEntry } from "../../data/logbook";
|
||||||
|
import { describeAction } from "../../data/script_i18n";
|
||||||
import type {
|
import type {
|
||||||
ActionTraceStep,
|
ActionTraceStep,
|
||||||
ChooseActionTraceStep,
|
ChooseActionTraceStep,
|
||||||
@@ -16,19 +23,12 @@ import type {
|
|||||||
} from "../../data/trace";
|
} from "../../data/trace";
|
||||||
import { getDataFromPath } from "../../data/trace";
|
import { getDataFromPath } from "../../data/trace";
|
||||||
import "../../panels/logbook/ha-logbook-renderer";
|
import "../../panels/logbook/ha-logbook-renderer";
|
||||||
import { traceTabStyles } from "./trace-tab-styles";
|
|
||||||
import type { HomeAssistant } from "../../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
|
import "../ha-code-editor";
|
||||||
|
import "../ha-icon-button";
|
||||||
|
import "./hat-logbook-note";
|
||||||
import type { NodeInfo } from "./hat-script-graph";
|
import type { NodeInfo } from "./hat-script-graph";
|
||||||
import { describeCondition, describeTrigger } from "../../data/automation_i18n";
|
import { traceTabStyles } from "./trace-tab-styles";
|
||||||
import type { EntityRegistryEntry } from "../../data/entity_registry";
|
|
||||||
import type { LabelRegistryEntry } from "../../data/label_registry";
|
|
||||||
import type { FloorRegistryEntry } from "../../data/floor_registry";
|
|
||||||
import {
|
|
||||||
floorsContext,
|
|
||||||
fullEntitiesContext,
|
|
||||||
labelsContext,
|
|
||||||
} from "../../data/context";
|
|
||||||
import { describeAction } from "../../data/script_i18n";
|
|
||||||
|
|
||||||
const TRACE_PATH_TABS = [
|
const TRACE_PATH_TABS = [
|
||||||
"step_config",
|
"step_config",
|
||||||
@@ -278,6 +278,7 @@ export class HaTracePathDetails extends LitElement {
|
|||||||
return config
|
return config
|
||||||
? html`<ha-code-editor
|
? html`<ha-code-editor
|
||||||
.value=${dump(config).trimEnd()}
|
.value=${dump(config).trimEnd()}
|
||||||
|
.hass=${this.hass}
|
||||||
read-only
|
read-only
|
||||||
dir="ltr"
|
dir="ltr"
|
||||||
></ha-code-editor>`
|
></ha-code-editor>`
|
||||||
|
|||||||
@@ -20,14 +20,14 @@ import {
|
|||||||
fullEntitiesContext,
|
fullEntitiesContext,
|
||||||
labelsContext,
|
labelsContext,
|
||||||
} from "../../data/context";
|
} from "../../data/context";
|
||||||
import type { EntityRegistryEntry } from "../../data/entity_registry";
|
import type { EntityRegistryEntry } from "../../data/entity/entity_registry";
|
||||||
import type { FloorRegistryEntry } from "../../data/floor_registry";
|
import type { FloorRegistryEntry } from "../../data/floor_registry";
|
||||||
import type { LabelRegistryEntry } from "../../data/label_registry";
|
import type { LabelRegistryEntry } from "../../data/label/label_registry";
|
||||||
import type { LogbookEntry } from "../../data/logbook";
|
import type { LogbookEntry } from "../../data/logbook";
|
||||||
import type {
|
import type {
|
||||||
ChooseAction,
|
ChooseAction,
|
||||||
Option,
|
|
||||||
IfAction,
|
IfAction,
|
||||||
|
Option,
|
||||||
ParallelAction,
|
ParallelAction,
|
||||||
RepeatAction,
|
RepeatAction,
|
||||||
SequenceAction,
|
SequenceAction,
|
||||||
|
|||||||
@@ -17,6 +17,12 @@ interface UserComboBoxItem extends PickerComboBoxItem {
|
|||||||
user?: User;
|
user?: User;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const SEARCH_KEYS = [
|
||||||
|
{ name: "primary", weight: 10 },
|
||||||
|
{ name: "search_labels.username", weight: 6 },
|
||||||
|
{ name: "id", weight: 3 },
|
||||||
|
];
|
||||||
|
|
||||||
@customElement("ha-user-picker")
|
@customElement("ha-user-picker")
|
||||||
class HaUserPicker extends LitElement {
|
class HaUserPicker extends LitElement {
|
||||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||||
@@ -109,9 +115,7 @@ class HaUserPicker extends LitElement {
|
|||||||
id: user.id,
|
id: user.id,
|
||||||
primary: user.name,
|
primary: user.name,
|
||||||
domain_name: user.name,
|
domain_name: user.name,
|
||||||
search_labels: [user.name, user.id, user.username].filter(
|
search_labels: { username: user.username },
|
||||||
Boolean
|
|
||||||
) as string[],
|
|
||||||
sorting_label: user.name,
|
sorting_label: user.name,
|
||||||
user,
|
user,
|
||||||
}));
|
}));
|
||||||
@@ -134,6 +138,10 @@ class HaUserPicker extends LitElement {
|
|||||||
.getItems=${this._getItems}
|
.getItems=${this._getItems}
|
||||||
.valueRenderer=${this._valueRenderer}
|
.valueRenderer=${this._valueRenderer}
|
||||||
.rowRenderer=${this._rowRenderer}
|
.rowRenderer=${this._rowRenderer}
|
||||||
|
.searchKeys=${SEARCH_KEYS}
|
||||||
|
.unknownItemText=${this.hass.localize(
|
||||||
|
"ui.components.user-picker.unknown"
|
||||||
|
)}
|
||||||
@value-changed=${this._valueChanged}
|
@value-changed=${this._valueChanged}
|
||||||
>
|
>
|
||||||
</ha-generic-picker>
|
</ha-generic-picker>
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ import type {
|
|||||||
import { supportsFeature } from "../common/entity/supports-feature";
|
import { supportsFeature } from "../common/entity/supports-feature";
|
||||||
import { showEnterCodeDialog } from "../dialogs/enter-code/show-enter-code-dialog";
|
import { showEnterCodeDialog } from "../dialogs/enter-code/show-enter-code-dialog";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
import { getExtendedEntityRegistryEntry } from "./entity_registry";
|
import { getExtendedEntityRegistryEntry } from "./entity/entity_registry";
|
||||||
|
|
||||||
export const FORMAT_TEXT = "text";
|
export const FORMAT_TEXT = "text";
|
||||||
export const FORMAT_NUMBER = "number";
|
export const FORMAT_NUMBER = "number";
|
||||||
|
|||||||
@@ -4,15 +4,16 @@ import { computeDomain } from "../common/entity/compute_domain";
|
|||||||
import { computeFloorName } from "../common/entity/compute_floor_name";
|
import { computeFloorName } from "../common/entity/compute_floor_name";
|
||||||
import type { HaDevicePickerDeviceFilterFunc } from "../components/device/ha-device-picker";
|
import type { HaDevicePickerDeviceFilterFunc } from "../components/device/ha-device-picker";
|
||||||
import type { PickerComboBoxItem } from "../components/ha-picker-combo-box";
|
import type { PickerComboBoxItem } from "../components/ha-picker-combo-box";
|
||||||
|
import type { FuseWeightedKey } from "../resources/fuseMultiTerm";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
import type { AreaRegistryEntry } from "./area_registry";
|
import type { AreaRegistryEntry } from "./area_registry";
|
||||||
import {
|
import {
|
||||||
getDeviceEntityDisplayLookup,
|
getDeviceEntityDisplayLookup,
|
||||||
type DeviceEntityDisplayLookup,
|
type DeviceEntityDisplayLookup,
|
||||||
type DeviceRegistryEntry,
|
type DeviceRegistryEntry,
|
||||||
} from "./device_registry";
|
} from "./device/device_registry";
|
||||||
import type { HaEntityPickerEntityFilterFunc } from "./entity";
|
import type { HaEntityPickerEntityFilterFunc } from "./entity/entity";
|
||||||
import type { EntityRegistryDisplayEntry } from "./entity_registry";
|
import type { EntityRegistryDisplayEntry } from "./entity/entity_registry";
|
||||||
import type { FloorRegistryEntry } from "./floor_registry";
|
import type { FloorRegistryEntry } from "./floor_registry";
|
||||||
|
|
||||||
export interface FloorComboBoxItem extends PickerComboBoxItem {
|
export interface FloorComboBoxItem extends PickerComboBoxItem {
|
||||||
@@ -26,7 +27,8 @@ export interface FloorNestedComboBoxItem extends PickerComboBoxItem {
|
|||||||
areas: FloorComboBoxItem[];
|
areas: FloorComboBoxItem[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface UnassignedAreasFloorComboBoxItem extends PickerComboBoxItem {
|
export interface UnassignedAreasFloorComboBoxItem {
|
||||||
|
id: undefined;
|
||||||
areas: FloorComboBoxItem[];
|
areas: FloorComboBoxItem[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,6 +100,29 @@ export const getAreasAndFloors = (
|
|||||||
excludeFloors
|
excludeFloors
|
||||||
) as FloorComboBoxItem[];
|
) as FloorComboBoxItem[];
|
||||||
|
|
||||||
|
export const areaFloorComboBoxKeys: FuseWeightedKey[] = [
|
||||||
|
{
|
||||||
|
name: "search_labels.name",
|
||||||
|
weight: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "search_labels.aliases",
|
||||||
|
weight: 8,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "search_labels.floorName",
|
||||||
|
weight: 6,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "search_labels.relatedAreas",
|
||||||
|
weight: 4,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "search_labels.id",
|
||||||
|
weight: 3,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
const getAreasAndFloorsItems = (
|
const getAreasAndFloorsItems = (
|
||||||
states: HomeAssistant["states"],
|
states: HomeAssistant["states"],
|
||||||
haFloors: HomeAssistant["floors"],
|
haFloors: HomeAssistant["floors"],
|
||||||
@@ -304,12 +329,12 @@ const getAreasAndFloorsItems = (
|
|||||||
primary: floorName,
|
primary: floorName,
|
||||||
floor: floor,
|
floor: floor,
|
||||||
icon: floor.icon || undefined,
|
icon: floor.icon || undefined,
|
||||||
search_labels: [
|
search_labels: {
|
||||||
floor.floor_id,
|
id: floor.floor_id,
|
||||||
floorName,
|
name: floorName || null,
|
||||||
...floor.aliases,
|
aliases: floor.aliases.join(", ") || null,
|
||||||
...areaSearchLabels,
|
relatedAreas: areaSearchLabels.join(" ") || null,
|
||||||
],
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
items.push(floorItem);
|
items.push(floorItem);
|
||||||
@@ -322,11 +347,12 @@ const getAreasAndFloorsItems = (
|
|||||||
primary: areaName || area.area_id,
|
primary: areaName || area.area_id,
|
||||||
area: area,
|
area: area,
|
||||||
icon: area.icon || undefined,
|
icon: area.icon || undefined,
|
||||||
search_labels: [
|
search_labels: {
|
||||||
area.area_id,
|
id: area.area_id,
|
||||||
...(areaName ? [areaName] : []),
|
name: areaName || null,
|
||||||
...area.aliases,
|
aliases: area.aliases.join(", ") || null,
|
||||||
],
|
floorName: floorName || null,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -339,19 +365,24 @@ const getAreasAndFloorsItems = (
|
|||||||
|
|
||||||
const unassignedAreaItems = hierarchy.areas.map((areaId) => {
|
const unassignedAreaItems = hierarchy.areas.map((areaId) => {
|
||||||
const area = haAreas[areaId];
|
const area = haAreas[areaId];
|
||||||
const areaName = computeAreaName(area) || area.area_id;
|
const areaName = computeAreaName(area);
|
||||||
return {
|
return {
|
||||||
id: formatId({ id: area.area_id, type: "area" }),
|
id: formatId({ id: area.area_id, type: "area" }),
|
||||||
type: "area" as const,
|
type: "area" as const,
|
||||||
primary: areaName,
|
primary: areaName || area.area_id,
|
||||||
area: area,
|
area: area,
|
||||||
icon: area.icon || undefined,
|
icon: area.icon || undefined,
|
||||||
search_labels: [area.area_id, areaName, ...area.aliases],
|
search_labels: {
|
||||||
|
id: area.area_id,
|
||||||
|
name: areaName || null,
|
||||||
|
aliases: area.aliases.join(", ") || null,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
if (nested && unassignedAreaItems.length) {
|
if (nested && unassignedAreaItems.length) {
|
||||||
items.push({
|
items.push({
|
||||||
|
id: undefined,
|
||||||
areas: unassignedAreaItems,
|
areas: unassignedAreaItems,
|
||||||
} as UnassignedAreasFloorComboBoxItem);
|
} as UnassignedAreasFloorComboBoxItem);
|
||||||
} else {
|
} else {
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
import type { DeviceRegistryEntry } from "./device_registry";
|
import type { DeviceRegistryEntry } from "./device/device_registry";
|
||||||
import type {
|
import type {
|
||||||
EntityRegistryDisplayEntry,
|
EntityRegistryDisplayEntry,
|
||||||
EntityRegistryEntry,
|
EntityRegistryEntry,
|
||||||
} from "./entity_registry";
|
} from "./entity/entity_registry";
|
||||||
import type { RegistryEntry } from "./registry";
|
import type { RegistryEntry } from "./registry";
|
||||||
|
|
||||||
export { subscribeAreaRegistry } from "./ws-area_registry";
|
export { subscribeAreaRegistry } from "./ws-area_registry";
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import type { HassEntity } from "home-assistant-js-websocket";
|
import type { HassEntity } from "home-assistant-js-websocket";
|
||||||
import type { HomeAssistant } from "../types";
|
|
||||||
import { supportsFeature } from "../common/entity/supports-feature";
|
import { supportsFeature } from "../common/entity/supports-feature";
|
||||||
import { UNAVAILABLE } from "./entity";
|
import type { HomeAssistant } from "../types";
|
||||||
|
import { UNAVAILABLE } from "./entity/entity";
|
||||||
|
|
||||||
export const enum AssistSatelliteEntityFeature {
|
export const enum AssistSatelliteEntityFeature {
|
||||||
ANNOUNCE = 1,
|
ANNOUNCE = 1,
|
||||||
|
|||||||
@@ -12,7 +12,10 @@ import type { Context, HomeAssistant } from "../types";
|
|||||||
import type { BlueprintInput } from "./blueprint";
|
import type { BlueprintInput } from "./blueprint";
|
||||||
import type { ConditionDescription } from "./condition";
|
import type { ConditionDescription } from "./condition";
|
||||||
import { CONDITION_BUILDING_BLOCKS } from "./condition";
|
import { CONDITION_BUILDING_BLOCKS } from "./condition";
|
||||||
import type { DeviceCondition, DeviceTrigger } from "./device_automation";
|
import type {
|
||||||
|
DeviceCondition,
|
||||||
|
DeviceTrigger,
|
||||||
|
} from "./device/device_automation";
|
||||||
import type { Action, Field, MODES } from "./script";
|
import type { Action, Field, MODES } from "./script";
|
||||||
import { migrateAutomationAction } from "./script";
|
import { migrateAutomationAction } from "./script";
|
||||||
import type { TriggerDescription } from "./trigger";
|
import type { TriggerDescription } from "./trigger";
|
||||||
|
|||||||
@@ -26,12 +26,15 @@ import type {
|
|||||||
Trigger,
|
Trigger,
|
||||||
} from "./automation";
|
} from "./automation";
|
||||||
import { getConditionDomain, getConditionObjectId } from "./condition";
|
import { getConditionDomain, getConditionObjectId } from "./condition";
|
||||||
import type { DeviceCondition, DeviceTrigger } from "./device_automation";
|
import type {
|
||||||
|
DeviceCondition,
|
||||||
|
DeviceTrigger,
|
||||||
|
} from "./device/device_automation";
|
||||||
import {
|
import {
|
||||||
localizeDeviceAutomationCondition,
|
localizeDeviceAutomationCondition,
|
||||||
localizeDeviceAutomationTrigger,
|
localizeDeviceAutomationTrigger,
|
||||||
} from "./device_automation";
|
} from "./device/device_automation";
|
||||||
import type { EntityRegistryEntry } from "./entity_registry";
|
import type { EntityRegistryEntry } from "./entity/entity_registry";
|
||||||
import type { FrontendLocaleData } from "./translation";
|
import type { FrontendLocaleData } from "./translation";
|
||||||
import { getTriggerDomain, getTriggerObjectId, isTriggerList } from "./trigger";
|
import { getTriggerDomain, getTriggerObjectId, isTriggerList } from "./trigger";
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import { getColorByIndex } from "../common/color/colors";
|
|||||||
import { computeDomain } from "../common/entity/compute_domain";
|
import { computeDomain } from "../common/entity/compute_domain";
|
||||||
import { computeStateName } from "../common/entity/compute_state_name";
|
import { computeStateName } from "../common/entity/compute_state_name";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
import { isUnavailableState } from "./entity";
|
import { isUnavailableState } from "./entity/entity";
|
||||||
|
|
||||||
export interface Calendar {
|
export interface Calendar {
|
||||||
entity_id: string;
|
entity_id: string;
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import { createContext } from "@lit/context";
|
import { createContext } from "@lit/context";
|
||||||
import type { HassConfig } from "home-assistant-js-websocket";
|
import type { HassConfig } from "home-assistant-js-websocket";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
import type { EntityRegistryEntry } from "./entity_registry";
|
import type { EntityRegistryEntry } from "./entity/entity_registry";
|
||||||
import type { LabelRegistryEntry } from "./label_registry";
|
import type { LabelRegistryEntry } from "./label/label_registry";
|
||||||
|
|
||||||
export const connectionContext =
|
export const connectionContext =
|
||||||
createContext<HomeAssistant["connection"]>("connection");
|
createContext<HomeAssistant["connection"]>("connection");
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import type {
|
|||||||
import { stateActive } from "../common/entity/state_active";
|
import { stateActive } from "../common/entity/state_active";
|
||||||
import { supportsFeature } from "../common/entity/supports-feature";
|
import { supportsFeature } from "../common/entity/supports-feature";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
import { UNAVAILABLE } from "./entity";
|
import { UNAVAILABLE } from "./entity/entity";
|
||||||
|
|
||||||
export const enum CoverEntityFeature {
|
export const enum CoverEntityFeature {
|
||||||
OPEN = 1,
|
OPEN = 1,
|
||||||
|
|||||||
@@ -1,14 +1,14 @@
|
|||||||
import { computeStateName } from "../common/entity/compute_state_name";
|
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||||
import type { HaFormSchema } from "../components/ha-form/types";
|
import type { HaFormSchema } from "../../components/ha-form/types";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
import type { BaseTrigger } from "./automation";
|
import type { BaseTrigger } from "../automation";
|
||||||
import { migrateAutomationTrigger } from "./automation";
|
import { migrateAutomationTrigger } from "../automation";
|
||||||
import type { EntityRegistryEntry } from "./entity_registry";
|
import type { EntityRegistryEntry } from "../entity/entity_registry";
|
||||||
import {
|
import {
|
||||||
computeEntityRegistryName,
|
computeEntityRegistryName,
|
||||||
entityRegistryByEntityId,
|
entityRegistryByEntityId,
|
||||||
entityRegistryById,
|
entityRegistryById,
|
||||||
} from "./entity_registry";
|
} from "../entity/entity_registry";
|
||||||
|
|
||||||
export interface DeviceAutomation {
|
export interface DeviceAutomation {
|
||||||
alias?: string;
|
alias?: string;
|
||||||
182
src/data/device/device_picker.ts
Normal file
182
src/data/device/device_picker.ts
Normal file
@@ -0,0 +1,182 @@
|
|||||||
|
import { computeAreaName } from "../../common/entity/compute_area_name";
|
||||||
|
import { computeDeviceNameDisplay } from "../../common/entity/compute_device_name";
|
||||||
|
import { computeDomain } from "../../common/entity/compute_domain";
|
||||||
|
import { getDeviceContext } from "../../common/entity/context/get_device_context";
|
||||||
|
import type { HaDevicePickerDeviceFilterFunc } from "../../components/device/ha-device-picker";
|
||||||
|
import type { PickerComboBoxItem } from "../../components/ha-picker-combo-box";
|
||||||
|
import type { FuseWeightedKey } from "../../resources/fuseMultiTerm";
|
||||||
|
import type { HomeAssistant } from "../../types";
|
||||||
|
import type { ConfigEntry } from "../config_entries";
|
||||||
|
import type { HaEntityPickerEntityFilterFunc } from "../entity/entity";
|
||||||
|
import { domainToName } from "../integration";
|
||||||
|
import {
|
||||||
|
getDeviceEntityDisplayLookup,
|
||||||
|
type DeviceEntityDisplayLookup,
|
||||||
|
} from "./device_registry";
|
||||||
|
|
||||||
|
export interface DevicePickerItem extends PickerComboBoxItem {
|
||||||
|
domain?: string;
|
||||||
|
domain_name?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const deviceComboBoxKeys: FuseWeightedKey[] = [
|
||||||
|
{
|
||||||
|
name: "search_labels.deviceName",
|
||||||
|
weight: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "search_labels.areaName",
|
||||||
|
weight: 8,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "search_labels.domainName",
|
||||||
|
weight: 4,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "search_labels.domain",
|
||||||
|
weight: 4,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export const getDevices = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
configEntryLookup: Record<string, ConfigEntry>,
|
||||||
|
includeDomains?: string[],
|
||||||
|
excludeDomains?: string[],
|
||||||
|
includeDeviceClasses?: string[],
|
||||||
|
deviceFilter?: HaDevicePickerDeviceFilterFunc,
|
||||||
|
entityFilter?: HaEntityPickerEntityFilterFunc,
|
||||||
|
excludeDevices?: string[],
|
||||||
|
value?: string,
|
||||||
|
idPrefix = ""
|
||||||
|
): DevicePickerItem[] => {
|
||||||
|
const devices = Object.values(hass.devices);
|
||||||
|
const entities = Object.values(hass.entities);
|
||||||
|
|
||||||
|
let deviceEntityLookup: DeviceEntityDisplayLookup = {};
|
||||||
|
|
||||||
|
if (
|
||||||
|
includeDomains ||
|
||||||
|
excludeDomains ||
|
||||||
|
includeDeviceClasses ||
|
||||||
|
entityFilter
|
||||||
|
) {
|
||||||
|
deviceEntityLookup = getDeviceEntityDisplayLookup(entities);
|
||||||
|
}
|
||||||
|
|
||||||
|
let inputDevices = devices.filter(
|
||||||
|
(device) => device.id === value || !device.disabled_by
|
||||||
|
);
|
||||||
|
|
||||||
|
if (includeDomains) {
|
||||||
|
inputDevices = inputDevices.filter((device) => {
|
||||||
|
const devEntities = deviceEntityLookup[device.id];
|
||||||
|
if (!devEntities || !devEntities.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return deviceEntityLookup[device.id].some((entity) =>
|
||||||
|
includeDomains.includes(computeDomain(entity.entity_id))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (excludeDomains) {
|
||||||
|
inputDevices = inputDevices.filter((device) => {
|
||||||
|
const devEntities = deviceEntityLookup[device.id];
|
||||||
|
if (!devEntities || !devEntities.length) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return entities.every(
|
||||||
|
(entity) => !excludeDomains.includes(computeDomain(entity.entity_id))
|
||||||
|
);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (excludeDevices) {
|
||||||
|
inputDevices = inputDevices.filter(
|
||||||
|
(device) => !excludeDevices!.includes(device.id)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (includeDeviceClasses) {
|
||||||
|
inputDevices = inputDevices.filter((device) => {
|
||||||
|
const devEntities = deviceEntityLookup[device.id];
|
||||||
|
if (!devEntities || !devEntities.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return deviceEntityLookup[device.id].some((entity) => {
|
||||||
|
const stateObj = hass.states[entity.entity_id];
|
||||||
|
if (!stateObj) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
stateObj.attributes.device_class &&
|
||||||
|
includeDeviceClasses.includes(stateObj.attributes.device_class)
|
||||||
|
);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entityFilter) {
|
||||||
|
inputDevices = inputDevices.filter((device) => {
|
||||||
|
const devEntities = deviceEntityLookup[device.id];
|
||||||
|
if (!devEntities || !devEntities.length) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return devEntities.some((entity) => {
|
||||||
|
const stateObj = hass.states[entity.entity_id];
|
||||||
|
if (!stateObj) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return entityFilter(stateObj);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (deviceFilter) {
|
||||||
|
inputDevices = inputDevices.filter(
|
||||||
|
(device) =>
|
||||||
|
// We always want to include the device of the current value
|
||||||
|
device.id === value || deviceFilter!(device)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
const outputDevices = inputDevices.map<DevicePickerItem>((device) => {
|
||||||
|
const deviceName = computeDeviceNameDisplay(
|
||||||
|
device,
|
||||||
|
hass,
|
||||||
|
deviceEntityLookup[device.id]
|
||||||
|
);
|
||||||
|
|
||||||
|
const { area } = getDeviceContext(device, hass);
|
||||||
|
|
||||||
|
const areaName = area ? computeAreaName(area) : undefined;
|
||||||
|
|
||||||
|
const configEntry = device.primary_config_entry
|
||||||
|
? configEntryLookup?.[device.primary_config_entry]
|
||||||
|
: undefined;
|
||||||
|
|
||||||
|
const domain = configEntry?.domain;
|
||||||
|
const domainName = domain ? domainToName(hass.localize, domain) : undefined;
|
||||||
|
const primary =
|
||||||
|
deviceName || hass.localize("ui.components.device-picker.unnamed_device");
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: `${idPrefix}${device.id}`,
|
||||||
|
label: "",
|
||||||
|
primary,
|
||||||
|
secondary: areaName,
|
||||||
|
domain: configEntry?.domain,
|
||||||
|
domain_name: domainName,
|
||||||
|
search_labels: {
|
||||||
|
deviceName,
|
||||||
|
areaName: areaName || null,
|
||||||
|
domain: domain || null,
|
||||||
|
domainName: domainName || null,
|
||||||
|
},
|
||||||
|
sorting_label: [primary, areaName, domainName].filter(Boolean).join("_"),
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
return outputDevices;
|
||||||
|
};
|
||||||
169
src/data/device/device_registry.ts
Normal file
169
src/data/device/device_registry.ts
Normal file
@@ -0,0 +1,169 @@
|
|||||||
|
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||||
|
import { caseInsensitiveStringCompare } from "../../common/string/compare";
|
||||||
|
import type { HomeAssistant } from "../../types";
|
||||||
|
import type { ConfigEntry } from "../config_entries";
|
||||||
|
import type {
|
||||||
|
EntityRegistryDisplayEntry,
|
||||||
|
EntityRegistryEntry,
|
||||||
|
} from "../entity/entity_registry";
|
||||||
|
import type { EntitySources } from "../entity/entity_sources";
|
||||||
|
import type { RegistryEntry } from "../registry";
|
||||||
|
|
||||||
|
export {
|
||||||
|
fetchDeviceRegistry,
|
||||||
|
subscribeDeviceRegistry,
|
||||||
|
} from "../ws-device_registry";
|
||||||
|
|
||||||
|
export interface DeviceRegistryEntry extends RegistryEntry {
|
||||||
|
id: string;
|
||||||
|
config_entries: string[];
|
||||||
|
config_entries_subentries: Record<string, (string | null)[]>;
|
||||||
|
connections: [string, string][];
|
||||||
|
identifiers: [string, string][];
|
||||||
|
manufacturer: string | null;
|
||||||
|
model: string | null;
|
||||||
|
model_id: string | null;
|
||||||
|
name: string | null;
|
||||||
|
labels: string[];
|
||||||
|
sw_version: string | null;
|
||||||
|
hw_version: string | null;
|
||||||
|
serial_number: string | null;
|
||||||
|
via_device_id: string | null;
|
||||||
|
area_id: string | null;
|
||||||
|
name_by_user: string | null;
|
||||||
|
entry_type: "service" | null;
|
||||||
|
disabled_by: "user" | "integration" | "config_entry" | null;
|
||||||
|
configuration_url: string | null;
|
||||||
|
primary_config_entry: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type DeviceEntityDisplayLookup = Record<
|
||||||
|
string,
|
||||||
|
EntityRegistryDisplayEntry[]
|
||||||
|
>;
|
||||||
|
|
||||||
|
export type DeviceEntityLookup<
|
||||||
|
T extends EntityRegistryEntry | EntityRegistryDisplayEntry =
|
||||||
|
| EntityRegistryEntry
|
||||||
|
| EntityRegistryDisplayEntry,
|
||||||
|
> = Record<string, T[]>;
|
||||||
|
|
||||||
|
export interface DeviceRegistryEntryMutableParams {
|
||||||
|
area_id?: string | null;
|
||||||
|
name_by_user?: string | null;
|
||||||
|
disabled_by?: string | null;
|
||||||
|
labels?: string[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const fallbackDeviceName = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
entities: EntityRegistryEntry[] | EntityRegistryDisplayEntry[] | string[]
|
||||||
|
) => {
|
||||||
|
for (const entity of entities || []) {
|
||||||
|
const entityId = typeof entity === "string" ? entity : entity.entity_id;
|
||||||
|
const stateObj = hass.states[entityId];
|
||||||
|
if (stateObj) {
|
||||||
|
return computeStateName(stateObj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return undefined;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const devicesInArea = (devices: DeviceRegistryEntry[], areaId: string) =>
|
||||||
|
devices.filter((device) => device.area_id === areaId);
|
||||||
|
|
||||||
|
export const updateDeviceRegistryEntry = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
deviceId: string,
|
||||||
|
updates: Partial<DeviceRegistryEntryMutableParams>
|
||||||
|
) =>
|
||||||
|
hass.callWS<DeviceRegistryEntry>({
|
||||||
|
type: "config/device_registry/update",
|
||||||
|
device_id: deviceId,
|
||||||
|
...updates,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const removeConfigEntryFromDevice = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
deviceId: string,
|
||||||
|
configEntryId: string
|
||||||
|
) =>
|
||||||
|
hass.callWS<DeviceRegistryEntry>({
|
||||||
|
type: "config/device_registry/remove_config_entry",
|
||||||
|
device_id: deviceId,
|
||||||
|
config_entry_id: configEntryId,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const sortDeviceRegistryByName = (
|
||||||
|
entries: DeviceRegistryEntry[],
|
||||||
|
language: string
|
||||||
|
) =>
|
||||||
|
entries.sort((entry1, entry2) =>
|
||||||
|
caseInsensitiveStringCompare(entry1.name || "", entry2.name || "", language)
|
||||||
|
);
|
||||||
|
|
||||||
|
export const getDeviceEntityLookup = (
|
||||||
|
entities: (EntityRegistryEntry | EntityRegistryDisplayEntry)[]
|
||||||
|
): DeviceEntityLookup => {
|
||||||
|
const deviceEntityLookup: DeviceEntityLookup = {};
|
||||||
|
for (const entity of entities) {
|
||||||
|
if (!entity.device_id) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!(entity.device_id in deviceEntityLookup)) {
|
||||||
|
deviceEntityLookup[entity.device_id] = [];
|
||||||
|
}
|
||||||
|
deviceEntityLookup[entity.device_id].push(entity);
|
||||||
|
}
|
||||||
|
return deviceEntityLookup;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getDeviceEntityDisplayLookup = (
|
||||||
|
entities: EntityRegistryDisplayEntry[]
|
||||||
|
): DeviceEntityDisplayLookup => {
|
||||||
|
const deviceEntityLookup: DeviceEntityDisplayLookup = {};
|
||||||
|
for (const entity of entities) {
|
||||||
|
if (!entity.device_id) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!(entity.device_id in deviceEntityLookup)) {
|
||||||
|
deviceEntityLookup[entity.device_id] = [];
|
||||||
|
}
|
||||||
|
deviceEntityLookup[entity.device_id].push(entity);
|
||||||
|
}
|
||||||
|
return deviceEntityLookup;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getDeviceIntegrationLookup = (
|
||||||
|
entitySources: EntitySources,
|
||||||
|
entities: EntityRegistryDisplayEntry[] | EntityRegistryEntry[],
|
||||||
|
devices?: DeviceRegistryEntry[],
|
||||||
|
configEntries?: ConfigEntry[]
|
||||||
|
): Record<string, Set<string>> => {
|
||||||
|
const deviceIntegrations: Record<string, Set<string>> = {};
|
||||||
|
|
||||||
|
for (const entity of entities) {
|
||||||
|
const source = entitySources[entity.entity_id];
|
||||||
|
if (!source?.domain || entity.device_id === null) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
deviceIntegrations[entity.device_id!] =
|
||||||
|
deviceIntegrations[entity.device_id!] || new Set<string>();
|
||||||
|
deviceIntegrations[entity.device_id!].add(source.domain);
|
||||||
|
}
|
||||||
|
// Lookup devices that have no entities
|
||||||
|
if (devices && configEntries) {
|
||||||
|
for (const device of devices) {
|
||||||
|
for (const config_entry_id of device.config_entries) {
|
||||||
|
const entry = configEntries.find((e) => e.entry_id === config_entry_id);
|
||||||
|
if (entry?.domain) {
|
||||||
|
deviceIntegrations[device.id] =
|
||||||
|
deviceIntegrations[device.id] || new Set<string>();
|
||||||
|
deviceIntegrations[device.id].add(entry.domain);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return deviceIntegrations;
|
||||||
|
};
|
||||||
@@ -1,322 +0,0 @@
|
|||||||
import { computeAreaName } from "../common/entity/compute_area_name";
|
|
||||||
import { computeDeviceNameDisplay } from "../common/entity/compute_device_name";
|
|
||||||
import { computeDomain } from "../common/entity/compute_domain";
|
|
||||||
import { computeStateName } from "../common/entity/compute_state_name";
|
|
||||||
import { getDeviceContext } from "../common/entity/context/get_device_context";
|
|
||||||
import { caseInsensitiveStringCompare } from "../common/string/compare";
|
|
||||||
import type { HaDevicePickerDeviceFilterFunc } from "../components/device/ha-device-picker";
|
|
||||||
import type { PickerComboBoxItem } from "../components/ha-picker-combo-box";
|
|
||||||
import type { HomeAssistant } from "../types";
|
|
||||||
import type { ConfigEntry } from "./config_entries";
|
|
||||||
import type { HaEntityPickerEntityFilterFunc } from "./entity";
|
|
||||||
import type {
|
|
||||||
EntityRegistryDisplayEntry,
|
|
||||||
EntityRegistryEntry,
|
|
||||||
} from "./entity_registry";
|
|
||||||
import type { EntitySources } from "./entity_sources";
|
|
||||||
import { domainToName } from "./integration";
|
|
||||||
import type { RegistryEntry } from "./registry";
|
|
||||||
|
|
||||||
export {
|
|
||||||
fetchDeviceRegistry,
|
|
||||||
subscribeDeviceRegistry,
|
|
||||||
} from "./ws-device_registry";
|
|
||||||
|
|
||||||
export interface DeviceRegistryEntry extends RegistryEntry {
|
|
||||||
id: string;
|
|
||||||
config_entries: string[];
|
|
||||||
config_entries_subentries: Record<string, (string | null)[]>;
|
|
||||||
connections: [string, string][];
|
|
||||||
identifiers: [string, string][];
|
|
||||||
manufacturer: string | null;
|
|
||||||
model: string | null;
|
|
||||||
model_id: string | null;
|
|
||||||
name: string | null;
|
|
||||||
labels: string[];
|
|
||||||
sw_version: string | null;
|
|
||||||
hw_version: string | null;
|
|
||||||
serial_number: string | null;
|
|
||||||
via_device_id: string | null;
|
|
||||||
area_id: string | null;
|
|
||||||
name_by_user: string | null;
|
|
||||||
entry_type: "service" | null;
|
|
||||||
disabled_by: "user" | "integration" | "config_entry" | null;
|
|
||||||
configuration_url: string | null;
|
|
||||||
primary_config_entry: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type DeviceEntityDisplayLookup = Record<
|
|
||||||
string,
|
|
||||||
EntityRegistryDisplayEntry[]
|
|
||||||
>;
|
|
||||||
|
|
||||||
export type DeviceEntityLookup<
|
|
||||||
T extends EntityRegistryEntry | EntityRegistryDisplayEntry =
|
|
||||||
| EntityRegistryEntry
|
|
||||||
| EntityRegistryDisplayEntry,
|
|
||||||
> = Record<string, T[]>;
|
|
||||||
|
|
||||||
export interface DeviceRegistryEntryMutableParams {
|
|
||||||
area_id?: string | null;
|
|
||||||
name_by_user?: string | null;
|
|
||||||
disabled_by?: string | null;
|
|
||||||
labels?: string[];
|
|
||||||
}
|
|
||||||
|
|
||||||
export const fallbackDeviceName = (
|
|
||||||
hass: HomeAssistant,
|
|
||||||
entities: EntityRegistryEntry[] | EntityRegistryDisplayEntry[] | string[]
|
|
||||||
) => {
|
|
||||||
for (const entity of entities || []) {
|
|
||||||
const entityId = typeof entity === "string" ? entity : entity.entity_id;
|
|
||||||
const stateObj = hass.states[entityId];
|
|
||||||
if (stateObj) {
|
|
||||||
return computeStateName(stateObj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return undefined;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const devicesInArea = (devices: DeviceRegistryEntry[], areaId: string) =>
|
|
||||||
devices.filter((device) => device.area_id === areaId);
|
|
||||||
|
|
||||||
export const updateDeviceRegistryEntry = (
|
|
||||||
hass: HomeAssistant,
|
|
||||||
deviceId: string,
|
|
||||||
updates: Partial<DeviceRegistryEntryMutableParams>
|
|
||||||
) =>
|
|
||||||
hass.callWS<DeviceRegistryEntry>({
|
|
||||||
type: "config/device_registry/update",
|
|
||||||
device_id: deviceId,
|
|
||||||
...updates,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const removeConfigEntryFromDevice = (
|
|
||||||
hass: HomeAssistant,
|
|
||||||
deviceId: string,
|
|
||||||
configEntryId: string
|
|
||||||
) =>
|
|
||||||
hass.callWS<DeviceRegistryEntry>({
|
|
||||||
type: "config/device_registry/remove_config_entry",
|
|
||||||
device_id: deviceId,
|
|
||||||
config_entry_id: configEntryId,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const sortDeviceRegistryByName = (
|
|
||||||
entries: DeviceRegistryEntry[],
|
|
||||||
language: string
|
|
||||||
) =>
|
|
||||||
entries.sort((entry1, entry2) =>
|
|
||||||
caseInsensitiveStringCompare(entry1.name || "", entry2.name || "", language)
|
|
||||||
);
|
|
||||||
|
|
||||||
export const getDeviceEntityLookup = (
|
|
||||||
entities: (EntityRegistryEntry | EntityRegistryDisplayEntry)[]
|
|
||||||
): DeviceEntityLookup => {
|
|
||||||
const deviceEntityLookup: DeviceEntityLookup = {};
|
|
||||||
for (const entity of entities) {
|
|
||||||
if (!entity.device_id) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!(entity.device_id in deviceEntityLookup)) {
|
|
||||||
deviceEntityLookup[entity.device_id] = [];
|
|
||||||
}
|
|
||||||
deviceEntityLookup[entity.device_id].push(entity);
|
|
||||||
}
|
|
||||||
return deviceEntityLookup;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getDeviceEntityDisplayLookup = (
|
|
||||||
entities: EntityRegistryDisplayEntry[]
|
|
||||||
): DeviceEntityDisplayLookup => {
|
|
||||||
const deviceEntityLookup: DeviceEntityDisplayLookup = {};
|
|
||||||
for (const entity of entities) {
|
|
||||||
if (!entity.device_id) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!(entity.device_id in deviceEntityLookup)) {
|
|
||||||
deviceEntityLookup[entity.device_id] = [];
|
|
||||||
}
|
|
||||||
deviceEntityLookup[entity.device_id].push(entity);
|
|
||||||
}
|
|
||||||
return deviceEntityLookup;
|
|
||||||
};
|
|
||||||
|
|
||||||
export const getDeviceIntegrationLookup = (
|
|
||||||
entitySources: EntitySources,
|
|
||||||
entities: EntityRegistryDisplayEntry[] | EntityRegistryEntry[],
|
|
||||||
devices?: DeviceRegistryEntry[],
|
|
||||||
configEntries?: ConfigEntry[]
|
|
||||||
): Record<string, Set<string>> => {
|
|
||||||
const deviceIntegrations: Record<string, Set<string>> = {};
|
|
||||||
|
|
||||||
for (const entity of entities) {
|
|
||||||
const source = entitySources[entity.entity_id];
|
|
||||||
if (!source?.domain || entity.device_id === null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
deviceIntegrations[entity.device_id!] =
|
|
||||||
deviceIntegrations[entity.device_id!] || new Set<string>();
|
|
||||||
deviceIntegrations[entity.device_id!].add(source.domain);
|
|
||||||
}
|
|
||||||
// Lookup devices that have no entities
|
|
||||||
if (devices && configEntries) {
|
|
||||||
for (const device of devices) {
|
|
||||||
for (const config_entry_id of device.config_entries) {
|
|
||||||
const entry = configEntries.find((e) => e.entry_id === config_entry_id);
|
|
||||||
if (entry?.domain) {
|
|
||||||
deviceIntegrations[device.id] =
|
|
||||||
deviceIntegrations[device.id] || new Set<string>();
|
|
||||||
deviceIntegrations[device.id].add(entry.domain);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return deviceIntegrations;
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface DevicePickerItem extends PickerComboBoxItem {
|
|
||||||
domain?: string;
|
|
||||||
domain_name?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getDevices = (
|
|
||||||
hass: HomeAssistant,
|
|
||||||
configEntryLookup: Record<string, ConfigEntry>,
|
|
||||||
includeDomains?: string[],
|
|
||||||
excludeDomains?: string[],
|
|
||||||
includeDeviceClasses?: string[],
|
|
||||||
deviceFilter?: HaDevicePickerDeviceFilterFunc,
|
|
||||||
entityFilter?: HaEntityPickerEntityFilterFunc,
|
|
||||||
excludeDevices?: string[],
|
|
||||||
value?: string,
|
|
||||||
idPrefix = ""
|
|
||||||
): DevicePickerItem[] => {
|
|
||||||
const devices = Object.values(hass.devices);
|
|
||||||
const entities = Object.values(hass.entities);
|
|
||||||
|
|
||||||
let deviceEntityLookup: DeviceEntityDisplayLookup = {};
|
|
||||||
|
|
||||||
if (
|
|
||||||
includeDomains ||
|
|
||||||
excludeDomains ||
|
|
||||||
includeDeviceClasses ||
|
|
||||||
entityFilter
|
|
||||||
) {
|
|
||||||
deviceEntityLookup = getDeviceEntityDisplayLookup(entities);
|
|
||||||
}
|
|
||||||
|
|
||||||
let inputDevices = devices.filter(
|
|
||||||
(device) => device.id === value || !device.disabled_by
|
|
||||||
);
|
|
||||||
|
|
||||||
if (includeDomains) {
|
|
||||||
inputDevices = inputDevices.filter((device) => {
|
|
||||||
const devEntities = deviceEntityLookup[device.id];
|
|
||||||
if (!devEntities || !devEntities.length) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return deviceEntityLookup[device.id].some((entity) =>
|
|
||||||
includeDomains.includes(computeDomain(entity.entity_id))
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (excludeDomains) {
|
|
||||||
inputDevices = inputDevices.filter((device) => {
|
|
||||||
const devEntities = deviceEntityLookup[device.id];
|
|
||||||
if (!devEntities || !devEntities.length) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return entities.every(
|
|
||||||
(entity) => !excludeDomains.includes(computeDomain(entity.entity_id))
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (excludeDevices) {
|
|
||||||
inputDevices = inputDevices.filter(
|
|
||||||
(device) => !excludeDevices!.includes(device.id)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (includeDeviceClasses) {
|
|
||||||
inputDevices = inputDevices.filter((device) => {
|
|
||||||
const devEntities = deviceEntityLookup[device.id];
|
|
||||||
if (!devEntities || !devEntities.length) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return deviceEntityLookup[device.id].some((entity) => {
|
|
||||||
const stateObj = hass.states[entity.entity_id];
|
|
||||||
if (!stateObj) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return (
|
|
||||||
stateObj.attributes.device_class &&
|
|
||||||
includeDeviceClasses.includes(stateObj.attributes.device_class)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entityFilter) {
|
|
||||||
inputDevices = inputDevices.filter((device) => {
|
|
||||||
const devEntities = deviceEntityLookup[device.id];
|
|
||||||
if (!devEntities || !devEntities.length) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return devEntities.some((entity) => {
|
|
||||||
const stateObj = hass.states[entity.entity_id];
|
|
||||||
if (!stateObj) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return entityFilter(stateObj);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deviceFilter) {
|
|
||||||
inputDevices = inputDevices.filter(
|
|
||||||
(device) =>
|
|
||||||
// We always want to include the device of the current value
|
|
||||||
device.id === value || deviceFilter!(device)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
const outputDevices = inputDevices.map<DevicePickerItem>((device) => {
|
|
||||||
const deviceName = computeDeviceNameDisplay(
|
|
||||||
device,
|
|
||||||
hass,
|
|
||||||
deviceEntityLookup[device.id]
|
|
||||||
);
|
|
||||||
|
|
||||||
const { area } = getDeviceContext(device, hass);
|
|
||||||
|
|
||||||
const areaName = area ? computeAreaName(area) : undefined;
|
|
||||||
|
|
||||||
const configEntry = device.primary_config_entry
|
|
||||||
? configEntryLookup?.[device.primary_config_entry]
|
|
||||||
: undefined;
|
|
||||||
|
|
||||||
const domain = configEntry?.domain;
|
|
||||||
const domainName = domain ? domainToName(hass.localize, domain) : undefined;
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: `${idPrefix}${device.id}`,
|
|
||||||
label: "",
|
|
||||||
primary:
|
|
||||||
deviceName ||
|
|
||||||
hass.localize("ui.components.device-picker.unnamed_device"),
|
|
||||||
secondary: areaName,
|
|
||||||
domain: configEntry?.domain,
|
|
||||||
domain_name: domainName,
|
|
||||||
search_labels: [deviceName, areaName, domain, domainName].filter(
|
|
||||||
Boolean
|
|
||||||
) as string[],
|
|
||||||
sorting_label: deviceName || "zzz",
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
return outputDevices;
|
|
||||||
};
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import type { HassEntity } from "home-assistant-js-websocket";
|
import type { HassEntity } from "home-assistant-js-websocket";
|
||||||
import { arrayLiteralIncludes } from "../common/array/literal-includes";
|
import { arrayLiteralIncludes } from "../../common/array/literal-includes";
|
||||||
|
|
||||||
export const UNAVAILABLE = "unavailable";
|
export const UNAVAILABLE = "unavailable";
|
||||||
export const UNKNOWN = "unknown";
|
export const UNKNOWN = "unknown";
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { formatDurationDigital } from "../common/datetime/format_duration";
|
import { formatDurationDigital } from "../../common/datetime/format_duration";
|
||||||
import type { FrontendLocaleData } from "./translation";
|
import type { FrontendLocaleData } from "../translation";
|
||||||
|
|
||||||
// These attributes are hidden from the more-info window for all entities.
|
// These attributes are hidden from the more-info window for all entities.
|
||||||
export const STATE_ATTRIBUTES = [
|
export const STATE_ATTRIBUTES = [
|
||||||
155
src/data/entity/entity_picker.ts
Normal file
155
src/data/entity/entity_picker.ts
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
import type { HassEntity } from "home-assistant-js-websocket";
|
||||||
|
import { computeDomain } from "../../common/entity/compute_domain";
|
||||||
|
import { computeEntityNameList } from "../../common/entity/compute_entity_name_display";
|
||||||
|
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||||
|
import { computeRTL } from "../../common/util/compute_rtl";
|
||||||
|
import type { PickerComboBoxItem } from "../../components/ha-picker-combo-box";
|
||||||
|
import type { FuseWeightedKey } from "../../resources/fuseMultiTerm";
|
||||||
|
import type { HomeAssistant } from "../../types";
|
||||||
|
import { domainToName } from "../integration";
|
||||||
|
import type { HaEntityPickerEntityFilterFunc } from "./entity";
|
||||||
|
|
||||||
|
export interface EntityComboBoxItem extends PickerComboBoxItem {
|
||||||
|
domain_name?: string;
|
||||||
|
stateObj?: HassEntity;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const entityComboBoxKeys: FuseWeightedKey[] = [
|
||||||
|
{
|
||||||
|
name: "search_labels.entityName",
|
||||||
|
weight: 10,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "search_labels.friendlyName",
|
||||||
|
weight: 8,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "search_labels.deviceName",
|
||||||
|
weight: 7,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "search_labels.areaName",
|
||||||
|
weight: 6,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "search_labels.domainName",
|
||||||
|
weight: 6,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "search_labels.entityId",
|
||||||
|
weight: 3,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
export const getEntities = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
includeDomains?: string[],
|
||||||
|
excludeDomains?: string[],
|
||||||
|
entityFilter?: HaEntityPickerEntityFilterFunc,
|
||||||
|
includeDeviceClasses?: string[],
|
||||||
|
includeUnitOfMeasurement?: string[],
|
||||||
|
includeEntities?: string[],
|
||||||
|
excludeEntities?: string[],
|
||||||
|
value?: string,
|
||||||
|
idPrefix = ""
|
||||||
|
): EntityComboBoxItem[] => {
|
||||||
|
let items: EntityComboBoxItem[] = [];
|
||||||
|
|
||||||
|
let entityIds = Object.keys(hass.states);
|
||||||
|
|
||||||
|
if (includeEntities) {
|
||||||
|
entityIds = entityIds.filter((entityId) =>
|
||||||
|
includeEntities.includes(entityId)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (excludeEntities) {
|
||||||
|
entityIds = entityIds.filter(
|
||||||
|
(entityId) => !excludeEntities.includes(entityId)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (includeDomains) {
|
||||||
|
entityIds = entityIds.filter((eid) =>
|
||||||
|
includeDomains.includes(computeDomain(eid))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (excludeDomains) {
|
||||||
|
entityIds = entityIds.filter(
|
||||||
|
(eid) => !excludeDomains.includes(computeDomain(eid))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
items = entityIds.map<EntityComboBoxItem>((entityId) => {
|
||||||
|
const stateObj = hass.states[entityId];
|
||||||
|
|
||||||
|
const friendlyName = computeStateName(stateObj); // Keep this for search
|
||||||
|
const [entityName, deviceName, areaName] = computeEntityNameList(
|
||||||
|
stateObj,
|
||||||
|
[{ type: "entity" }, { type: "device" }, { type: "area" }],
|
||||||
|
hass.entities,
|
||||||
|
hass.devices,
|
||||||
|
hass.areas,
|
||||||
|
hass.floors
|
||||||
|
);
|
||||||
|
|
||||||
|
const domainName = domainToName(hass.localize, computeDomain(entityId));
|
||||||
|
|
||||||
|
const isRTL = computeRTL(hass);
|
||||||
|
|
||||||
|
const primary = entityName || deviceName || entityId;
|
||||||
|
const secondary = [areaName, entityName ? deviceName : undefined]
|
||||||
|
.filter(Boolean)
|
||||||
|
.join(isRTL ? " ◂ " : " ▸ ");
|
||||||
|
|
||||||
|
return {
|
||||||
|
id: `${idPrefix}${entityId}`,
|
||||||
|
primary: primary,
|
||||||
|
secondary: secondary,
|
||||||
|
domain_name: domainName,
|
||||||
|
sorting_label: [primary, secondary].filter(Boolean).join("_"),
|
||||||
|
search_labels: {
|
||||||
|
entityName: entityName || null,
|
||||||
|
deviceName: deviceName || null,
|
||||||
|
areaName: areaName || null,
|
||||||
|
domainName: domainName || null,
|
||||||
|
friendlyName: friendlyName || null,
|
||||||
|
entityId: entityId,
|
||||||
|
},
|
||||||
|
stateObj: stateObj,
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
if (includeDeviceClasses) {
|
||||||
|
items = items.filter(
|
||||||
|
(item) =>
|
||||||
|
// We always want to include the entity of the current value
|
||||||
|
item.id === value ||
|
||||||
|
(item.stateObj?.attributes.device_class &&
|
||||||
|
includeDeviceClasses.includes(item.stateObj.attributes.device_class))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (includeUnitOfMeasurement) {
|
||||||
|
items = items.filter(
|
||||||
|
(item) =>
|
||||||
|
// We always want to include the entity of the current value
|
||||||
|
item.id === value ||
|
||||||
|
(item.stateObj?.attributes.unit_of_measurement &&
|
||||||
|
includeUnitOfMeasurement.includes(
|
||||||
|
item.stateObj.attributes.unit_of_measurement
|
||||||
|
))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (entityFilter) {
|
||||||
|
items = items.filter(
|
||||||
|
(item) =>
|
||||||
|
// We always want to include the entity of the current value
|
||||||
|
item.id === value || (item.stateObj && entityFilter!(item.stateObj))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return items;
|
||||||
|
};
|
||||||
@@ -1,19 +1,14 @@
|
|||||||
import type { Connection, HassEntity } from "home-assistant-js-websocket";
|
import type { Connection } from "home-assistant-js-websocket";
|
||||||
import { createCollection } from "home-assistant-js-websocket";
|
import { createCollection } from "home-assistant-js-websocket";
|
||||||
import type { Store } from "home-assistant-js-websocket/dist/store";
|
import type { Store } from "home-assistant-js-websocket/dist/store";
|
||||||
import memoizeOne from "memoize-one";
|
import memoizeOne from "memoize-one";
|
||||||
import { computeDomain } from "../common/entity/compute_domain";
|
import { computeDomain } from "../../common/entity/compute_domain";
|
||||||
import { computeEntityNameList } from "../common/entity/compute_entity_name_display";
|
import { computeStateName } from "../../common/entity/compute_state_name";
|
||||||
import { computeStateName } from "../common/entity/compute_state_name";
|
import { caseInsensitiveStringCompare } from "../../common/string/compare";
|
||||||
import { caseInsensitiveStringCompare } from "../common/string/compare";
|
import { debounce } from "../../common/util/debounce";
|
||||||
import { computeRTL } from "../common/util/compute_rtl";
|
import type { HomeAssistant } from "../../types";
|
||||||
import { debounce } from "../common/util/debounce";
|
import type { LightColor } from "../light";
|
||||||
import type { PickerComboBoxItem } from "../components/ha-picker-combo-box";
|
import type { RegistryEntry } from "../registry";
|
||||||
import type { HomeAssistant } from "../types";
|
|
||||||
import type { HaEntityPickerEntityFilterFunc } from "./entity";
|
|
||||||
import { domainToName } from "./integration";
|
|
||||||
import type { LightColor } from "./light";
|
|
||||||
import type { RegistryEntry } from "./registry";
|
|
||||||
|
|
||||||
type EntityCategory = "config" | "diagnostic";
|
type EntityCategory = "config" | "diagnostic";
|
||||||
|
|
||||||
@@ -329,121 +324,3 @@ export const getAutomaticEntityIds = (
|
|||||||
type: "config/entity_registry/get_automatic_entity_ids",
|
type: "config/entity_registry/get_automatic_entity_ids",
|
||||||
entity_ids,
|
entity_ids,
|
||||||
});
|
});
|
||||||
|
|
||||||
export interface EntityComboBoxItem extends PickerComboBoxItem {
|
|
||||||
domain_name?: string;
|
|
||||||
stateObj?: HassEntity;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const getEntities = (
|
|
||||||
hass: HomeAssistant,
|
|
||||||
includeDomains?: string[],
|
|
||||||
excludeDomains?: string[],
|
|
||||||
entityFilter?: HaEntityPickerEntityFilterFunc,
|
|
||||||
includeDeviceClasses?: string[],
|
|
||||||
includeUnitOfMeasurement?: string[],
|
|
||||||
includeEntities?: string[],
|
|
||||||
excludeEntities?: string[],
|
|
||||||
value?: string,
|
|
||||||
idPrefix = ""
|
|
||||||
): EntityComboBoxItem[] => {
|
|
||||||
let items: EntityComboBoxItem[] = [];
|
|
||||||
|
|
||||||
let entityIds = Object.keys(hass.states);
|
|
||||||
|
|
||||||
if (includeEntities) {
|
|
||||||
entityIds = entityIds.filter((entityId) =>
|
|
||||||
includeEntities.includes(entityId)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (excludeEntities) {
|
|
||||||
entityIds = entityIds.filter(
|
|
||||||
(entityId) => !excludeEntities.includes(entityId)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (includeDomains) {
|
|
||||||
entityIds = entityIds.filter((eid) =>
|
|
||||||
includeDomains.includes(computeDomain(eid))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (excludeDomains) {
|
|
||||||
entityIds = entityIds.filter(
|
|
||||||
(eid) => !excludeDomains.includes(computeDomain(eid))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
items = entityIds.map<EntityComboBoxItem>((entityId) => {
|
|
||||||
const stateObj = hass.states[entityId];
|
|
||||||
|
|
||||||
const friendlyName = computeStateName(stateObj); // Keep this for search
|
|
||||||
const [entityName, deviceName, areaName] = computeEntityNameList(
|
|
||||||
stateObj,
|
|
||||||
[{ type: "entity" }, { type: "device" }, { type: "area" }],
|
|
||||||
hass.entities,
|
|
||||||
hass.devices,
|
|
||||||
hass.areas,
|
|
||||||
hass.floors
|
|
||||||
);
|
|
||||||
|
|
||||||
const domainName = domainToName(hass.localize, computeDomain(entityId));
|
|
||||||
|
|
||||||
const isRTL = computeRTL(hass);
|
|
||||||
|
|
||||||
const primary = entityName || deviceName || entityId;
|
|
||||||
const secondary = [areaName, entityName ? deviceName : undefined]
|
|
||||||
.filter(Boolean)
|
|
||||||
.join(isRTL ? " ◂ " : " ▸ ");
|
|
||||||
|
|
||||||
return {
|
|
||||||
id: `${idPrefix}${entityId}`,
|
|
||||||
primary: primary,
|
|
||||||
secondary: secondary,
|
|
||||||
domain_name: domainName,
|
|
||||||
sorting_label: [deviceName, entityName].filter(Boolean).join("_"),
|
|
||||||
search_labels: [
|
|
||||||
entityName,
|
|
||||||
deviceName,
|
|
||||||
areaName,
|
|
||||||
domainName,
|
|
||||||
friendlyName,
|
|
||||||
entityId,
|
|
||||||
].filter(Boolean) as string[],
|
|
||||||
stateObj: stateObj,
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
if (includeDeviceClasses) {
|
|
||||||
items = items.filter(
|
|
||||||
(item) =>
|
|
||||||
// We always want to include the entity of the current value
|
|
||||||
item.id === value ||
|
|
||||||
(item.stateObj?.attributes.device_class &&
|
|
||||||
includeDeviceClasses.includes(item.stateObj.attributes.device_class))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (includeUnitOfMeasurement) {
|
|
||||||
items = items.filter(
|
|
||||||
(item) =>
|
|
||||||
// We always want to include the entity of the current value
|
|
||||||
item.id === value ||
|
|
||||||
(item.stateObj?.attributes.unit_of_measurement &&
|
|
||||||
includeUnitOfMeasurement.includes(
|
|
||||||
item.stateObj.attributes.unit_of_measurement
|
|
||||||
))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (entityFilter) {
|
|
||||||
items = items.filter(
|
|
||||||
(item) =>
|
|
||||||
// We always want to include the entity of the current value
|
|
||||||
item.id === value || (item.stateObj && entityFilter!(item.stateObj))
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return items;
|
|
||||||
};
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
import { timeCachePromiseFunc } from "../common/util/time-cache-function-promise";
|
import { timeCachePromiseFunc } from "../../common/util/time-cache-function-promise";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../../types";
|
||||||
|
|
||||||
interface EntitySource {
|
interface EntitySource {
|
||||||
domain: string;
|
domain: string;
|
||||||
@@ -56,11 +56,11 @@ import type { HomeAssistant } from "../types";
|
|||||||
import type {
|
import type {
|
||||||
EntityRegistryDisplayEntry,
|
EntityRegistryDisplayEntry,
|
||||||
EntityRegistryEntry,
|
EntityRegistryEntry,
|
||||||
} from "./entity_registry";
|
} from "./entity/entity_registry";
|
||||||
|
|
||||||
import { mdiHomeAssistant } from "../resources/home-assistant-logo-svg";
|
import { mdiHomeAssistant } from "../resources/home-assistant-logo-svg";
|
||||||
import { getTriggerDomain, getTriggerObjectId } from "./trigger";
|
|
||||||
import { getConditionDomain, getConditionObjectId } from "./condition";
|
import { getConditionDomain, getConditionObjectId } from "./condition";
|
||||||
|
import { getTriggerDomain, getTriggerObjectId } from "./trigger";
|
||||||
|
|
||||||
/** Icon to use when no icon specified for service. */
|
/** Icon to use when no icon specified for service. */
|
||||||
export const DEFAULT_SERVICE_ICON = mdiRoomService;
|
export const DEFAULT_SERVICE_ICON = mdiRoomService;
|
||||||
|
|||||||
@@ -1,104 +1,32 @@
|
|||||||
import { mdiLabel } from "@mdi/js";
|
import { mdiLabel } from "@mdi/js";
|
||||||
import type { Connection } from "home-assistant-js-websocket";
|
import { computeDomain } from "../../common/entity/compute_domain";
|
||||||
import { createCollection } from "home-assistant-js-websocket";
|
import type { HaDevicePickerDeviceFilterFunc } from "../../components/device/ha-device-picker";
|
||||||
import type { Store } from "home-assistant-js-websocket/dist/store";
|
import type { PickerComboBoxItem } from "../../components/ha-picker-combo-box";
|
||||||
import { computeDomain } from "../common/entity/compute_domain";
|
import type { FuseWeightedKey } from "../../resources/fuseMultiTerm";
|
||||||
import { stringCompare } from "../common/string/compare";
|
import type { HomeAssistant } from "../../types";
|
||||||
import { debounce } from "../common/util/debounce";
|
|
||||||
import type { HaDevicePickerDeviceFilterFunc } from "../components/device/ha-device-picker";
|
|
||||||
import type { PickerComboBoxItem } from "../components/ha-picker-combo-box";
|
|
||||||
import type { HomeAssistant } from "../types";
|
|
||||||
import {
|
import {
|
||||||
getDeviceEntityDisplayLookup,
|
getDeviceEntityDisplayLookup,
|
||||||
type DeviceEntityDisplayLookup,
|
type DeviceEntityDisplayLookup,
|
||||||
type DeviceRegistryEntry,
|
type DeviceRegistryEntry,
|
||||||
} from "./device_registry";
|
} from "../device/device_registry";
|
||||||
import type { HaEntityPickerEntityFilterFunc } from "./entity";
|
import type { HaEntityPickerEntityFilterFunc } from "../entity/entity";
|
||||||
import type { EntityRegistryDisplayEntry } from "./entity_registry";
|
import type { EntityRegistryDisplayEntry } from "../entity/entity_registry";
|
||||||
import type { RegistryEntry } from "./registry";
|
import type { LabelRegistryEntry } from "./label_registry";
|
||||||
|
|
||||||
export interface LabelRegistryEntry extends RegistryEntry {
|
export const labelComboBoxKeys: FuseWeightedKey[] = [
|
||||||
label_id: string;
|
{
|
||||||
name: string;
|
name: "search_labels.name",
|
||||||
icon: string | null;
|
weight: 10,
|
||||||
color: string | null;
|
},
|
||||||
description: string | null;
|
{
|
||||||
}
|
name: "search_labels.description",
|
||||||
|
weight: 5,
|
||||||
export interface LabelRegistryEntryMutableParams {
|
},
|
||||||
name: string;
|
{
|
||||||
icon?: string | null;
|
name: "search_labels.id",
|
||||||
color?: string | null;
|
weight: 4,
|
||||||
description?: string | null;
|
},
|
||||||
}
|
];
|
||||||
|
|
||||||
export const fetchLabelRegistry = (conn: Connection) =>
|
|
||||||
conn
|
|
||||||
.sendMessagePromise({
|
|
||||||
type: "config/label_registry/list",
|
|
||||||
})
|
|
||||||
.then((labels) =>
|
|
||||||
(labels as LabelRegistryEntry[]).sort((ent1, ent2) =>
|
|
||||||
stringCompare(ent1.name, ent2.name)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
export const subscribeLabelRegistryUpdates = (
|
|
||||||
conn: Connection,
|
|
||||||
store: Store<LabelRegistryEntry[]>
|
|
||||||
) =>
|
|
||||||
conn.subscribeEvents(
|
|
||||||
debounce(
|
|
||||||
() =>
|
|
||||||
fetchLabelRegistry(conn).then((labels: LabelRegistryEntry[]) =>
|
|
||||||
store.setState(labels, true)
|
|
||||||
),
|
|
||||||
500,
|
|
||||||
true
|
|
||||||
),
|
|
||||||
"label_registry_updated"
|
|
||||||
);
|
|
||||||
|
|
||||||
export const subscribeLabelRegistry = (
|
|
||||||
conn: Connection,
|
|
||||||
onChange: (labels: LabelRegistryEntry[]) => void
|
|
||||||
) =>
|
|
||||||
createCollection<LabelRegistryEntry[]>(
|
|
||||||
"_labelRegistry",
|
|
||||||
fetchLabelRegistry,
|
|
||||||
subscribeLabelRegistryUpdates,
|
|
||||||
conn,
|
|
||||||
onChange
|
|
||||||
);
|
|
||||||
|
|
||||||
export const createLabelRegistryEntry = (
|
|
||||||
hass: HomeAssistant,
|
|
||||||
values: LabelRegistryEntryMutableParams
|
|
||||||
) =>
|
|
||||||
hass.callWS<LabelRegistryEntry>({
|
|
||||||
type: "config/label_registry/create",
|
|
||||||
...values,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const updateLabelRegistryEntry = (
|
|
||||||
hass: HomeAssistant,
|
|
||||||
labelId: string,
|
|
||||||
updates: Partial<LabelRegistryEntryMutableParams>
|
|
||||||
) =>
|
|
||||||
hass.callWS<LabelRegistryEntry>({
|
|
||||||
type: "config/label_registry/update",
|
|
||||||
label_id: labelId,
|
|
||||||
...updates,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const deleteLabelRegistryEntry = (
|
|
||||||
hass: HomeAssistant,
|
|
||||||
labelId: string
|
|
||||||
) =>
|
|
||||||
hass.callWS({
|
|
||||||
type: "config/label_registry/delete",
|
|
||||||
label_id: labelId,
|
|
||||||
});
|
|
||||||
|
|
||||||
export const getLabels = (
|
export const getLabels = (
|
||||||
hassStates: HomeAssistant["states"],
|
hassStates: HomeAssistant["states"],
|
||||||
@@ -273,9 +201,11 @@ export const getLabels = (
|
|||||||
icon: label.icon || undefined,
|
icon: label.icon || undefined,
|
||||||
icon_path: label.icon ? undefined : mdiLabel,
|
icon_path: label.icon ? undefined : mdiLabel,
|
||||||
sorting_label: label.name,
|
sorting_label: label.name,
|
||||||
search_labels: [label.name, label.label_id, label.description].filter(
|
search_labels: {
|
||||||
(v): v is string => Boolean(v)
|
name: label.name,
|
||||||
),
|
description: label.description,
|
||||||
|
id: label.label_id,
|
||||||
|
},
|
||||||
}));
|
}));
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
90
src/data/label/label_registry.ts
Normal file
90
src/data/label/label_registry.ts
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
import type { Connection } from "home-assistant-js-websocket";
|
||||||
|
import { createCollection } from "home-assistant-js-websocket";
|
||||||
|
import type { Store } from "home-assistant-js-websocket/dist/store";
|
||||||
|
import { stringCompare } from "../../common/string/compare";
|
||||||
|
import { debounce } from "../../common/util/debounce";
|
||||||
|
import type { HomeAssistant } from "../../types";
|
||||||
|
import type { RegistryEntry } from "../registry";
|
||||||
|
|
||||||
|
export interface LabelRegistryEntry extends RegistryEntry {
|
||||||
|
label_id: string;
|
||||||
|
name: string;
|
||||||
|
icon: string | null;
|
||||||
|
color: string | null;
|
||||||
|
description: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface LabelRegistryEntryMutableParams {
|
||||||
|
name: string;
|
||||||
|
icon?: string | null;
|
||||||
|
color?: string | null;
|
||||||
|
description?: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const fetchLabelRegistry = (conn: Connection) =>
|
||||||
|
conn
|
||||||
|
.sendMessagePromise({
|
||||||
|
type: "config/label_registry/list",
|
||||||
|
})
|
||||||
|
.then((labels) =>
|
||||||
|
(labels as LabelRegistryEntry[]).sort((ent1, ent2) =>
|
||||||
|
stringCompare(ent1.name, ent2.name)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
export const subscribeLabelRegistryUpdates = (
|
||||||
|
conn: Connection,
|
||||||
|
store: Store<LabelRegistryEntry[]>
|
||||||
|
) =>
|
||||||
|
conn.subscribeEvents(
|
||||||
|
debounce(
|
||||||
|
() =>
|
||||||
|
fetchLabelRegistry(conn).then((labels: LabelRegistryEntry[]) =>
|
||||||
|
store.setState(labels, true)
|
||||||
|
),
|
||||||
|
500,
|
||||||
|
true
|
||||||
|
),
|
||||||
|
"label_registry_updated"
|
||||||
|
);
|
||||||
|
|
||||||
|
export const subscribeLabelRegistry = (
|
||||||
|
conn: Connection,
|
||||||
|
onChange: (labels: LabelRegistryEntry[]) => void
|
||||||
|
) =>
|
||||||
|
createCollection<LabelRegistryEntry[]>(
|
||||||
|
"_labelRegistry",
|
||||||
|
fetchLabelRegistry,
|
||||||
|
subscribeLabelRegistryUpdates,
|
||||||
|
conn,
|
||||||
|
onChange
|
||||||
|
);
|
||||||
|
|
||||||
|
export const createLabelRegistryEntry = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
values: LabelRegistryEntryMutableParams
|
||||||
|
) =>
|
||||||
|
hass.callWS<LabelRegistryEntry>({
|
||||||
|
type: "config/label_registry/create",
|
||||||
|
...values,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const updateLabelRegistryEntry = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
labelId: string,
|
||||||
|
updates: Partial<LabelRegistryEntryMutableParams>
|
||||||
|
) =>
|
||||||
|
hass.callWS<LabelRegistryEntry>({
|
||||||
|
type: "config/label_registry/update",
|
||||||
|
label_id: labelId,
|
||||||
|
...updates,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const deleteLabelRegistryEntry = (
|
||||||
|
hass: HomeAssistant,
|
||||||
|
labelId: string
|
||||||
|
) =>
|
||||||
|
hass.callWS({
|
||||||
|
type: "config/label_registry/delete",
|
||||||
|
label_id: labelId,
|
||||||
|
});
|
||||||
@@ -2,7 +2,7 @@ import type {
|
|||||||
HassEntityAttributeBase,
|
HassEntityAttributeBase,
|
||||||
HassEntityBase,
|
HassEntityBase,
|
||||||
} from "home-assistant-js-websocket";
|
} from "home-assistant-js-websocket";
|
||||||
import { UNAVAILABLE } from "./entity";
|
import { UNAVAILABLE } from "./entity/entity";
|
||||||
|
|
||||||
export type LawnMowerEntityState =
|
export type LawnMowerEntityState =
|
||||||
| "paused"
|
| "paused"
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ import type {
|
|||||||
HassEntityAttributeBase,
|
HassEntityAttributeBase,
|
||||||
HassEntityBase,
|
HassEntityBase,
|
||||||
} from "home-assistant-js-websocket";
|
} from "home-assistant-js-websocket";
|
||||||
import { getExtendedEntityRegistryEntry } from "./entity_registry";
|
|
||||||
import { showEnterCodeDialog } from "../dialogs/enter-code/show-enter-code-dialog";
|
import { showEnterCodeDialog } from "../dialogs/enter-code/show-enter-code-dialog";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
import { UNAVAILABLE } from "./entity";
|
import { UNAVAILABLE } from "./entity/entity";
|
||||||
|
import { getExtendedEntityRegistryEntry } from "./entity/entity_registry";
|
||||||
|
|
||||||
export const enum LockEntityFeature {
|
export const enum LockEntityFeature {
|
||||||
OPEN = 1,
|
OPEN = 1,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ import { computeStateDomain } from "../common/entity/compute_state_domain";
|
|||||||
import { autoCaseNoun } from "../common/translations/auto_case_noun";
|
import { autoCaseNoun } from "../common/translations/auto_case_noun";
|
||||||
import type { LocalizeFunc } from "../common/translations/localize";
|
import type { LocalizeFunc } from "../common/translations/localize";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
import { UNAVAILABLE, UNKNOWN } from "./entity";
|
import { UNAVAILABLE, UNKNOWN } from "./entity/entity";
|
||||||
import { isNumericEntity } from "./history";
|
import { isNumericEntity } from "./history";
|
||||||
|
|
||||||
const LOGBOOK_LOCALIZE_PATH = "ui.components.logbook.messages";
|
const LOGBOOK_LOCALIZE_PATH = "ui.components.logbook.messages";
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
|
import type { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||||
|
import { isComponentLoaded } from "../common/config/is_component_loaded";
|
||||||
import { navigate } from "../common/navigate";
|
import { navigate } from "../common/navigate";
|
||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
import { subscribeDeviceRegistry } from "./device_registry";
|
import { subscribeDeviceRegistry } from "./device/device_registry";
|
||||||
import { isComponentLoaded } from "../common/config/is_component_loaded";
|
|
||||||
import { getThreadDataSetTLV, listThreadDataSets } from "./thread";
|
import { getThreadDataSetTLV, listThreadDataSets } from "./thread";
|
||||||
|
|
||||||
export enum NetworkType {
|
export enum NetworkType {
|
||||||
|
|||||||
@@ -32,11 +32,11 @@ import type {
|
|||||||
HassEntityAttributeBase,
|
HassEntityAttributeBase,
|
||||||
HassEntityBase,
|
HassEntityBase,
|
||||||
} from "home-assistant-js-websocket";
|
} from "home-assistant-js-websocket";
|
||||||
import { supportsFeature } from "../common/entity/supports-feature";
|
|
||||||
import { stateActive } from "../common/entity/state_active";
|
import { stateActive } from "../common/entity/state_active";
|
||||||
|
import { supportsFeature } from "../common/entity/supports-feature";
|
||||||
import type { MediaPlayerItemId } from "../components/media-player/ha-media-player-browse";
|
import type { MediaPlayerItemId } from "../components/media-player/ha-media-player-browse";
|
||||||
import type { HomeAssistant, TranslationDict } from "../types";
|
import type { HomeAssistant, TranslationDict } from "../types";
|
||||||
import { isUnavailableState } from "./entity";
|
import { isUnavailableState } from "./entity/entity";
|
||||||
import { isTTSMediaSource } from "./tts";
|
import { isTTSMediaSource } from "./tts";
|
||||||
|
|
||||||
interface MediaPlayerEntityAttributes extends HassEntityAttributeBase {
|
interface MediaPlayerEntityAttributes extends HassEntityAttributeBase {
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { html, nothing } from "lit";
|
import { html, nothing } from "lit";
|
||||||
|
import "../components/ha-expansion-panel";
|
||||||
import {
|
import {
|
||||||
showAlertDialog,
|
showAlertDialog,
|
||||||
showConfirmationDialog,
|
showConfirmationDialog,
|
||||||
@@ -7,8 +8,7 @@ import type { HomeAssistant } from "../types";
|
|||||||
import {
|
import {
|
||||||
getAutomaticEntityIds,
|
getAutomaticEntityIds,
|
||||||
updateEntityRegistryEntry,
|
updateEntityRegistryEntry,
|
||||||
} from "./entity_registry";
|
} from "./entity/entity_registry";
|
||||||
import "../components/ha-expansion-panel";
|
|
||||||
|
|
||||||
export const regenerateEntityIds = async (
|
export const regenerateEntityIds = async (
|
||||||
element: HTMLElement,
|
element: HTMLElement,
|
||||||
|
|||||||
@@ -8,15 +8,15 @@ import { isTemplate } from "../common/string/has-template";
|
|||||||
import type { HomeAssistant } from "../types";
|
import type { HomeAssistant } from "../types";
|
||||||
import type { Condition } from "./automation";
|
import type { Condition } from "./automation";
|
||||||
import { describeCondition } from "./automation_i18n";
|
import { describeCondition } from "./automation_i18n";
|
||||||
import { localizeDeviceAutomationAction } from "./device_automation";
|
import { localizeDeviceAutomationAction } from "./device/device_automation";
|
||||||
import type { EntityRegistryEntry } from "./entity_registry";
|
import type { EntityRegistryEntry } from "./entity/entity_registry";
|
||||||
import {
|
import {
|
||||||
computeEntityRegistryName,
|
computeEntityRegistryName,
|
||||||
entityRegistryById,
|
entityRegistryById,
|
||||||
} from "./entity_registry";
|
} from "./entity/entity_registry";
|
||||||
import type { FloorRegistryEntry } from "./floor_registry";
|
import type { FloorRegistryEntry } from "./floor_registry";
|
||||||
import { domainToName } from "./integration";
|
import { domainToName } from "./integration";
|
||||||
import type { LabelRegistryEntry } from "./label_registry";
|
import type { LabelRegistryEntry } from "./label/label_registry";
|
||||||
import type {
|
import type {
|
||||||
ActionType,
|
ActionType,
|
||||||
ActionTypes,
|
ActionTypes,
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user