mirror of
https://github.com/home-assistant/frontend.git
synced 2026-11-30 16:49:04 +00:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9083641ae7 | ||
|
|
5fc4ad4e0c | ||
|
|
ba33d2897b | ||
|
|
9484d51694 | ||
|
|
55739f2666 | ||
|
|
483b8d1c76 |
No files matched your search
@@ -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();
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -22,7 +22,10 @@ import type { LocalizeFunc } from "../../common/translations/localize";
|
||||
import { nextRender } from "../../common/util/render-status";
|
||||
import type { CameraCapabilities, CameraEntity } from "../../data/camera";
|
||||
import type { CameraStreamStatus } from "../../data/camera-streams";
|
||||
import { showCameraStreamInfoDialog } from "../../dialogs/camera/show-dialog-camera-stream-info";
|
||||
import {
|
||||
showCameraStreamInfoDialog,
|
||||
type CameraStreamInfo,
|
||||
} from "../../dialogs/camera/show-dialog-camera-stream-info";
|
||||
import "../ha-camera-stream";
|
||||
import type { HaCameraStream } from "../ha-camera-stream";
|
||||
import "../ha-icon-button";
|
||||
@@ -108,6 +111,8 @@ export class HaCameraPlayer extends LitElement {
|
||||
|
||||
@state() private _capabilities?: CameraCapabilities;
|
||||
|
||||
private _streamInfoCallbacks = new Set<(info: CameraStreamInfo) => void>();
|
||||
|
||||
@state() private _video?: HTMLVideoElement;
|
||||
|
||||
@state() private _muted = false;
|
||||
@@ -213,6 +218,7 @@ export class HaCameraPlayer extends LitElement {
|
||||
);
|
||||
clearTimeout(this._controlsTimeout);
|
||||
clearTimeout(this._wheelHintTimeout);
|
||||
this._streamInfoCallbacks.clear();
|
||||
this._unbindVideo(this._video);
|
||||
this._video = undefined;
|
||||
this._pointers.clear();
|
||||
@@ -252,6 +258,10 @@ export class HaCameraPlayer extends LitElement {
|
||||
this._unbindVideo(changedProps.get("_video") as HTMLVideoElement);
|
||||
this._bindVideo(this._video);
|
||||
}
|
||||
if (changedProps.has("_status") || changedProps.has("_capabilities")) {
|
||||
const info = this._streamInfo();
|
||||
this._streamInfoCallbacks.forEach((callback) => callback(info));
|
||||
}
|
||||
}
|
||||
|
||||
protected render() {
|
||||
@@ -602,10 +612,26 @@ export class HaCameraPlayer extends LitElement {
|
||||
this._posterSize = ev.detail.size;
|
||||
}
|
||||
|
||||
private _showStreamInfo() {
|
||||
showCameraStreamInfoDialog(this, {
|
||||
private _streamInfo(): CameraStreamInfo {
|
||||
return {
|
||||
status: this._status,
|
||||
supportedTypes: this._capabilities?.frontend_stream_types,
|
||||
};
|
||||
}
|
||||
|
||||
private _subscribeStreamInfo = (
|
||||
callback: (info: CameraStreamInfo) => void
|
||||
) => {
|
||||
this._streamInfoCallbacks.add(callback);
|
||||
callback(this._streamInfo());
|
||||
return () => {
|
||||
this._streamInfoCallbacks.delete(callback);
|
||||
};
|
||||
};
|
||||
|
||||
private _showStreamInfo() {
|
||||
showCameraStreamInfoDialog(this, {
|
||||
subscribe: this._subscribeStreamInfo,
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -28,7 +28,10 @@ import { fetchCloudStatus } from "../../data/cloud";
|
||||
import { apiContext, configContext } from "../../data/context";
|
||||
import { haStyleDialog, haStyleDialogFixedTop } from "../../resources/styles";
|
||||
import { DialogMixin } from "../dialog-mixin";
|
||||
import type { CameraStreamInfoDialogParams } from "./show-dialog-camera-stream-info";
|
||||
import type {
|
||||
CameraStreamInfo,
|
||||
CameraStreamInfoDialogParams,
|
||||
} from "./show-dialog-camera-stream-info";
|
||||
|
||||
// Ordered from the fastest to the most compatible
|
||||
const STREAM_TYPES: { type: CameraStreamType; icon: string }[] = [
|
||||
@@ -53,6 +56,23 @@ class DialogCameraStreamInfo extends DialogMixin<CameraStreamInfoDialogParams>(
|
||||
|
||||
@state() private _cloudIceServers = false;
|
||||
|
||||
@state() private _info?: CameraStreamInfo;
|
||||
|
||||
private _unsubscribe?: () => void;
|
||||
|
||||
public connectedCallback() {
|
||||
super.connectedCallback();
|
||||
this._unsubscribe = this.params?.subscribe((info) => {
|
||||
this._info = info;
|
||||
});
|
||||
}
|
||||
|
||||
public disconnectedCallback() {
|
||||
this._unsubscribe?.();
|
||||
this._unsubscribe = undefined;
|
||||
super.disconnectedCallback();
|
||||
}
|
||||
|
||||
protected firstUpdated() {
|
||||
this._fetchCloudIceServers();
|
||||
}
|
||||
@@ -74,10 +94,10 @@ class DialogCameraStreamInfo extends DialogMixin<CameraStreamInfoDialogParams>(
|
||||
}
|
||||
|
||||
protected render() {
|
||||
if (!this.params) {
|
||||
if (!this._info) {
|
||||
return nothing;
|
||||
}
|
||||
const { status, supportedTypes } = this.params;
|
||||
const { status, supportedTypes } = this._info;
|
||||
// Without a video stream, still images are all the camera has
|
||||
const stillImagesOnly = supportedTypes?.length === 0;
|
||||
// MJPEG is only the fallback, only worth explaining while it shows
|
||||
@@ -161,7 +181,7 @@ class DialogCameraStreamInfo extends DialogMixin<CameraStreamInfoDialogParams>(
|
||||
type: CameraStreamType;
|
||||
icon: string;
|
||||
}) {
|
||||
const { status } = this.params!;
|
||||
const { status } = this._info!;
|
||||
const current = !status.connecting && status.type === type;
|
||||
const upgrading = status.upgrading === type;
|
||||
return html`
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
import { fireEvent } from "../../common/dom/fire_event";
|
||||
import type { CameraStreamStatus, StreamType } from "../../data/camera-streams";
|
||||
|
||||
export interface CameraStreamInfoDialogParams {
|
||||
export interface CameraStreamInfo {
|
||||
status: CameraStreamStatus;
|
||||
/** The stream types the camera supports, undefined while unknown */
|
||||
supportedTypes?: StreamType[];
|
||||
}
|
||||
|
||||
export interface CameraStreamInfoDialogParams {
|
||||
/** Calls back with the current info right away and on every change */
|
||||
subscribe: (callback: (info: CameraStreamInfo) => void) => () => void;
|
||||
}
|
||||
|
||||
export const showCameraStreamInfoDialog = (
|
||||
element: HTMLElement,
|
||||
params: CameraStreamInfoDialogParams
|
||||
|
||||
@@ -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");
|
||||
@@ -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)
|
||||
|
||||
@@ -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";
|
||||
|
||||
@@ -8266,6 +8266,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}\n other {depend}\n} on {name} and may stop working.",
|
||||
"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