mirror of
https://github.com/home-assistant/frontend.git
synced 2026-12-01 09:09:11 +00:00
Compare commits
13
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
57d73d236f | ||
|
|
336259f6d2 | ||
|
|
1882e154fe | ||
|
|
baa067caf0 | ||
|
|
07b5d9e98c | ||
|
|
f2b2c92bdd | ||
|
|
33ef19dac1 | ||
|
|
1e797c345c | ||
|
|
9083641ae7 | ||
|
|
5fc4ad4e0c | ||
|
|
ba33d2897b | ||
|
|
9484d51694 | ||
|
|
55739f2666 |
No files matched your search
+5
-5
@@ -40,7 +40,7 @@
|
||||
"license": "Apache-2.0",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "8.1.3",
|
||||
"@babel/runtime": "8.1.4",
|
||||
"@braintree/sanitize-url": "7.1.2",
|
||||
"@codemirror/autocomplete": "6.20.4",
|
||||
"@codemirror/commands": "6.11.2",
|
||||
@@ -136,13 +136,13 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@ampproject/remapping": "2.3.0",
|
||||
"@babel/core": "8.1.3",
|
||||
"@babel/core": "8.1.4",
|
||||
"@babel/helper-compilation-targets": "8.0.7",
|
||||
"@babel/helper-define-polyfill-provider": "1.0.0",
|
||||
"@babel/plugin-transform-class-properties": "8.0.1",
|
||||
"@babel/plugin-transform-private-methods": "8.0.1",
|
||||
"@babel/plugin-transform-runtime": "8.1.2",
|
||||
"@babel/preset-env": "8.0.7",
|
||||
"@babel/preset-env": "8.1.4",
|
||||
"@bundle-stats/plugin-webpack-filter": "4.23.1",
|
||||
"@eslint/js": "10.0.1",
|
||||
"@gfx/zopfli": "1.0.15",
|
||||
@@ -177,7 +177,7 @@
|
||||
"browserslist-useragent-regexp": "4.1.4",
|
||||
"core-js-compat": "3.51.0",
|
||||
"del": "9.0.1",
|
||||
"eslint": "10.15.0",
|
||||
"eslint": "10.16.0",
|
||||
"eslint-config-prettier": "10.1.9",
|
||||
"eslint-import-resolver-webpack": "0.13.11",
|
||||
"eslint-plugin-import-x": "4.18.1",
|
||||
@@ -222,7 +222,7 @@
|
||||
"webpackbar": "7.0.0",
|
||||
"workbox-build": "7.4.1"
|
||||
},
|
||||
"packageManager": "[email protected]3.0",
|
||||
"packageManager": "[email protected]4.0",
|
||||
"volta": {
|
||||
"node": "24.22.3"
|
||||
}
|
||||
|
||||
Generated
+521
-526
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,74 @@
|
||||
import type { ReactiveControllerHost } from "@lit/reactive-element/reactive-controller";
|
||||
import type {
|
||||
ConditionContext,
|
||||
VisibilityCondition,
|
||||
} from "../../panels/lovelace/common/validate-condition";
|
||||
import { addEntityToCondition } from "../../panels/lovelace/common/validate-condition";
|
||||
import type { HomeAssistant } from "../../types";
|
||||
import type { ConditionEvaluation } from "../controllers/condition-evaluator-controller";
|
||||
import { ConditionEvaluatorController } from "../controllers/condition-evaluator-controller";
|
||||
import { dropInvalidConditions } from "./sanitize";
|
||||
|
||||
export interface VisibilitySubscription {
|
||||
/** Pass each new hass object so client-side conditions check again. */
|
||||
update(hass: HomeAssistant): void;
|
||||
/** Close the subscriptions. `onChange` is not called again. */
|
||||
unsubscribe(): void;
|
||||
}
|
||||
|
||||
/**
|
||||
* Live visibility of a list of dashboard visibility conditions, for code
|
||||
* without a Lit host, such as custom cards and plugins. Conditions core
|
||||
* evaluates are subscribed to; the rest are checked locally. Reports
|
||||
* `unknown` until core replies.
|
||||
*/
|
||||
export const subscribeVisibility = (
|
||||
hass: HomeAssistant,
|
||||
conditions: VisibilityCondition[],
|
||||
onChange: (result: ConditionEvaluation, error?: string) => void,
|
||||
context: ConditionContext = {}
|
||||
): VisibilitySubscription => {
|
||||
// The controller only needs a host to register with and to re-render.
|
||||
const host: ReactiveControllerHost = {
|
||||
addController: () => undefined,
|
||||
removeController: () => undefined,
|
||||
requestUpdate: () => undefined,
|
||||
updateComplete: Promise.resolve(true),
|
||||
};
|
||||
|
||||
let active = true;
|
||||
|
||||
const controller = new ConditionEvaluatorController(host, {
|
||||
resubscribeDelay: 0,
|
||||
onResult: (result, error) => {
|
||||
if (active) {
|
||||
onChange(result, error);
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
const sanitized = dropInvalidConditions(conditions);
|
||||
const { entity_id: entityId } = context;
|
||||
|
||||
// Core-evaluated conditions never see the context, so fold its entity in
|
||||
// first, as the dashboard mixin does.
|
||||
const validConditions = entityId
|
||||
? sanitized.map((condition) => addEntityToCondition(condition, entityId))
|
||||
: sanitized;
|
||||
const getContext = () => context;
|
||||
|
||||
controller.hostConnected();
|
||||
controller.observe(validConditions, hass, getContext);
|
||||
|
||||
return {
|
||||
update: (newHass) => {
|
||||
if (active) {
|
||||
controller.observe(validConditions, newHass, getContext);
|
||||
}
|
||||
},
|
||||
unsubscribe: () => {
|
||||
active = false;
|
||||
controller.hostDisconnected();
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -1939,6 +1939,10 @@ export class HaCodeEditor extends ReactiveElement {
|
||||
padding-top: var(--code-editor-toolbar-height);
|
||||
}
|
||||
|
||||
:host(.fullscreen) {
|
||||
--code-mirror-min-height: 100%;
|
||||
}
|
||||
|
||||
:host(.fullscreen) .cm-editor {
|
||||
height: 100% !important;
|
||||
max-height: 100% !important;
|
||||
|
||||
@@ -73,6 +73,15 @@ export class HaDropdown extends Dropdown {
|
||||
// @ts-ignore
|
||||
// eslint-disable-next-line @typescript-eslint/naming-convention
|
||||
private override async showMenu() {
|
||||
// Flip away from the safe areas instead of opening into them, where the
|
||||
// max-height below would squeeze the menu.
|
||||
const styles = getComputedStyle(this);
|
||||
// @ts-ignore flipPadding is typed as a number, floating-ui accepts sides
|
||||
this.popup.flipPadding = {
|
||||
top: parseFloat(styles.getPropertyValue("--safe-area-inset-top")) || 0,
|
||||
bottom:
|
||||
parseFloat(styles.getPropertyValue("--safe-area-inset-bottom")) || 0,
|
||||
};
|
||||
// @ts-ignore
|
||||
await super.showMenu();
|
||||
const triggerElement = this.getTrigger();
|
||||
|
||||
@@ -23,6 +23,7 @@ import {
|
||||
getPanelIcon,
|
||||
getPanelIconPath,
|
||||
getPanelTitle,
|
||||
getSelectedPanelUrlPath,
|
||||
} from "../data/panel";
|
||||
import type { PersistentNotification } from "../data/persistent_notification";
|
||||
import { subscribeNotifications } from "../data/persistent_notification";
|
||||
@@ -231,12 +232,36 @@ class HaSidebar extends SubscribeMixin(ScrollableFadeMixin(LitElement)) {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
const selectedPanel = this.hass.panelUrl;
|
||||
|
||||
// prettier-ignore
|
||||
return html`
|
||||
${this._renderHeader()}
|
||||
${this._renderAllPanels(selectedPanel)}`;
|
||||
${this._renderAllPanels()}`;
|
||||
}
|
||||
|
||||
private _computeSidebarPanels(): [PanelInfo[], PanelInfo[]] | undefined {
|
||||
if (!this._panelOrder || !this._hiddenPanels) {
|
||||
return undefined;
|
||||
}
|
||||
return computePanels(
|
||||
this.hass.panels,
|
||||
getDefaultPanelUrlPath(this.hass),
|
||||
this._panelOrder,
|
||||
this._hiddenPanels,
|
||||
this.hass.locale
|
||||
);
|
||||
}
|
||||
|
||||
private _computeSelectedPanel(
|
||||
sidebarPanels: [PanelInfo[], PanelInfo[]] | undefined,
|
||||
route: Route | undefined
|
||||
): string {
|
||||
if (!route) {
|
||||
return this.hass.panelUrl;
|
||||
}
|
||||
const urlPaths = (sidebarPanels ?? [[], []])
|
||||
.flat()
|
||||
.map((panel) => panel.url_path);
|
||||
return getSelectedPanelUrlPath(urlPaths, route.path);
|
||||
}
|
||||
|
||||
protected shouldUpdate(changedProps: PropertyValues): boolean {
|
||||
@@ -254,7 +279,20 @@ class HaSidebar extends SubscribeMixin(ScrollableFadeMixin(LitElement)) {
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
if (!this.hass || !changedProps.has("hass")) {
|
||||
if (!this.hass) {
|
||||
return false;
|
||||
}
|
||||
if (changedProps.has("route")) {
|
||||
const sidebarPanels = this._computeSidebarPanels();
|
||||
const oldRoute = changedProps.get("route") as Route | undefined;
|
||||
if (
|
||||
this._computeSelectedPanel(sidebarPanels, oldRoute) !==
|
||||
this._computeSelectedPanel(sidebarPanels, this.route)
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (!changedProps.has("hass")) {
|
||||
return false;
|
||||
}
|
||||
const oldHass = changedProps.get("hass") as HomeAssistant;
|
||||
@@ -355,7 +393,9 @@ class HaSidebar extends SubscribeMixin(ScrollableFadeMixin(LitElement)) {
|
||||
</div>`;
|
||||
}
|
||||
|
||||
private _renderAllPanels(selectedPanel: string) {
|
||||
private _renderAllPanels() {
|
||||
const sidebarPanels = this._computeSidebarPanels();
|
||||
const selectedPanel = this._computeSelectedPanel(sidebarPanels, this.route);
|
||||
const renderList = (content, cls: string, scrollable: boolean) =>
|
||||
html`<ha-list-nav
|
||||
class=${classMap({
|
||||
@@ -365,7 +405,7 @@ class HaSidebar extends SubscribeMixin(ScrollableFadeMixin(LitElement)) {
|
||||
>${content}</ha-list-nav
|
||||
>`;
|
||||
|
||||
if (!this._panelOrder || !this._hiddenPanels) {
|
||||
if (!sidebarPanels) {
|
||||
return html`<div class="panels-list">
|
||||
<div class="wrapper">
|
||||
${renderList(
|
||||
@@ -390,15 +430,7 @@ class HaSidebar extends SubscribeMixin(ScrollableFadeMixin(LitElement)) {
|
||||
</div>`;
|
||||
}
|
||||
|
||||
const defaultPanel = getDefaultPanelUrlPath(this.hass);
|
||||
|
||||
const [beforeSpacer, afterSpacer] = computePanels(
|
||||
this.hass.panels,
|
||||
defaultPanel,
|
||||
this._panelOrder,
|
||||
this._hiddenPanels,
|
||||
this.hass.locale
|
||||
);
|
||||
const [beforeSpacer, afterSpacer] = sidebarPanels;
|
||||
|
||||
// prettier-ignore
|
||||
return html`<div class="panels-list">
|
||||
|
||||
@@ -196,6 +196,21 @@ export const getPanelIconPath = (panel: PanelInfo): string | undefined => {
|
||||
|
||||
export const FIXED_PANELS = [PROFILE_PANEL, "config", NOT_FOUND_PANEL];
|
||||
|
||||
// A panel's url_path can span several segments (e.g. "config/logs"), so the
|
||||
// most specific url_path matching the path wins over its first segment.
|
||||
export const getSelectedPanelUrlPath = (
|
||||
urlPaths: string[],
|
||||
path: string
|
||||
): string =>
|
||||
urlPaths.reduce(
|
||||
(selected, urlPath) =>
|
||||
urlPath.length > selected.length &&
|
||||
(path === `/${urlPath}` || path.startsWith(`/${urlPath}/`))
|
||||
? urlPath
|
||||
: selected,
|
||||
path.split("/")[1] ?? ""
|
||||
);
|
||||
|
||||
export interface PanelMutableParams {
|
||||
title?: string | null;
|
||||
icon?: string | null;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import type { ContextType } from "@lit/context";
|
||||
import type { HassConfig, UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import { ERR_CONNECTION_LOST } from "home-assistant-js-websocket";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
@@ -456,6 +457,11 @@ class MoreInfoUpdate extends LitElement {
|
||||
false
|
||||
);
|
||||
} catch (err: any) {
|
||||
// The update keeps running when the connection drops during a long install.
|
||||
if (err?.error?.code === ERR_CONNECTION_LOST) {
|
||||
return;
|
||||
}
|
||||
|
||||
const message = await this._localizeInstallError(err);
|
||||
|
||||
if (this._isShown()) {
|
||||
|
||||
@@ -620,15 +620,14 @@ class MoreInfoWeather extends LitElement {
|
||||
}
|
||||
|
||||
.temp-attribute .temp {
|
||||
position: relative;
|
||||
margin-right: var(--ha-space-6);
|
||||
direction: ltr;
|
||||
}
|
||||
|
||||
.temp-attribute .temp span {
|
||||
position: absolute;
|
||||
position: relative;
|
||||
font-size: var(--ha-font-size-2xl);
|
||||
top: 1px;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.state,
|
||||
|
||||
@@ -2,4 +2,10 @@ import "@webcomponents/scoped-custom-element-registry/scoped-custom-element-regi
|
||||
import "../resources/scoped-registry-ready";
|
||||
import "../layouts/home-assistant";
|
||||
|
||||
// Custom cards and plugins can reach the helpers on any page, not only once a
|
||||
// dashboard has loaded.
|
||||
Object.assign(window, {
|
||||
loadCardHelpers: () => import("../panels/lovelace/custom-card-helpers"),
|
||||
});
|
||||
|
||||
import("../resources/append-ha-style");
|
||||
@@ -93,13 +93,13 @@ export class CloudRemotePref extends LitElement {
|
||||
<ha-card
|
||||
outlined
|
||||
header=${this.hass.localize(
|
||||
"ui.panel.config.cloud.account.remote.card_title"
|
||||
"ui.panel.config.cloud.account.remote.title"
|
||||
)}
|
||||
>
|
||||
<div class="header-actions">
|
||||
<ha-switch
|
||||
.accessibleLabel=${this.hass.localize(
|
||||
"ui.panel.config.cloud.account.remote.card_title"
|
||||
"ui.panel.config.cloud.account.remote.title"
|
||||
)}
|
||||
.checked=${remote_enabled}
|
||||
@change=${this._toggleChanged}
|
||||
|
||||
@@ -104,7 +104,7 @@ export class CloudWebhooks extends LitElement {
|
||||
<div class="card-actions">
|
||||
<ha-button
|
||||
appearance="plain"
|
||||
href="https://www.nabucasa.com/config/webhooks"
|
||||
href="https://www.nabucasa.com/config/webhooks/"
|
||||
target="_blank"
|
||||
rel="noreferrer"
|
||||
>
|
||||
|
||||
@@ -514,8 +514,16 @@ class AddIntegrationDialog extends LitElement {
|
||||
return [...integrations]
|
||||
.filter((item) => !brand || item.domain === brand)
|
||||
.sort(byName)
|
||||
.flatMap((item) => this._brandRows(item))
|
||||
.filter((row) => !brand || !row.is_header);
|
||||
.flatMap((item) =>
|
||||
this._brandRows(item)
|
||||
.filter((row) => !row.is_header)
|
||||
// The brand on the second line, so its entries read as a group
|
||||
.map((row) =>
|
||||
brand || !this._isBrand(item)
|
||||
? row
|
||||
: { ...row, description: item.name }
|
||||
)
|
||||
);
|
||||
}
|
||||
// A brand shows its integrations here, not itself, like the website
|
||||
if (category) {
|
||||
@@ -1207,17 +1215,11 @@ class AddIntegrationDialog extends LitElement {
|
||||
})}
|
||||
>
|
||||
${
|
||||
!this._stickyBrand
|
||||
? nothing
|
||||
: this._filter
|
||||
? html`<ha-section-title class="sticky">
|
||||
${this._stickyBrand}
|
||||
</ha-section-title>`
|
||||
: html`<ha-integration-list-title
|
||||
class="sticky raised"
|
||||
>
|
||||
${this._stickyBrand}
|
||||
</ha-integration-list-title>`
|
||||
this._stickyBrand
|
||||
? html`<ha-section-title class="sticky">
|
||||
${this._stickyBrand}
|
||||
</ha-section-title>`
|
||||
: nothing
|
||||
}
|
||||
<ha-list-virtualized
|
||||
.rows=${this._filter ? rows : this._withEndSpace(rows)}
|
||||
@@ -1771,7 +1773,7 @@ class AddIntegrationDialog extends LitElement {
|
||||
);
|
||||
}
|
||||
|
||||
// The virtualizer positions rows, so CSS sticky can't hold the brand
|
||||
// The virtualizer positions rows, so CSS sticky can't hold the section title
|
||||
@eventOptions({ passive: true })
|
||||
private _visibilityChanged(ev: HASSDomEvent<HaListVisibilityChangedDetail>) {
|
||||
const rows = this._getRows();
|
||||
@@ -1794,11 +1796,7 @@ class AddIntegrationDialog extends LitElement {
|
||||
return html`<div style="height: var(--ha-space-2)"></div>`;
|
||||
}
|
||||
if (integration.is_header) {
|
||||
return this._filter
|
||||
? html`<ha-section-title>${integration.name}</ha-section-title>`
|
||||
: html`<ha-integration-list-title>
|
||||
${integration.name}
|
||||
</ha-integration-list-title>`;
|
||||
return html`<ha-section-title>${integration.name}</ha-section-title>`;
|
||||
}
|
||||
return html`
|
||||
<ha-integration-list-item
|
||||
|
||||
@@ -26,6 +26,7 @@ import { customElement, property, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import memoizeOne from "memoize-one";
|
||||
import { navigate } from "../../../common/navigate";
|
||||
import { formatListWithAnds } from "../../../common/string/format-list";
|
||||
import { copyToClipboard } from "../../../common/util/copy-clipboard";
|
||||
import "../../../components/ha-dropdown";
|
||||
import type { HaDropdownSelectEvent } from "../../../components/ha-dropdown";
|
||||
@@ -95,6 +96,9 @@ export class HaConfigEntryRow extends LitElement {
|
||||
|
||||
@property({ attribute: false }) public data!: ConfigEntryData;
|
||||
|
||||
/** The loaded integrations that lose this integration with this entry. */
|
||||
@property({ attribute: false }) public dependents?: IntegrationManifest[];
|
||||
|
||||
@state() private _expanded = true;
|
||||
|
||||
@state() private _devicesExpanded = true;
|
||||
@@ -812,14 +816,33 @@ export class HaConfigEntryRow extends LitElement {
|
||||
const applicationCredentialsId =
|
||||
await this._applicationCredentialForRemove(entryId);
|
||||
|
||||
const text = this.hass.localize(
|
||||
"ui.panel.config.integrations.config_entry.delete_confirm_text"
|
||||
);
|
||||
const confirmed = await showConfirmationDialog(this, {
|
||||
title: this.hass.localize(
|
||||
"ui.panel.config.integrations.config_entry.delete_confirm_title",
|
||||
{ title: this.data.entry.title }
|
||||
),
|
||||
text: this.hass.localize(
|
||||
"ui.panel.config.integrations.config_entry.delete_confirm_text"
|
||||
),
|
||||
text: this.dependents?.length
|
||||
? html`${text}<br /><br />${this.hass.localize(
|
||||
"ui.panel.config.integrations.config_entry.delete_confirm_dependents",
|
||||
{
|
||||
count: this.dependents.length,
|
||||
integrations: formatListWithAnds(
|
||||
this.hass.locale,
|
||||
this.dependents.map((manifest) =>
|
||||
domainToName(this.hass.localize, manifest.domain, manifest)
|
||||
)
|
||||
),
|
||||
name: domainToName(
|
||||
this.hass.localize,
|
||||
this.data.entry.domain,
|
||||
this.manifest
|
||||
),
|
||||
}
|
||||
)}`
|
||||
: text,
|
||||
confirmText: this.hass!.localize("ui.common.delete"),
|
||||
dismissText: this.hass!.localize("ui.common.cancel"),
|
||||
destructive: true,
|
||||
|
||||
@@ -21,7 +21,7 @@ import memoizeOne from "memoize-one";
|
||||
import { ensureArray } from "../../../common/array/ensure-array";
|
||||
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
|
||||
import { QueryParamsController } from "../../../common/controllers/query-params-controller";
|
||||
import { ContextSubscriptionController } from "../../../common/decorators/consume";
|
||||
import { consume } from "../../../common/decorators/consume";
|
||||
import type { HASSDomTargetEvent } from "../../../common/dom/fire_event";
|
||||
import { computeDeviceNameDisplay } from "../../../common/entity/compute_device_name";
|
||||
import {
|
||||
@@ -176,9 +176,9 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
@state() private _manifest?: IntegrationManifest;
|
||||
|
||||
/** The manifests of all loaded integrations, to find the dependents. */
|
||||
@state() private _loadedManifests?: DomainManifestLookup;
|
||||
|
||||
private _manifestsConsumer?: ContextSubscriptionController<DomainManifestLookup>;
|
||||
@consume({ context: manifestsContext, subscribe: true })
|
||||
@state()
|
||||
private _loadedManifests?: DomainManifestLookup;
|
||||
|
||||
@state() private _extraConfigEntries?: ConfigEntry[];
|
||||
|
||||
@@ -432,17 +432,23 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
this.domain
|
||||
);
|
||||
|
||||
const dependents = this._getDependents(
|
||||
this.domain,
|
||||
this._loadedManifests,
|
||||
this.hass.localize,
|
||||
this.hass.locale.language
|
||||
);
|
||||
// Without the dependents, a dependency looks like a YAML integration.
|
||||
const dependents =
|
||||
this._manifest && !this._manifest.config_flow
|
||||
? this._getDependents(
|
||||
this.domain,
|
||||
this._loadedManifests,
|
||||
this.hass.localize,
|
||||
this.hass.locale.language
|
||||
)
|
||||
: [];
|
||||
const showDependents = normalEntries.length === 0 && dependents.length > 0;
|
||||
const dependencyOnly =
|
||||
normalEntries.length === 0 &&
|
||||
dependents.length > 0 &&
|
||||
!this._manifest?.config_flow;
|
||||
// Deleting the last entry in use leaves the dependents without it.
|
||||
const entriesInUse = configEntries.filter(
|
||||
(entry) => entry.source !== "ignore" && !entry.disabled_by
|
||||
);
|
||||
const lastEntryId =
|
||||
entriesInUse.length === 1 ? entriesInUse[0].entry_id : undefined;
|
||||
// Hold back the YAML texts and "Add entry" until the manifest and the
|
||||
// dependents are known. Entries do not wait, so a failed request cannot
|
||||
// hide them.
|
||||
@@ -461,7 +467,7 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
|
||||
const showAddEntry =
|
||||
this._manifest?.integration_type !== "hardware" &&
|
||||
!showDependents &&
|
||||
!dependencyOnly &&
|
||||
!dependentsLoading &&
|
||||
!setUpInPanel &&
|
||||
(!this._manifest?.single_config_entry ||
|
||||
@@ -653,7 +659,7 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
}
|
||||
${
|
||||
normalEntries.length === 0 &&
|
||||
!showDependents &&
|
||||
!dependencyOnly &&
|
||||
!dependentsLoading &&
|
||||
!setUpInPanel &&
|
||||
this._manifest &&
|
||||
@@ -1010,6 +1016,11 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
.diagnosticHandler=${this._diagnosticHandler}
|
||||
.entities=${this._entities}
|
||||
.data=${data}
|
||||
.dependents=${
|
||||
data.entry.entry_id === lastEntryId
|
||||
? dependents
|
||||
: undefined
|
||||
}
|
||||
data-entry-id=${data.entry.entry_id}
|
||||
></ha-config-entry-row>`
|
||||
)}
|
||||
@@ -1018,19 +1029,7 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
: nothing
|
||||
}
|
||||
${
|
||||
showDependents
|
||||
? html`<div class="section">
|
||||
<h3 class="section-header">
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.integrations.integration_page.used_by"
|
||||
)}
|
||||
</h3>
|
||||
${this._renderDependents(dependents)}
|
||||
</div>`
|
||||
: nothing
|
||||
}
|
||||
${
|
||||
showDependents ||
|
||||
dependencyOnly ||
|
||||
dependentsLoading ||
|
||||
(setUpInPanel && normalEntries.length === 0)
|
||||
? nothing
|
||||
@@ -1077,6 +1076,11 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
.diagnosticHandler=${this._diagnosticHandler}
|
||||
.entities=${this._entities}
|
||||
.data=${data}
|
||||
.dependents=${
|
||||
data.entry.entry_id === lastEntryId
|
||||
? dependents
|
||||
: undefined
|
||||
}
|
||||
data-entry-id=${data.entry.entry_id}
|
||||
></ha-config-entry-row>`
|
||||
)}
|
||||
@@ -1084,26 +1088,23 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
}
|
||||
</div>`
|
||||
}
|
||||
${
|
||||
dependents.length
|
||||
? html`<div class="section">
|
||||
<h3 class="section-header">
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.integrations.integration_page.used_by"
|
||||
)}
|
||||
</h3>
|
||||
${this._renderDependents(dependents)}
|
||||
</div>`
|
||||
: nothing
|
||||
}
|
||||
</div>
|
||||
</hass-subpage>
|
||||
`;
|
||||
}
|
||||
|
||||
// Only an integration without a config flow needs the loaded manifests, so
|
||||
// other integration pages do not make the context fetch them.
|
||||
private _watchLoadedManifests(): void {
|
||||
if (this._manifestsConsumer) {
|
||||
return;
|
||||
}
|
||||
this._manifestsConsumer = new ContextSubscriptionController(
|
||||
this,
|
||||
manifestsContext,
|
||||
(manifests) => {
|
||||
this._loadedManifests = manifests;
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
private _getDependents = memoizeOne(
|
||||
(
|
||||
domain: string,
|
||||
@@ -1199,9 +1200,6 @@ class HaConfigIntegrationPage extends SubscribeMixin(LitElement) {
|
||||
return;
|
||||
}
|
||||
this._manifest = await fetchIntegrationManifest(this.hass, this.domain);
|
||||
if (!this._manifest.config_flow) {
|
||||
this._watchLoadedManifests();
|
||||
}
|
||||
if (
|
||||
this._manifest.integration_type &&
|
||||
!["device", "hub", "service"].includes(this._manifest.integration_type)
|
||||
|
||||
@@ -820,15 +820,14 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
|
||||
}
|
||||
|
||||
.temp-attribute .temp {
|
||||
position: relative;
|
||||
margin-right: 24px;
|
||||
direction: ltr;
|
||||
}
|
||||
|
||||
.temp-attribute .temp span {
|
||||
position: absolute;
|
||||
position: relative;
|
||||
font-size: var(--ha-font-size-2xl);
|
||||
top: 1px;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.state,
|
||||
@@ -1025,12 +1024,6 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
|
||||
font-size: var(--ha-font-size-xl);
|
||||
}
|
||||
|
||||
[class*="narrow"] .temp-attribute .temp {
|
||||
margin-right: 16px;
|
||||
margin-inline-end: 16px;
|
||||
margin-inline-start: initial;
|
||||
}
|
||||
|
||||
[class*="narrow"] .temp span {
|
||||
top: 1px;
|
||||
font-size: var(--ha-font-size-l);
|
||||
|
||||
@@ -9,6 +9,8 @@ export {
|
||||
showPromptDialog,
|
||||
} from "../../dialogs/generic/show-dialog-box";
|
||||
export { importMoreInfoControl } from "../../dialogs/more-info/state_more_info_control";
|
||||
|
||||
export { subscribeVisibility } from "../../common/condition/subscribe-visibility";
|
||||
export { createBadgeElement } from "./create-element/create-badge-element";
|
||||
export { createCardElement } from "./create-element/create-card-element";
|
||||
export { createHeaderFooterElement } from "./create-element/create-header-footer-element";
|
||||
|
||||
@@ -8,6 +8,7 @@ import deepFreeze from "deep-freeze";
|
||||
import type { CSSResultGroup, PropertyValues } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import type { HASSDomEvent } from "../../../../common/dom/fire_event";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
import { ctrlOrCmdLabel } from "../../../../common/keyboard/ctrl-or-cmd";
|
||||
@@ -75,6 +76,8 @@ export class HuiDialogEditBadge
|
||||
|
||||
@state() private _animateWidth = false;
|
||||
|
||||
private _largeBeforeCodeEditor = false;
|
||||
|
||||
@state() private _badgeConfig?: LovelaceBadgeConfig;
|
||||
|
||||
@state() private _saving = false;
|
||||
@@ -99,6 +102,7 @@ export class HuiDialogEditBadge
|
||||
this._badgeConfig = params.badgeConfig;
|
||||
|
||||
this.large = false;
|
||||
this._animateWidth = false;
|
||||
if (this._badgeConfig && !Object.isFrozen(this._badgeConfig)) {
|
||||
this._badgeConfig = deepFreeze(this._badgeConfig);
|
||||
}
|
||||
@@ -202,7 +206,10 @@ export class HuiDialogEditBadge
|
||||
.open=${this._open}
|
||||
.accessibleLabel=${heading}
|
||||
.width=${this.large ? "full" : "large"}
|
||||
class=${this._animateWidth ? "animate-width" : ""}
|
||||
class=${classMap({
|
||||
"animate-width": this._animateWidth,
|
||||
"yaml-mode": !this._GUImode,
|
||||
})}
|
||||
@dialog-set-fullscreen=${this._stopWidthAnimation}
|
||||
.preventScrimClose=${this.isEffectiveDirtyState}
|
||||
@keydown=${this._ignoreKeydown}
|
||||
@@ -345,11 +352,21 @@ export class HuiDialogEditBadge
|
||||
|
||||
private _handleGUIModeChanged(ev: HASSDomEvent<GUIModeChangedEvent>): void {
|
||||
ev.stopPropagation();
|
||||
// Fired again on every error while staying in the same mode
|
||||
if (ev.detail.guiMode !== this._GUImode) {
|
||||
if (ev.detail.guiMode) {
|
||||
this.large = this._largeBeforeCodeEditor;
|
||||
} else {
|
||||
this._largeBeforeCodeEditor = this.large;
|
||||
this.large = true;
|
||||
}
|
||||
}
|
||||
this._GUImode = ev.detail.guiMode;
|
||||
this._guiModeAvailable = ev.detail.guiModeAvailable;
|
||||
}
|
||||
|
||||
private _toggleMode(): void {
|
||||
this._animateWidth = true;
|
||||
withViewTransition(() => {
|
||||
this._badgeEditorEl?.toggleMode();
|
||||
});
|
||||
@@ -513,6 +530,17 @@ export class HuiDialogEditBadge
|
||||
ha-dialog ha-icon-button[slot="headerActionItems"] {
|
||||
color: var(--secondary-text-color);
|
||||
}
|
||||
@supports (min-height: min(1px, 2px)) {
|
||||
@media (min-width: 1000px) {
|
||||
ha-dialog.yaml-mode {
|
||||
/* Minus the toolbar of the code editor */
|
||||
--code-mirror-min-height: min(
|
||||
500px,
|
||||
var(--code-mirror-max-height, 100vh) - 28px
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
ha-dialog.animate-width {
|
||||
--ha-dialog-width-transition:
|
||||
min-width var(--ha-animation-duration-normal) ease-out,
|
||||
|
||||
@@ -8,6 +8,7 @@ import deepFreeze from "deep-freeze";
|
||||
import type { CSSResultGroup, PropertyValues } from "lit";
|
||||
import { LitElement, css, html, nothing } from "lit";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import memoizeOne from "memoize-one";
|
||||
import type { HASSDomEvent } from "../../../../common/dom/fire_event";
|
||||
import { fireEvent } from "../../../../common/dom/fire_event";
|
||||
@@ -83,6 +84,8 @@ export class HuiDialogEditCard
|
||||
|
||||
@state() private _animateWidth = false;
|
||||
|
||||
private _largeBeforeCodeEditor = false;
|
||||
|
||||
@state() private _cardConfig?: LovelaceCardConfig;
|
||||
|
||||
@state() private _sectionConfig?: LovelaceSectionConfig;
|
||||
@@ -111,6 +114,7 @@ export class HuiDialogEditCard
|
||||
this._cardConfig = params.cardConfig;
|
||||
|
||||
this.large = false;
|
||||
this._animateWidth = false;
|
||||
if (this._cardConfig && !Object.isFrozen(this._cardConfig)) {
|
||||
this._cardConfig = deepFreeze(this._cardConfig);
|
||||
}
|
||||
@@ -214,7 +218,10 @@ export class HuiDialogEditCard
|
||||
.open=${this._open}
|
||||
.accessibleLabel=${heading}
|
||||
.width=${this.large ? "full" : "large"}
|
||||
class=${this._animateWidth ? "animate-width" : ""}
|
||||
class=${classMap({
|
||||
"animate-width": this._animateWidth,
|
||||
"yaml-mode": !this._GUImode,
|
||||
})}
|
||||
@dialog-set-fullscreen=${this._stopWidthAnimation}
|
||||
.preventScrimClose=${this.isEffectiveDirtyState}
|
||||
@keydown=${this._ignoreKeydown}
|
||||
@@ -371,11 +378,21 @@ export class HuiDialogEditCard
|
||||
|
||||
private _handleGUIModeChanged(ev: HASSDomEvent<GUIModeChangedEvent>): void {
|
||||
ev.stopPropagation();
|
||||
// Fired again on every error while staying in the same mode
|
||||
if (ev.detail.guiMode !== this._GUImode) {
|
||||
if (ev.detail.guiMode) {
|
||||
this.large = this._largeBeforeCodeEditor;
|
||||
} else {
|
||||
this._largeBeforeCodeEditor = this.large;
|
||||
this.large = true;
|
||||
}
|
||||
}
|
||||
this._GUImode = ev.detail.guiMode;
|
||||
this._guiModeAvailable = ev.detail.guiModeAvailable;
|
||||
}
|
||||
|
||||
private _toggleMode(): void {
|
||||
this._animateWidth = true;
|
||||
withViewTransition(() => {
|
||||
this._cardEditorEl?.toggleMode();
|
||||
});
|
||||
@@ -595,6 +612,17 @@ export class HuiDialogEditCard
|
||||
ha-dialog ha-icon-button[slot="headerActionItems"] {
|
||||
color: var(--secondary-text-color);
|
||||
}
|
||||
@supports (min-height: min(1px, 2px)) {
|
||||
@media (min-width: 1000px) {
|
||||
ha-dialog.yaml-mode {
|
||||
/* Minus the toolbar of the code editor */
|
||||
--code-mirror-min-height: min(
|
||||
500px,
|
||||
var(--code-mirror-max-height, 100vh) - 28px
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
ha-dialog.animate-width {
|
||||
--ha-dialog-width-transition:
|
||||
min-width var(--ha-animation-duration-normal) ease-out,
|
||||
|
||||
@@ -264,8 +264,11 @@ export class HuiDialogEditSection
|
||||
<ha-dialog
|
||||
.open=${this._open}
|
||||
.accessibleLabel=${heading}
|
||||
width="large"
|
||||
class=${this._animateWidth ? "animate-width" : ""}
|
||||
.width=${this._yamlMode ? "full" : "large"}
|
||||
class=${classMap({
|
||||
"animate-width": this._animateWidth,
|
||||
"yaml-mode": this._yamlMode,
|
||||
})}
|
||||
style=${styleMap({ "--preview-column-span": previewColumnSpan })}
|
||||
@dialog-set-fullscreen=${this._stopWidthAnimation}
|
||||
.preventScrimClose=${this.isDirtyState}
|
||||
@@ -529,6 +532,7 @@ export class HuiDialogEditSection
|
||||
|
||||
private async _toggleMode(): Promise<void> {
|
||||
if (this._yamlMode && this._yamlError) return;
|
||||
this._animateWidth = true;
|
||||
await withViewTransition(() => {
|
||||
this._yamlMode = !this._yamlMode;
|
||||
});
|
||||
@@ -750,6 +754,17 @@ export class HuiDialogEditSection
|
||||
);
|
||||
}
|
||||
|
||||
@supports (min-height: min(1px, 2px)) {
|
||||
@media (min-width: 1000px) {
|
||||
ha-dialog.yaml-mode {
|
||||
/* Minus the toolbar of the code editor */
|
||||
--code-mirror-min-height: min(
|
||||
500px,
|
||||
var(--code-mirror-max-height, 100vh) - 28px
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
ha-dialog.animate-width {
|
||||
--ha-dialog-width-transition:
|
||||
min-width var(--ha-animation-duration-normal) ease-out,
|
||||
@@ -836,10 +851,11 @@ export class HuiDialogEditSection
|
||||
@media (min-width: 1000px) {
|
||||
ha-dialog {
|
||||
--editor-column-width: 520px;
|
||||
/* Plus the paddings of the preview and the dialog */
|
||||
/* Plus the paddings of the preview */
|
||||
--preview-column-total-width: calc(var(--preview-width) + 28px);
|
||||
--ha-dialog-width-lg: calc(
|
||||
var(--editor-column-width) + var(--preview-width) + 28px + 2 *
|
||||
var(--dialog-content-padding)
|
||||
var(--editor-column-width) + var(--preview-column-total-width) +
|
||||
2 * var(--dialog-content-padding)
|
||||
);
|
||||
}
|
||||
.content {
|
||||
@@ -854,6 +870,13 @@ export class HuiDialogEditSection
|
||||
.content > .element-preview {
|
||||
flex: 1 1 0;
|
||||
}
|
||||
ha-dialog.yaml-mode .content > .element-editor {
|
||||
flex: 1 0 var(--editor-column-width);
|
||||
}
|
||||
ha-dialog.yaml-mode .content > .element-preview {
|
||||
box-sizing: border-box;
|
||||
flex: 0 1 var(--preview-column-total-width);
|
||||
}
|
||||
.content > .element-editor,
|
||||
.content > .element-preview {
|
||||
min-width: 0;
|
||||
|
||||
@@ -90,6 +90,8 @@ export class HuiDialogEditView extends DirtyStateProviderMixin<LovelaceViewConfi
|
||||
|
||||
@state() private _open = false;
|
||||
|
||||
@state() private _animateWidth = false;
|
||||
|
||||
get _type(): string {
|
||||
return getViewType(this._config);
|
||||
}
|
||||
@@ -136,6 +138,7 @@ export class HuiDialogEditView extends DirtyStateProviderMixin<LovelaceViewConfi
|
||||
this._params = undefined;
|
||||
this._config = {};
|
||||
this._yamlMode = false;
|
||||
this._animateWidth = false;
|
||||
this._currTab = TABS[0];
|
||||
fireEvent(this, "dialog-closed", { dialog: this.localName });
|
||||
}
|
||||
@@ -210,10 +213,12 @@ export class HuiDialogEditView extends DirtyStateProviderMixin<LovelaceViewConfi
|
||||
<ha-dialog
|
||||
.open=${this._open}
|
||||
.accessibleLabel=${this._viewConfigTitle}
|
||||
width="large"
|
||||
.width=${this._yamlMode ? "full" : "large"}
|
||||
.preventScrimClose=${this.isDirtyState}
|
||||
@closed=${this._dialogClosed}
|
||||
@dialog-set-fullscreen=${this._stopWidthAnimation}
|
||||
class=${classMap({
|
||||
"animate-width": this._animateWidth,
|
||||
"yaml-mode": this._yamlMode,
|
||||
})}
|
||||
>
|
||||
@@ -365,7 +370,13 @@ export class HuiDialogEditView extends DirtyStateProviderMixin<LovelaceViewConfi
|
||||
}
|
||||
}
|
||||
|
||||
// The code editor's fullscreen changes the height at once, so the width must not lag behind
|
||||
private _stopWidthAnimation() {
|
||||
this._animateWidth = false;
|
||||
}
|
||||
|
||||
private async _toggleMode() {
|
||||
this._animateWidth = true;
|
||||
this._yamlMode = !this._yamlMode;
|
||||
if (this._yamlMode) {
|
||||
await this.updateComplete;
|
||||
@@ -680,6 +691,29 @@ export class HuiDialogEditView extends DirtyStateProviderMixin<LovelaceViewConfi
|
||||
ha-dialog.yaml-mode {
|
||||
--dialog-content-padding: 0;
|
||||
}
|
||||
@media (min-width: 1000px) {
|
||||
ha-dialog.yaml-mode {
|
||||
/* 80px - margin of the dialog
|
||||
137px - header and footer */
|
||||
--code-mirror-max-height: calc(100vh - 217px);
|
||||
}
|
||||
}
|
||||
@supports (min-height: min(1px, 2px)) {
|
||||
@media (min-width: 1000px) {
|
||||
ha-dialog.yaml-mode {
|
||||
/* Minus the toolbar of the code editor */
|
||||
--code-mirror-min-height: min(
|
||||
500px,
|
||||
var(--code-mirror-max-height, 100vh) - 28px
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
ha-dialog.animate-width {
|
||||
--ha-dialog-width-transition:
|
||||
min-width var(--ha-animation-duration-normal) ease-out,
|
||||
max-width var(--ha-animation-duration-normal) ease-out;
|
||||
}
|
||||
h2 {
|
||||
margin: 0;
|
||||
font-size: inherit;
|
||||
|
||||
@@ -305,6 +305,11 @@ export const haTheme = EditorView.theme({
|
||||
|
||||
".cm-scroller": { outline: "none" },
|
||||
|
||||
// On these instead of the editor, so that the gutter grows along
|
||||
".cm-content, .cm-gutter": {
|
||||
minHeight: "var(--code-mirror-min-height, 100%)",
|
||||
},
|
||||
|
||||
".cm-content": {
|
||||
caretColor: "var(--secondary-text-color)",
|
||||
paddingTop: "16px",
|
||||
|
||||
@@ -7616,7 +7616,6 @@
|
||||
},
|
||||
"remote": {
|
||||
"title": "Remote access",
|
||||
"card_title": "Remote connection",
|
||||
"connected": "Connected",
|
||||
"not_connected": "Not connected",
|
||||
"reconnecting": "Not connected. Trying to reconnect.",
|
||||
@@ -8266,6 +8265,7 @@
|
||||
"delete": "Delete",
|
||||
"delete_confirm_title": "Delete {title}?",
|
||||
"delete_confirm_text": "Its devices and entities will be permanently deleted.",
|
||||
"delete_confirm_dependents": "{integrations} {count, plural,\n one {depends on {name} and may stop working.}\n other {depend on {name} and may stop working.}\n}",
|
||||
"enable_debug_logging": "Enable debug logging",
|
||||
"reconfigure": "Reconfigure",
|
||||
"reload": "Reload",
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { subscribeVisibility } from "../../../src/common/condition/subscribe-visibility";
|
||||
import type { VisibilityCondition } from "../../../src/panels/lovelace/common/validate-condition";
|
||||
import type { HomeAssistant } from "../../../src/types";
|
||||
|
||||
interface CapturedSubscription {
|
||||
push: (message: { result?: boolean }) => void;
|
||||
unsub: ReturnType<typeof vi.fn>;
|
||||
condition: unknown;
|
||||
}
|
||||
|
||||
let subs: CapturedSubscription[];
|
||||
|
||||
const tick = () =>
|
||||
new Promise<void>((resolve) => {
|
||||
setTimeout(resolve, 10);
|
||||
});
|
||||
|
||||
const createHass = (userId = "user1"): HomeAssistant =>
|
||||
({
|
||||
connection: {
|
||||
subscribeMessage: vi.fn(
|
||||
(
|
||||
onChange: CapturedSubscription["push"],
|
||||
msg: { condition: unknown }
|
||||
) => {
|
||||
const unsub = vi.fn();
|
||||
|
||||
subs.push({ push: onChange, unsub, condition: msg.condition });
|
||||
|
||||
return Promise.resolve(unsub);
|
||||
}
|
||||
),
|
||||
},
|
||||
states: {},
|
||||
user: { id: userId },
|
||||
locale: { time_zone: "local" },
|
||||
config: { time_zone: "America/New_York" },
|
||||
}) as unknown as HomeAssistant;
|
||||
|
||||
describe("subscribeVisibility", () => {
|
||||
beforeEach(() => {
|
||||
subs = [];
|
||||
});
|
||||
|
||||
it("checks client conditions again with each hass passed to update", async () => {
|
||||
const onChange = vi.fn();
|
||||
|
||||
const conditions: VisibilityCondition[] = [
|
||||
{ condition: "user", users: ["user1"] },
|
||||
];
|
||||
|
||||
const subscription = subscribeVisibility(
|
||||
createHass("user1"),
|
||||
conditions,
|
||||
onChange
|
||||
);
|
||||
|
||||
await tick();
|
||||
expect(onChange).toHaveBeenLastCalledWith("visible", undefined);
|
||||
|
||||
subscription.update(createHass("user2"));
|
||||
expect(onChange).toHaveBeenLastCalledWith("hidden", undefined);
|
||||
});
|
||||
|
||||
it("closes core subscriptions and stops reporting after unsubscribe", async () => {
|
||||
const onChange = vi.fn();
|
||||
|
||||
const conditions: VisibilityCondition[] = [
|
||||
{ condition: "state", entity: "light.kitchen", state: "on" },
|
||||
];
|
||||
|
||||
const subscription = subscribeVisibility(
|
||||
createHass(),
|
||||
conditions,
|
||||
onChange
|
||||
);
|
||||
|
||||
await tick();
|
||||
expect(subs).toHaveLength(1);
|
||||
|
||||
subs[0].push({ result: true });
|
||||
expect(onChange).toHaveBeenLastCalledWith("visible", undefined);
|
||||
onChange.mockClear();
|
||||
|
||||
subscription.unsubscribe();
|
||||
await tick();
|
||||
expect(subs[0].unsub).toHaveBeenCalled();
|
||||
expect(onChange).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("sends the context entity to core for conditions without one", async () => {
|
||||
const conditions: VisibilityCondition[] = [
|
||||
{ condition: "state", state: "on" },
|
||||
];
|
||||
|
||||
subscribeVisibility(createHass(), conditions, vi.fn(), {
|
||||
entity_id: "light.kitchen",
|
||||
});
|
||||
|
||||
await tick();
|
||||
expect(subs).toHaveLength(1);
|
||||
expect(subs[0].condition).toEqual({
|
||||
condition: "state",
|
||||
entity_id: "light.kitchen",
|
||||
state: "on",
|
||||
});
|
||||
});
|
||||
});
|
||||
+44
-1
@@ -1,5 +1,8 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getConfigSubpageTitle } from "../../src/data/panel";
|
||||
import {
|
||||
getConfigSubpageTitle,
|
||||
getSelectedPanelUrlPath,
|
||||
} from "../../src/data/panel";
|
||||
import type { PageNavigation } from "../../src/layouts/hass-tabs-subpage";
|
||||
import type { HomeAssistant } from "../../src/types";
|
||||
|
||||
@@ -83,3 +86,43 @@ describe("getConfigSubpageTitle", () => {
|
||||
).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("getSelectedPanelUrlPath", () => {
|
||||
const urlPaths = ["lovelace", "history", "config/logs", "config/logs/raw"];
|
||||
|
||||
it("falls back to the first path segment", () => {
|
||||
expect(getSelectedPanelUrlPath(urlPaths, "/config/automation")).toBe(
|
||||
"config"
|
||||
);
|
||||
expect(getSelectedPanelUrlPath(urlPaths, "/profile/general")).toBe(
|
||||
"profile"
|
||||
);
|
||||
});
|
||||
|
||||
it("selects a panel whose url_path has several segments", () => {
|
||||
expect(getSelectedPanelUrlPath(urlPaths, "/config/logs")).toBe(
|
||||
"config/logs"
|
||||
);
|
||||
expect(getSelectedPanelUrlPath(urlPaths, "/config/logs/details")).toBe(
|
||||
"config/logs"
|
||||
);
|
||||
});
|
||||
|
||||
it("prefers the most specific url_path", () => {
|
||||
expect(getSelectedPanelUrlPath(urlPaths, "/config/logs/raw")).toBe(
|
||||
"config/logs/raw"
|
||||
);
|
||||
});
|
||||
|
||||
it("only matches whole segments", () => {
|
||||
expect(getSelectedPanelUrlPath(urlPaths, "/config/logsfoo")).toBe("config");
|
||||
});
|
||||
|
||||
it("keeps matching single segment panels on their subpaths", () => {
|
||||
expect(getSelectedPanelUrlPath(urlPaths, "/lovelace/0")).toBe("lovelace");
|
||||
});
|
||||
|
||||
it("returns an empty url_path for the root path", () => {
|
||||
expect(getSelectedPanelUrlPath(urlPaths, "/")).toBe("");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user