mirror of
https://github.com/home-assistant/frontend.git
synced 2026-12-01 09:09:11 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ea9939167 | ||
|
|
dcc19b8fa5 | ||
|
|
9335d12eaa | ||
|
|
cafb485e1e |
No files matched your search
+5
-5
@@ -40,7 +40,7 @@
|
||||
"license": "Apache-2.0",
|
||||
"type": "module",
|
||||
"dependencies": {
|
||||
"@babel/runtime": "8.1.4",
|
||||
"@babel/runtime": "8.1.3",
|
||||
"@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.4",
|
||||
"@babel/core": "8.1.3",
|
||||
"@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.1.4",
|
||||
"@babel/preset-env": "8.0.7",
|
||||
"@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.16.0",
|
||||
"eslint": "10.15.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]4.0",
|
||||
"packageManager": "[email protected]3.0",
|
||||
"volta": {
|
||||
"node": "24.22.3"
|
||||
}
|
||||
|
||||
Generated
+526
-521
File diff suppressed because it is too large.
Load diff
@@ -1,74 +0,0 @@
|
||||
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();
|
||||
},
|
||||
};
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
/**
|
||||
* How long after the full screen button the companion apps hide the page for
|
||||
* the change, and after that how long they keep it hidden. A later hide ends
|
||||
* streams as usual.
|
||||
*/
|
||||
export const FULLSCREEN_ENTER_TIME = 1000;
|
||||
|
||||
let enterStart = 0;
|
||||
|
||||
let enterId = 0;
|
||||
|
||||
// The last entering each stream let a hidden page through for
|
||||
const claimedEnters = new WeakMap<object, number>();
|
||||
|
||||
/**
|
||||
* Marks that the full screen button was pressed to enter full screen. The
|
||||
* companion apps hide the page for a moment then, which shouldn't end a
|
||||
* stream. Leaving full screen isn't marked, so locking the phone or leaving
|
||||
* the app right after it always ends the streams.
|
||||
*/
|
||||
export const startEnteringFullscreen = () => {
|
||||
enterId++;
|
||||
enterStart = Date.now();
|
||||
};
|
||||
|
||||
/** Ends it early, like when the browser denies full screen. */
|
||||
export const cancelEnteringFullscreen = () => {
|
||||
enterStart = 0;
|
||||
};
|
||||
|
||||
export const isEnteringFullscreen = () =>
|
||||
Date.now() - enterStart < FULLSCREEN_ENTER_TIME;
|
||||
|
||||
/**
|
||||
* Whether the page is hidden by entering full screen, which hides it only
|
||||
* once. Any later hiding is the user leaving, so each stream gets true only
|
||||
* once per entering.
|
||||
*/
|
||||
export const claimFullscreenEnterHide = (stream: object): boolean => {
|
||||
if (!isEnteringFullscreen() || claimedEnters.get(stream) === enterId) {
|
||||
return false;
|
||||
}
|
||||
claimedEnters.set(stream, enterId);
|
||||
// Counts from here, so the video still plays on when the page shows again
|
||||
enterStart = Date.now();
|
||||
return true;
|
||||
};
|
||||
@@ -17,11 +17,17 @@ import { consumeLocalize } from "../../common/decorators/consume-context-entry";
|
||||
import { storage } from "../../common/decorators/storage";
|
||||
import { deepActiveElement } from "../../common/dom/deep-active-element";
|
||||
import { fireEvent, type HASSDomEvent } from "../../common/dom/fire_event";
|
||||
import {
|
||||
cancelEnteringFullscreen,
|
||||
isEnteringFullscreen,
|
||||
startEnteringFullscreen,
|
||||
} from "../../common/dom/entering-fullscreen";
|
||||
import { ctrlOrCmdLabel } from "../../common/keyboard/ctrl-or-cmd";
|
||||
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 { isExternal } from "../../data/external";
|
||||
import {
|
||||
showCameraStreamInfoDialog,
|
||||
type CameraStreamInfo,
|
||||
@@ -142,6 +148,10 @@ export class HaCameraPlayer extends LitElement {
|
||||
// full screen player
|
||||
@state() private _paused = false;
|
||||
|
||||
// Playing when its button entered full screen, so a pause meanwhile is the
|
||||
// companion app's
|
||||
private _playingBeforeFullscreen = false;
|
||||
|
||||
@query("ha-camera-stream") private _stream?: HaCameraStream;
|
||||
|
||||
@query(".player") private _player?: HTMLElement;
|
||||
@@ -195,7 +205,7 @@ export class HaCameraPlayer extends LitElement {
|
||||
|
||||
public connectedCallback() {
|
||||
super.connectedCallback();
|
||||
document.addEventListener("visibilitychange", this._requestWakeLock);
|
||||
document.addEventListener("visibilitychange", this._visibilityChanged);
|
||||
// The first update requests it, once keep-awake is set
|
||||
if (this.hasUpdated) {
|
||||
this._requestWakeLock();
|
||||
@@ -209,7 +219,7 @@ export class HaCameraPlayer extends LitElement {
|
||||
|
||||
public disconnectedCallback() {
|
||||
super.disconnectedCallback();
|
||||
document.removeEventListener("visibilitychange", this._requestWakeLock);
|
||||
document.removeEventListener("visibilitychange", this._visibilityChanged);
|
||||
this._releaseWakeLock();
|
||||
document.removeEventListener("fullscreenchange", this._fullscreenChanged);
|
||||
document.removeEventListener(
|
||||
@@ -485,6 +495,11 @@ export class HaCameraPlayer extends LitElement {
|
||||
</div>`;
|
||||
}
|
||||
|
||||
private _visibilityChanged = () => {
|
||||
this._requestWakeLock();
|
||||
this._resumeAfterEnteringFullscreen();
|
||||
};
|
||||
|
||||
/**
|
||||
* Browsers release the lock when the page is hidden, so it is requested
|
||||
* again whenever the page shows.
|
||||
@@ -720,6 +735,7 @@ export class HaCameraPlayer extends LitElement {
|
||||
this._paused = Boolean(
|
||||
video?.paused && (video.srcObject || video.currentSrc)
|
||||
);
|
||||
this._resumeAfterEnteringFullscreen();
|
||||
};
|
||||
|
||||
private _toggleMute() {
|
||||
@@ -771,16 +787,27 @@ export class HaCameraPlayer extends LitElement {
|
||||
("webkitFullscreenElement" in document
|
||||
? (document.webkitFullscreenElement as Element | null)
|
||||
: null);
|
||||
const fullscreen = Boolean(
|
||||
this._fullscreen = Boolean(
|
||||
this._player && fullscreenElement === this._player
|
||||
);
|
||||
if (fullscreen !== this._fullscreen) {
|
||||
this._fullscreen = fullscreen;
|
||||
// The size changes, so the zoomed in area would be off
|
||||
this._zoom = ZOOM_PAN_IDENTITY;
|
||||
}
|
||||
this._resumeAfterEnteringFullscreen();
|
||||
};
|
||||
|
||||
// The companion apps pause the video while entering full screen
|
||||
private _resumeAfterEnteringFullscreen() {
|
||||
if (
|
||||
isExternal &&
|
||||
this._playingBeforeFullscreen &&
|
||||
this._paused &&
|
||||
document.visibilityState === "visible" &&
|
||||
isEnteringFullscreen()
|
||||
) {
|
||||
// Only once, so a pause in the iPhone's own full screen controls stays
|
||||
this._playingBeforeFullscreen = false;
|
||||
this._ensurePlaying();
|
||||
}
|
||||
}
|
||||
|
||||
private async _toggleFullscreen() {
|
||||
const player = this._player;
|
||||
if (!player) {
|
||||
@@ -795,6 +822,10 @@ export class HaCameraPlayer extends LitElement {
|
||||
}
|
||||
return;
|
||||
}
|
||||
this._playingBeforeFullscreen = Boolean(
|
||||
this._video && !this._video.paused
|
||||
);
|
||||
startEnteringFullscreen();
|
||||
if (player.requestFullscreen) {
|
||||
await player.requestFullscreen();
|
||||
} else if ("webkitRequestFullscreen" in player) {
|
||||
@@ -808,6 +839,7 @@ export class HaCameraPlayer extends LitElement {
|
||||
}
|
||||
} catch (_err: unknown) {
|
||||
// Denied by the browser
|
||||
cancelEnteringFullscreen();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1939,10 +1939,6 @@ 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;
|
||||
|
||||
@@ -9,6 +9,10 @@ import { consume } from "../common/decorators/consume";
|
||||
import { isComponentLoaded } from "../common/config/is_component_loaded";
|
||||
import { consumeLocalize } from "../common/decorators/consume-context-entry";
|
||||
import { fireEvent } from "../common/dom/fire_event";
|
||||
import {
|
||||
claimFullscreenEnterHide,
|
||||
FULLSCREEN_ENTER_TIME,
|
||||
} from "../common/dom/entering-fullscreen";
|
||||
import type { LocalizeFunc } from "../common/translations/localize";
|
||||
import { nextRender } from "../common/util/render-status";
|
||||
import { fetchStreamUrl } from "../data/camera";
|
||||
@@ -101,16 +105,19 @@ export class HaHLSPlayer extends LitElement {
|
||||
return;
|
||||
}
|
||||
if (document.hidden) {
|
||||
if (isExternal) {
|
||||
if (isExternal && !claimFullscreenEnterHide(this)) {
|
||||
// The companion apps pause JavaScript timers while in the background,
|
||||
// so a delayed clean up would not run until the app is opened again
|
||||
this._cleanUp();
|
||||
return;
|
||||
}
|
||||
this._hiddenCleanupTimeout = window.setTimeout(() => {
|
||||
this._hiddenCleanupTimeout = undefined;
|
||||
this._cleanUp();
|
||||
}, HIDDEN_CLEANUP_DELAY);
|
||||
this._hiddenCleanupTimeout = window.setTimeout(
|
||||
() => {
|
||||
this._hiddenCleanupTimeout = undefined;
|
||||
this._cleanUp();
|
||||
},
|
||||
isExternal ? FULLSCREEN_ENTER_TIME : HIDDEN_CLEANUP_DELAY
|
||||
);
|
||||
} else if (this._hiddenCleanupTimeout) {
|
||||
// stream was not cleaned up yet, just cancel the cleanup
|
||||
clearTimeout(this._hiddenCleanupTimeout);
|
||||
|
||||
@@ -8,6 +8,10 @@ import { styleMap } from "lit/directives/style-map";
|
||||
import { consume } from "../common/decorators/consume";
|
||||
import { consumeLocalize } from "../common/decorators/consume-context-entry";
|
||||
import { fireEvent } from "../common/dom/fire_event";
|
||||
import {
|
||||
claimFullscreenEnterHide,
|
||||
FULLSCREEN_ENTER_TIME,
|
||||
} from "../common/dom/entering-fullscreen";
|
||||
import type { LocalizeFunc } from "../common/translations/localize";
|
||||
import {
|
||||
addWebRtcCandidate,
|
||||
@@ -242,16 +246,19 @@ export class HaWebRtcPlayer extends LitElement {
|
||||
return;
|
||||
}
|
||||
if (document.hidden) {
|
||||
if (isExternal) {
|
||||
if (isExternal && !claimFullscreenEnterHide(this)) {
|
||||
// The companion apps pause JavaScript timers while in the background,
|
||||
// so a delayed clean up would not run until the app is opened again
|
||||
this._cleanUp();
|
||||
return;
|
||||
}
|
||||
this._hiddenCleanupTimeout = window.setTimeout(() => {
|
||||
this._hiddenCleanupTimeout = undefined;
|
||||
this._cleanUp();
|
||||
}, HIDDEN_CLEANUP_DELAY);
|
||||
this._hiddenCleanupTimeout = window.setTimeout(
|
||||
() => {
|
||||
this._hiddenCleanupTimeout = undefined;
|
||||
this._cleanUp();
|
||||
},
|
||||
isExternal ? FULLSCREEN_ENTER_TIME : HIDDEN_CLEANUP_DELAY
|
||||
);
|
||||
} else if (this._hiddenCleanupTimeout) {
|
||||
// stream was not cleaned up yet, just cancel the cleanup
|
||||
clearTimeout(this._hiddenCleanupTimeout);
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
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";
|
||||
@@ -457,11 +456,6 @@ 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,14 +620,15 @@ class MoreInfoWeather extends LitElement {
|
||||
}
|
||||
|
||||
.temp-attribute .temp {
|
||||
position: relative;
|
||||
margin-right: var(--ha-space-6);
|
||||
direction: ltr;
|
||||
}
|
||||
|
||||
.temp-attribute .temp span {
|
||||
position: relative;
|
||||
position: absolute;
|
||||
font-size: var(--ha-font-size-2xl);
|
||||
top: 1px;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.state,
|
||||
|
||||
@@ -2,10 +2,4 @@ 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");
|
||||
@@ -1,63 +0,0 @@
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, state } from "lit/decorators";
|
||||
import { consumeLocalize } from "../../../common/decorators/consume-context-entry";
|
||||
import type { LocalizeFunc } from "../../../common/translations/localize";
|
||||
import "../../../components/ha-code-editor";
|
||||
import "../../../components/ha-dialog";
|
||||
import { DialogMixin } from "../../../dialogs/dialog-mixin";
|
||||
import type { BlueprintContentDialogParams } from "./show-dialog-blueprint-content";
|
||||
|
||||
@customElement("dialog-blueprint-content")
|
||||
class DialogBlueprintContent extends DialogMixin<BlueprintContentDialogParams>(
|
||||
LitElement
|
||||
) {
|
||||
@state()
|
||||
@consumeLocalize()
|
||||
private _localize!: LocalizeFunc;
|
||||
|
||||
protected render() {
|
||||
if (!this.params) {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
return html`
|
||||
<ha-dialog
|
||||
open
|
||||
width="full"
|
||||
flexcontent
|
||||
header-title=${this._localize(
|
||||
"ui.panel.config.blueprint.add.raw_blueprint"
|
||||
)}
|
||||
header-subtitle=${this.params.name}
|
||||
>
|
||||
<ha-code-editor
|
||||
mode="yaml"
|
||||
.value=${this.params.content}
|
||||
read-only
|
||||
in-dialog
|
||||
dir="ltr"
|
||||
></ha-code-editor>
|
||||
</ha-dialog>
|
||||
`;
|
||||
}
|
||||
|
||||
static styles = css`
|
||||
ha-dialog {
|
||||
--dialog-content-padding: 0;
|
||||
}
|
||||
/* A grid, so that the editor fills the height and scrolls inside */
|
||||
ha-code-editor {
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
display: grid;
|
||||
grid-template-rows: minmax(0, 1fr);
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
declare global {
|
||||
interface HTMLElementTagNameMap {
|
||||
"dialog-blueprint-content": DialogBlueprintContent;
|
||||
}
|
||||
}
|
||||
@@ -1,14 +1,16 @@
|
||||
import "@home-assistant/components/card";
|
||||
import { mdiClose, mdiCodeBraces, mdiOpenInNew } from "@mdi/js";
|
||||
import { mdiClose, mdiOpenInNew } from "@mdi/js";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, query, state } from "lit/decorators";
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
import type { HASSDomTargetEvent } from "../../../common/dom/fire_event";
|
||||
import { withViewTransition } from "../../../common/util/view-transition";
|
||||
import "../../../components/ha-alert";
|
||||
import "../../../components/ha-button";
|
||||
import "../../../components/ha-code-editor";
|
||||
import "../../../components/ha-dialog";
|
||||
import "../../../components/ha-dialog-footer";
|
||||
import "../../../components/ha-dialog-header";
|
||||
import "../../../components/ha-expansion-panel";
|
||||
import "../../../components/ha-markdown";
|
||||
import "../../../components/ha-spinner";
|
||||
import "../../../components/input/ha-input";
|
||||
@@ -19,7 +21,6 @@ import { DirtyStateProviderMixin } from "../../../mixins/dirty-state-provider-mi
|
||||
import { haStyleDialog } from "../../../resources/styles";
|
||||
import type { HomeAssistant } from "../../../types";
|
||||
import { documentationUrl } from "../../../util/documentation-url";
|
||||
import { showBlueprintContentDialog } from "./show-dialog-blueprint-content";
|
||||
|
||||
interface BlueprintImportState {
|
||||
value: string;
|
||||
@@ -32,6 +33,8 @@ class DialogImportBlueprint extends DirtyStateProviderMixin<BlueprintImportState
|
||||
) {
|
||||
@property({ attribute: false }) public hass!: HomeAssistant;
|
||||
|
||||
@property({ type: Boolean, reflect: true }) public large = false;
|
||||
|
||||
@state() private _params?;
|
||||
|
||||
@state() private _open = false;
|
||||
@@ -55,6 +58,7 @@ class DialogImportBlueprint extends DirtyStateProviderMixin<BlueprintImportState
|
||||
this._error = undefined;
|
||||
this._url = this._params.url;
|
||||
this._sourceUrlWarning = !this._isTrustedBlueprintUrl(this._url);
|
||||
this.large = false;
|
||||
this._open = true;
|
||||
this._initDirtyTracking(
|
||||
{ type: "shallow" },
|
||||
@@ -84,6 +88,7 @@ class DialogImportBlueprint extends DirtyStateProviderMixin<BlueprintImportState
|
||||
<ha-dialog
|
||||
.open=${this._open}
|
||||
.accessibleLabel=${heading}
|
||||
width=${this.large ? "full" : "medium"}
|
||||
.preventScrimClose=${this.isDirtyState}
|
||||
@closed=${this._dialogClosed}
|
||||
>
|
||||
@@ -94,7 +99,9 @@ class DialogImportBlueprint extends DirtyStateProviderMixin<BlueprintImportState
|
||||
.label=${this.hass.localize("ui.common.close")}
|
||||
.path=${mdiClose}
|
||||
></ha-icon-button>
|
||||
<span slot="title">${heading}</span>
|
||||
<span slot="title" class="title-enlargeable" @click=${this._enlarge}>
|
||||
${heading}
|
||||
</span>
|
||||
</ha-dialog-header>
|
||||
<div>
|
||||
${
|
||||
@@ -157,37 +164,18 @@ class DialogImportBlueprint extends DirtyStateProviderMixin<BlueprintImportState
|
||||
></ha-input>
|
||||
`
|
||||
}
|
||||
<hac-card class="content-card">
|
||||
<div class="content-row">
|
||||
<div class="content-text">
|
||||
<span>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.blueprint.add.raw_blueprint"
|
||||
)}
|
||||
</span>
|
||||
<span class="content-description">
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.blueprint.add.raw_blueprint_description"
|
||||
)}
|
||||
</span>
|
||||
</div>
|
||||
<ha-button
|
||||
appearance="filled"
|
||||
.accessibleLabel=${this.hass.localize(
|
||||
"ui.panel.config.blueprint.add.view_raw_blueprint_label"
|
||||
)}
|
||||
@click=${this._showContent}
|
||||
>
|
||||
<ha-svg-icon
|
||||
slot="start"
|
||||
.path=${mdiCodeBraces}
|
||||
></ha-svg-icon>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.blueprint.add.view_raw_blueprint"
|
||||
)}
|
||||
</ha-button>
|
||||
</div>
|
||||
</hac-card>
|
||||
<ha-expansion-panel
|
||||
.header=${this.hass.localize(
|
||||
"ui.panel.config.blueprint.add.raw_blueprint"
|
||||
)}
|
||||
>
|
||||
<ha-code-editor
|
||||
mode="yaml"
|
||||
.value=${this._result.raw_data}
|
||||
read-only
|
||||
dir="ltr"
|
||||
></ha-code-editor>
|
||||
</ha-expansion-panel>
|
||||
${
|
||||
this._result?.exists
|
||||
? html`
|
||||
@@ -287,10 +275,9 @@ class DialogImportBlueprint extends DirtyStateProviderMixin<BlueprintImportState
|
||||
`;
|
||||
}
|
||||
|
||||
private _showContent() {
|
||||
showBlueprintContentDialog(this, {
|
||||
name: this._result!.blueprint.metadata.name,
|
||||
content: this._result!.raw_data,
|
||||
private _enlarge() {
|
||||
withViewTransition(() => {
|
||||
this.large = !this.large;
|
||||
});
|
||||
}
|
||||
|
||||
@@ -397,23 +384,11 @@ class DialogImportBlueprint extends DirtyStateProviderMixin<BlueprintImportState
|
||||
a ha-svg-icon {
|
||||
--mdc-icon-size: 16px;
|
||||
}
|
||||
.content-card {
|
||||
margin: var(--ha-space-6) 0 var(--ha-space-2);
|
||||
ha-expansion-panel {
|
||||
--expansion-panel-content-padding: 0px;
|
||||
}
|
||||
.content-row {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: var(--ha-space-4);
|
||||
}
|
||||
.content-text {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
.content-description {
|
||||
font-size: var(--ha-font-size-s);
|
||||
color: var(--secondary-text-color);
|
||||
.title-enlargeable {
|
||||
display: block;
|
||||
}
|
||||
`,
|
||||
];
|
||||
|
||||
@@ -1,20 +0,0 @@
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
|
||||
export interface BlueprintContentDialogParams {
|
||||
name: string;
|
||||
content: string;
|
||||
}
|
||||
|
||||
export const loadBlueprintContentDialog = () =>
|
||||
import("./dialog-blueprint-content");
|
||||
|
||||
export const showBlueprintContentDialog = (
|
||||
element: HTMLElement,
|
||||
dialogParams: BlueprintContentDialogParams
|
||||
): void => {
|
||||
fireEvent(element, "show-dialog", {
|
||||
dialogTag: "dialog-blueprint-content",
|
||||
dialogImport: loadBlueprintContentDialog,
|
||||
dialogParams,
|
||||
});
|
||||
};
|
||||
@@ -93,13 +93,13 @@ export class CloudRemotePref extends LitElement {
|
||||
<ha-card
|
||||
outlined
|
||||
header=${this.hass.localize(
|
||||
"ui.panel.config.cloud.account.remote.title"
|
||||
"ui.panel.config.cloud.account.remote.card_title"
|
||||
)}
|
||||
>
|
||||
<div class="header-actions">
|
||||
<ha-switch
|
||||
.accessibleLabel=${this.hass.localize(
|
||||
"ui.panel.config.cloud.account.remote.title"
|
||||
"ui.panel.config.cloud.account.remote.card_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"
|
||||
>
|
||||
|
||||
@@ -820,14 +820,15 @@ class HuiWeatherForecastCard extends LitElement implements LovelaceCard {
|
||||
}
|
||||
|
||||
.temp-attribute .temp {
|
||||
position: relative;
|
||||
margin-right: 24px;
|
||||
direction: ltr;
|
||||
}
|
||||
|
||||
.temp-attribute .temp span {
|
||||
position: relative;
|
||||
position: absolute;
|
||||
font-size: var(--ha-font-size-2xl);
|
||||
top: 1px;
|
||||
vertical-align: top;
|
||||
}
|
||||
|
||||
.state,
|
||||
@@ -1024,6 +1025,12 @@ 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,8 +9,6 @@ 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,7 +8,6 @@ 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";
|
||||
@@ -76,8 +75,6 @@ export class HuiDialogEditBadge
|
||||
|
||||
@state() private _animateWidth = false;
|
||||
|
||||
private _largeBeforeCodeEditor = false;
|
||||
|
||||
@state() private _badgeConfig?: LovelaceBadgeConfig;
|
||||
|
||||
@state() private _saving = false;
|
||||
@@ -102,7 +99,6 @@ 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);
|
||||
}
|
||||
@@ -206,10 +202,7 @@ export class HuiDialogEditBadge
|
||||
.open=${this._open}
|
||||
.accessibleLabel=${heading}
|
||||
.width=${this.large ? "full" : "large"}
|
||||
class=${classMap({
|
||||
"animate-width": this._animateWidth,
|
||||
"yaml-mode": !this._GUImode,
|
||||
})}
|
||||
class=${this._animateWidth ? "animate-width" : ""}
|
||||
@dialog-set-fullscreen=${this._stopWidthAnimation}
|
||||
.preventScrimClose=${this.isEffectiveDirtyState}
|
||||
@keydown=${this._ignoreKeydown}
|
||||
@@ -352,21 +345,11 @@ 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();
|
||||
});
|
||||
@@ -530,17 +513,6 @@ 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,7 +8,6 @@ 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";
|
||||
@@ -84,8 +83,6 @@ export class HuiDialogEditCard
|
||||
|
||||
@state() private _animateWidth = false;
|
||||
|
||||
private _largeBeforeCodeEditor = false;
|
||||
|
||||
@state() private _cardConfig?: LovelaceCardConfig;
|
||||
|
||||
@state() private _sectionConfig?: LovelaceSectionConfig;
|
||||
@@ -114,7 +111,6 @@ 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);
|
||||
}
|
||||
@@ -218,10 +214,7 @@ export class HuiDialogEditCard
|
||||
.open=${this._open}
|
||||
.accessibleLabel=${heading}
|
||||
.width=${this.large ? "full" : "large"}
|
||||
class=${classMap({
|
||||
"animate-width": this._animateWidth,
|
||||
"yaml-mode": !this._GUImode,
|
||||
})}
|
||||
class=${this._animateWidth ? "animate-width" : ""}
|
||||
@dialog-set-fullscreen=${this._stopWidthAnimation}
|
||||
.preventScrimClose=${this.isEffectiveDirtyState}
|
||||
@keydown=${this._ignoreKeydown}
|
||||
@@ -378,21 +371,11 @@ 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();
|
||||
});
|
||||
@@ -612,17 +595,6 @@ 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,11 +264,8 @@ export class HuiDialogEditSection
|
||||
<ha-dialog
|
||||
.open=${this._open}
|
||||
.accessibleLabel=${heading}
|
||||
.width=${this._yamlMode ? "full" : "large"}
|
||||
class=${classMap({
|
||||
"animate-width": this._animateWidth,
|
||||
"yaml-mode": this._yamlMode,
|
||||
})}
|
||||
width="large"
|
||||
class=${this._animateWidth ? "animate-width" : ""}
|
||||
style=${styleMap({ "--preview-column-span": previewColumnSpan })}
|
||||
@dialog-set-fullscreen=${this._stopWidthAnimation}
|
||||
.preventScrimClose=${this.isDirtyState}
|
||||
@@ -532,7 +529,6 @@ export class HuiDialogEditSection
|
||||
|
||||
private async _toggleMode(): Promise<void> {
|
||||
if (this._yamlMode && this._yamlError) return;
|
||||
this._animateWidth = true;
|
||||
await withViewTransition(() => {
|
||||
this._yamlMode = !this._yamlMode;
|
||||
});
|
||||
@@ -754,17 +750,6 @@ 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,
|
||||
@@ -851,11 +836,10 @@ export class HuiDialogEditSection
|
||||
@media (min-width: 1000px) {
|
||||
ha-dialog {
|
||||
--editor-column-width: 520px;
|
||||
/* Plus the paddings of the preview */
|
||||
--preview-column-total-width: calc(var(--preview-width) + 28px);
|
||||
/* Plus the paddings of the preview and the dialog */
|
||||
--ha-dialog-width-lg: calc(
|
||||
var(--editor-column-width) + var(--preview-column-total-width) +
|
||||
2 * var(--dialog-content-padding)
|
||||
var(--editor-column-width) + var(--preview-width) + 28px + 2 *
|
||||
var(--dialog-content-padding)
|
||||
);
|
||||
}
|
||||
.content {
|
||||
@@ -870,13 +854,6 @@ 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,8 +90,6 @@ export class HuiDialogEditView extends DirtyStateProviderMixin<LovelaceViewConfi
|
||||
|
||||
@state() private _open = false;
|
||||
|
||||
@state() private _animateWidth = false;
|
||||
|
||||
get _type(): string {
|
||||
return getViewType(this._config);
|
||||
}
|
||||
@@ -138,7 +136,6 @@ 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 });
|
||||
}
|
||||
@@ -213,12 +210,10 @@ export class HuiDialogEditView extends DirtyStateProviderMixin<LovelaceViewConfi
|
||||
<ha-dialog
|
||||
.open=${this._open}
|
||||
.accessibleLabel=${this._viewConfigTitle}
|
||||
.width=${this._yamlMode ? "full" : "large"}
|
||||
width="large"
|
||||
.preventScrimClose=${this.isDirtyState}
|
||||
@closed=${this._dialogClosed}
|
||||
@dialog-set-fullscreen=${this._stopWidthAnimation}
|
||||
class=${classMap({
|
||||
"animate-width": this._animateWidth,
|
||||
"yaml-mode": this._yamlMode,
|
||||
})}
|
||||
>
|
||||
@@ -370,13 +365,7 @@ 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;
|
||||
@@ -691,29 +680,6 @@ 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,11 +305,6 @@ 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",
|
||||
|
||||
@@ -7136,9 +7136,6 @@
|
||||
"community_forums": "View blueprints on the community forums",
|
||||
"url": "Blueprint address",
|
||||
"raw_blueprint": "Blueprint content",
|
||||
"raw_blueprint_description": "Check the code before you import it.",
|
||||
"view_raw_blueprint": "View",
|
||||
"view_raw_blueprint_label": "View blueprint content",
|
||||
"importing": "Loading blueprint…",
|
||||
"import_btn": "Preview",
|
||||
"saving": "Importing blueprint…",
|
||||
@@ -7619,6 +7616,7 @@
|
||||
},
|
||||
"remote": {
|
||||
"title": "Remote access",
|
||||
"card_title": "Remote connection",
|
||||
"connected": "Connected",
|
||||
"not_connected": "Not connected",
|
||||
"reconnecting": "Not connected. Trying to reconnect.",
|
||||
@@ -8268,7 +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 on {name} and may stop working.}\n other {depend on {name} and may stop working.}\n}",
|
||||
"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",
|
||||
|
||||
@@ -1,109 +0,0 @@
|
||||
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",
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,49 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
cancelEnteringFullscreen,
|
||||
claimFullscreenEnterHide,
|
||||
FULLSCREEN_ENTER_TIME,
|
||||
isEnteringFullscreen,
|
||||
startEnteringFullscreen,
|
||||
} from "../../../src/common/dom/entering-fullscreen";
|
||||
|
||||
describe("entering-fullscreen", () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("lets each stream through one hidden page per entering", () => {
|
||||
const streamA = {};
|
||||
const streamB = {};
|
||||
|
||||
expect(claimFullscreenEnterHide(streamA)).toBe(false);
|
||||
|
||||
// Each stream once, and the window counts from the last claim
|
||||
startEnteringFullscreen();
|
||||
vi.advanceTimersByTime(FULLSCREEN_ENTER_TIME - 100);
|
||||
expect(claimFullscreenEnterHide(streamA)).toBe(true);
|
||||
expect(claimFullscreenEnterHide(streamA)).toBe(false);
|
||||
vi.advanceTimersByTime(FULLSCREEN_ENTER_TIME - 100);
|
||||
expect(claimFullscreenEnterHide(streamB)).toBe(true);
|
||||
vi.advanceTimersByTime(FULLSCREEN_ENTER_TIME);
|
||||
expect(isEnteringFullscreen()).toBe(false);
|
||||
expect(claimFullscreenEnterHide({})).toBe(false);
|
||||
|
||||
// Expired before any claim
|
||||
startEnteringFullscreen();
|
||||
vi.advanceTimersByTime(FULLSCREEN_ENTER_TIME);
|
||||
expect(claimFullscreenEnterHide(streamA)).toBe(false);
|
||||
|
||||
startEnteringFullscreen();
|
||||
cancelEnteringFullscreen();
|
||||
expect(claimFullscreenEnterHide(streamA)).toBe(false);
|
||||
|
||||
// A new entering lets the same stream through again
|
||||
startEnteringFullscreen();
|
||||
expect(claimFullscreenEnterHide(streamA)).toBe(true);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user