mirror of
https://github.com/home-assistant/frontend.git
synced 2026-11-26 14:49:00 +00:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
daa11d4033 | ||
|
|
4657adc2bd | ||
|
|
116afd2065 | ||
|
|
6929509967 | ||
|
|
39a8832c53 | ||
|
|
89b954f04f | ||
|
|
c2432ddf86 |
No files matched your search
@@ -70,32 +70,6 @@ const ENTITIES = [
|
||||
CoverEntityFeature.CLOSE_TILT,
|
||||
},
|
||||
},
|
||||
{
|
||||
entity_id: "cover.tilt_only_closed",
|
||||
state: "closed",
|
||||
attributes: {
|
||||
friendly_name: "Tilt-only blind closed",
|
||||
device_class: "blind",
|
||||
assumed_state: true,
|
||||
supported_features:
|
||||
CoverEntityFeature.OPEN_TILT +
|
||||
CoverEntityFeature.STOP_TILT +
|
||||
CoverEntityFeature.CLOSE_TILT,
|
||||
},
|
||||
},
|
||||
{
|
||||
entity_id: "cover.tilt_only_open",
|
||||
state: "open",
|
||||
attributes: {
|
||||
friendly_name: "Tilt-only blind open",
|
||||
device_class: "blind",
|
||||
assumed_state: true,
|
||||
supported_features:
|
||||
CoverEntityFeature.OPEN_TILT +
|
||||
CoverEntityFeature.STOP_TILT +
|
||||
CoverEntityFeature.CLOSE_TILT,
|
||||
},
|
||||
},
|
||||
{
|
||||
entity_id: "cover.tilt_slider_half",
|
||||
state: "on",
|
||||
|
||||
+2
-2
@@ -126,9 +126,9 @@
|
||||
"matchPackageNames": ["echarts", "zrender"]
|
||||
},
|
||||
{
|
||||
"description": "Group formatjs monorepo packages",
|
||||
"description": "Group formatjs monorepo package",
|
||||
"groupName": "formatjs",
|
||||
"matchPackageNames": ["@formatjs/**", "intl-messageformat"]
|
||||
"matchPackageNames": ["@formatjs/**"]
|
||||
},
|
||||
{
|
||||
"description": "Group Playwright package and CI container updates",
|
||||
|
||||
@@ -235,7 +235,7 @@ export class HaCameraPlayer extends LitElement {
|
||||
const aspectRatio = this._aspectRatio();
|
||||
if (aspectRatio !== this._firedAspectRatio) {
|
||||
this._firedAspectRatio = aspectRatio;
|
||||
fireEvent(this, "media-size-changed", { aspectRatio });
|
||||
fireEvent(this, "camera-aspect-ratio-changed", { aspectRatio });
|
||||
}
|
||||
if (changedProps.has("keepAwake")) {
|
||||
if (this.keepAwake) {
|
||||
@@ -1189,7 +1189,6 @@ declare global {
|
||||
"ha-camera-player": HaCameraPlayer;
|
||||
}
|
||||
interface HASSDomEvents {
|
||||
/** The natural width limits the picture's width when it is set */
|
||||
"media-size-changed": { aspectRatio: number; naturalWidth?: number };
|
||||
"camera-aspect-ratio-changed": { aspectRatio: number };
|
||||
}
|
||||
}
|
||||
@@ -179,10 +179,6 @@ export class HaControlCircularSlider extends LitElement {
|
||||
|
||||
disconnectedCallback(): void {
|
||||
super.disconnectedCallback();
|
||||
this._destroyListeners();
|
||||
if (this._activeSlider) {
|
||||
this._cancelInteraction();
|
||||
}
|
||||
}
|
||||
|
||||
private _managers: HammerManager[] = [];
|
||||
@@ -252,18 +248,6 @@ export class HaControlCircularSlider extends LitElement {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
private _cancelInteraction() {
|
||||
if (this._activeSlider) {
|
||||
fireEvent(this, `${this._activeSlider}-changing`, {
|
||||
value: undefined,
|
||||
});
|
||||
}
|
||||
this._activeSlider = undefined;
|
||||
this._localValue = this.value;
|
||||
this._localLow = this.low;
|
||||
this._localHigh = this.high;
|
||||
}
|
||||
|
||||
private _setupListeners() {
|
||||
if (this._interactions && this._managers.length === 0) {
|
||||
this._interactions.forEach((interaction) => {
|
||||
@@ -295,7 +279,15 @@ export class HaControlCircularSlider extends LitElement {
|
||||
mc.add(new Tap({ event: "singletap" }));
|
||||
|
||||
const cancelInteraction = () => {
|
||||
this._cancelInteraction();
|
||||
if (this._activeSlider) {
|
||||
fireEvent(this, `${this._activeSlider}-changing`, {
|
||||
value: undefined,
|
||||
});
|
||||
}
|
||||
this._activeSlider = undefined;
|
||||
this._localValue = this.value;
|
||||
this._localLow = this.low;
|
||||
this._localHigh = this.high;
|
||||
if (pressToActivate) {
|
||||
panRecognizer.set({ enable: false });
|
||||
}
|
||||
|
||||
@@ -238,7 +238,6 @@ export class HaGridSizeEditor extends LitElement {
|
||||
grid-template-rows: auto auto;
|
||||
grid-template-columns: auto 1fr;
|
||||
gap: var(--ha-space-2);
|
||||
padding-left: var(--ha-space-4);
|
||||
}
|
||||
.precise {
|
||||
grid-area: precise;
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import type { PropertyValues, TemplateResult } from "lit";
|
||||
import type { TemplateResult } from "lit";
|
||||
import { LitElement, css, html, nothing } from "lit";
|
||||
import { customElement, property } from "lit/decorators";
|
||||
import { ifDefined } from "lit/directives/if-defined";
|
||||
import type { ActionHandlerOptions } from "../../data/lovelace/action_handler";
|
||||
import { actionHandlerBind } from "../../panels/lovelace/common/directives/action-handler-directive";
|
||||
import { actionHandler } from "../../panels/lovelace/common/directives/action-handler-directive";
|
||||
import "../ha-icon";
|
||||
import "../ha-svg-icon";
|
||||
|
||||
@@ -56,11 +56,6 @@ export class HaTileIcon extends LitElement {
|
||||
return nothing;
|
||||
}
|
||||
|
||||
protected updated(changedProps: PropertyValues<this>): void {
|
||||
super.updated(changedProps);
|
||||
actionHandlerBind(this, this.actionHandlerOptions);
|
||||
}
|
||||
|
||||
protected render(): TemplateResult {
|
||||
const hasImage = Boolean(this.imageUrl);
|
||||
|
||||
@@ -72,6 +67,7 @@ export class HaTileIcon extends LitElement {
|
||||
aria-label=${ifDefined(
|
||||
this.interactive ? this.accessibleLabel : undefined
|
||||
)}
|
||||
.actionHandler=${actionHandler(this.actionHandlerOptions)}
|
||||
>
|
||||
<slot name="icon">${this._renderIcon()}</slot>
|
||||
</div>
|
||||
@@ -98,7 +94,6 @@ export class HaTileIcon extends LitElement {
|
||||
:host([interactive]) {
|
||||
-webkit-tap-highlight-color: transparent;
|
||||
pointer-events: auto;
|
||||
cursor: pointer;
|
||||
}
|
||||
:host([interactive]:active) {
|
||||
transform: scale(1.2);
|
||||
@@ -148,9 +143,6 @@ export class HaTileIcon extends LitElement {
|
||||
transition: color 180ms ease-in-out;
|
||||
pointer-events: none;
|
||||
}
|
||||
::slotted(:not([slot])) {
|
||||
pointer-events: none;
|
||||
}
|
||||
.container img {
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
|
||||
@@ -5,9 +5,6 @@ import {
|
||||
} from "home-assistant-js-websocket";
|
||||
import type { Store } from "home-assistant-js-websocket/dist/store";
|
||||
import type { DataTableRowData } from "../components/data-table/ha-data-table";
|
||||
import type { HomeAssistant } from "../types";
|
||||
import type { ConfigEntry } from "./config_entries";
|
||||
import type { DeviceRegistryEntry } from "./device/device_registry";
|
||||
|
||||
export interface BluetoothDeviceData extends DataTableRowData {
|
||||
address: string;
|
||||
@@ -77,54 +74,6 @@ export const isScannerStateMismatch = (state: BluetoothScannerState): boolean =>
|
||||
state.requested_mode !== "auto" &&
|
||||
state.current_mode !== state.requested_mode;
|
||||
|
||||
export interface BluetoothAdapterDevice {
|
||||
device: DeviceRegistryEntry;
|
||||
entry: ConfigEntry;
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits the Bluetooth adapters into enabled and disabled ones. An adapter is
|
||||
* a device with a Bluetooth connection that belongs to a `bluetooth` config
|
||||
* entry. Config entries without such a device (for example ignored discoveries
|
||||
* or removed proxies) are not adapters, unless they are disabled, so they can
|
||||
* still be enabled again.
|
||||
*/
|
||||
export const getBluetoothAdapters = (
|
||||
devices: HomeAssistant["devices"],
|
||||
configEntries: ConfigEntry[]
|
||||
) => {
|
||||
const entryMap = new Map(configEntries.map((e) => [e.entry_id, e]));
|
||||
|
||||
const enabledDevices: BluetoothAdapterDevice[] = [];
|
||||
const disabledDevices: BluetoothAdapterDevice[] = [];
|
||||
const matchedEntryIds = new Set<string>();
|
||||
|
||||
for (const device of Object.values(devices)) {
|
||||
const btConnection = device.connections.find((c) => c[0] === "bluetooth");
|
||||
if (!btConnection) {
|
||||
continue;
|
||||
}
|
||||
const entry = device.config_entries
|
||||
.map((id) => entryMap.get(id))
|
||||
.find((e) => e !== undefined);
|
||||
if (!entry) {
|
||||
continue;
|
||||
}
|
||||
matchedEntryIds.add(entry.entry_id);
|
||||
if (entry.disabled_by !== null) {
|
||||
disabledDevices.push({ device, entry });
|
||||
} else {
|
||||
enabledDevices.push({ device, entry });
|
||||
}
|
||||
}
|
||||
|
||||
const disabledEntriesWithoutDevice = configEntries.filter(
|
||||
(e) => e.disabled_by !== null && !matchedEntryIds.has(e.entry_id)
|
||||
);
|
||||
|
||||
return { enabledDevices, disabledDevices, disabledEntriesWithoutDevice };
|
||||
};
|
||||
|
||||
export const subscribeBluetoothScannersDetailsUpdates = (
|
||||
conn: Connection,
|
||||
store: Store<BluetoothScannersDetails>
|
||||
|
||||
+5
-19
@@ -239,29 +239,12 @@ export interface CoverEntity extends HassEntityBase {
|
||||
attributes: CoverEntityAttributes;
|
||||
}
|
||||
|
||||
// For covers that report no value, the open or closed state tells where it is
|
||||
const valueFromState = (stateObj: CoverEntity): number | undefined => {
|
||||
if (stateObj.state === UNKNOWN || stateObj.state === UNAVAILABLE) {
|
||||
return undefined;
|
||||
}
|
||||
return stateObj.state === "closed" || stateObj.state === "opening" ? 0 : 100;
|
||||
};
|
||||
|
||||
export const coverCurrentValue = (
|
||||
stateObj: CoverEntity,
|
||||
mode: CoverControlMode
|
||||
): number | undefined => {
|
||||
if (mode === "tilt") {
|
||||
const tilt = stateObj.attributes.current_tilt_position;
|
||||
// The state only describes the slats when the cover can't move up or down
|
||||
if (
|
||||
tilt != null ||
|
||||
coverSupportsTiltPosition(stateObj) ||
|
||||
coverHasPositionControls(stateObj)
|
||||
) {
|
||||
return tilt ?? undefined;
|
||||
}
|
||||
return valueFromState(stateObj);
|
||||
return stateObj.attributes.current_tilt_position ?? undefined;
|
||||
}
|
||||
const position = stateObj.attributes.current_position;
|
||||
if (
|
||||
@@ -270,7 +253,10 @@ export const coverCurrentValue = (
|
||||
) {
|
||||
return position ?? undefined;
|
||||
}
|
||||
return valueFromState(stateObj);
|
||||
if (stateObj.state === UNKNOWN || stateObj.state === UNAVAILABLE) {
|
||||
return undefined;
|
||||
}
|
||||
return stateObj.state === "closed" || stateObj.state === "opening" ? 0 : 100;
|
||||
};
|
||||
|
||||
declare global {
|
||||
|
||||
@@ -3,11 +3,8 @@ import {
|
||||
mdiImageMultipleOutline,
|
||||
mdiLightningBolt,
|
||||
} from "@mdi/js";
|
||||
import type { ContextType } from "@lit/context";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, state } from "lit/decorators";
|
||||
import { isComponentLoaded } from "../../common/config/is_component_loaded";
|
||||
import { consume } from "../../common/decorators/consume";
|
||||
import { consumeLocalize } from "../../common/decorators/consume-context-entry";
|
||||
import type { LocalizeFunc } from "../../common/translations/localize";
|
||||
import { CAMERA_STREAM_TYPE_NAMES } from "../../components/camera/ha-camera-stream-badge";
|
||||
@@ -24,8 +21,6 @@ import {
|
||||
type CameraStreamType,
|
||||
type StreamType,
|
||||
} from "../../data/camera-streams";
|
||||
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";
|
||||
@@ -45,34 +40,6 @@ class DialogCameraStreamInfo extends DialogMixin<CameraStreamInfoDialogParams>(
|
||||
@consumeLocalize()
|
||||
private _localize!: LocalizeFunc;
|
||||
|
||||
@consume({ context: apiContext })
|
||||
private _api!: ContextType<typeof apiContext>;
|
||||
|
||||
@consume({ context: configContext })
|
||||
private _hassConfig!: ContextType<typeof configContext>;
|
||||
|
||||
@state() private _cloudIceServers = false;
|
||||
|
||||
protected firstUpdated() {
|
||||
this._fetchCloudIceServers();
|
||||
}
|
||||
|
||||
// The same check that core uses to add the cloud TURN servers
|
||||
private async _fetchCloudIceServers() {
|
||||
if (!isComponentLoaded(this._hassConfig.config, "cloud")) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const status = await fetchCloudStatus(this._api.callWS);
|
||||
this._cloudIceServers =
|
||||
status.logged_in &&
|
||||
status.active_subscription &&
|
||||
status.prefs.cloud_ice_servers_enabled;
|
||||
} catch (_err) {
|
||||
// Without the cloud status the label stays hidden
|
||||
}
|
||||
}
|
||||
|
||||
protected render() {
|
||||
if (!this.params) {
|
||||
return nothing;
|
||||
@@ -157,18 +124,6 @@ class DialogCameraStreamInfo extends DialogMixin<CameraStreamInfoDialogParams>(
|
||||
wrap-supporting-text
|
||||
>
|
||||
<ha-svg-icon slot="start" .path=${icon}></ha-svg-icon>
|
||||
${
|
||||
type === STREAM_TYPE_WEB_RTC && this._cloudIceServers
|
||||
? html`<span slot="headline" class="headline">
|
||||
${CAMERA_STREAM_TYPE_NAMES[type]}
|
||||
<span class="tag cloud"
|
||||
>${this._localize(
|
||||
"ui.dialogs.camera_stream_info.enhanced_by_cloud"
|
||||
)}</span
|
||||
>
|
||||
</span>`
|
||||
: nothing
|
||||
}
|
||||
${
|
||||
current
|
||||
? html`<span slot="end" class="tag current"
|
||||
@@ -233,20 +188,6 @@ class DialogCameraStreamInfo extends DialogMixin<CameraStreamInfoDialogParams>(
|
||||
color: var(--secondary-text-color);
|
||||
}
|
||||
|
||||
.headline {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
gap: var(--ha-space-2);
|
||||
/* The row keeps the headline on one line, but a long tag must wrap */
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.tag.cloud {
|
||||
background-color: var(--ha-color-fill-primary-quiet-resting);
|
||||
color: var(--ha-color-on-primary-quiet);
|
||||
}
|
||||
|
||||
.tag.current {
|
||||
background-color: var(--ha-color-fill-success-quiet-resting);
|
||||
color: var(--ha-color-on-success-quiet);
|
||||
|
||||
@@ -2,8 +2,6 @@ import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { consume } from "../../../common/decorators/consume";
|
||||
import { transform } from "../../../common/decorators/transform";
|
||||
import type { HASSDomCurrentTargetEvent } from "../../../common/dom/fire_event";
|
||||
import { fireEvent } from "../../../common/dom/fire_event";
|
||||
import { connectionContext, formattersContext } from "../../../data/context";
|
||||
import type { ImageEntity } from "../../../data/image";
|
||||
import { computeImageUrl } from "../../../data/image";
|
||||
@@ -30,17 +28,6 @@ class MoreInfoImage extends LitElement {
|
||||
|
||||
@property({ attribute: false }) public stateObj?: ImageEntity;
|
||||
|
||||
private _size?: HASSDomEvents["media-size-changed"];
|
||||
|
||||
public connectedCallback() {
|
||||
super.connectedCallback();
|
||||
// A cached view that was detached while the picture loaded couldn't send
|
||||
// its size, and the picture doesn't load again when it's shown
|
||||
if (this._size) {
|
||||
fireEvent(this, "media-size-changed", this._size);
|
||||
}
|
||||
}
|
||||
|
||||
protected render() {
|
||||
if (!this._connection || !this.stateObj) {
|
||||
return nothing;
|
||||
@@ -52,28 +39,16 @@ class MoreInfoImage extends LitElement {
|
||||
return html`<img
|
||||
alt=${this._formatEntityName?.(this.stateObj) || this.stateObj.entity_id}
|
||||
src=${this._connection.hassUrl(imageUrl)}
|
||||
@load=${this._imageLoaded}
|
||||
/> `;
|
||||
}
|
||||
|
||||
private _imageLoaded(ev: HASSDomCurrentTargetEvent<HTMLImageElement>) {
|
||||
const { naturalWidth, naturalHeight } = ev.currentTarget;
|
||||
if (!naturalWidth || !naturalHeight) {
|
||||
return;
|
||||
}
|
||||
this._size = { aspectRatio: naturalWidth / naturalHeight, naturalWidth };
|
||||
fireEvent(this, "media-size-changed", this._size);
|
||||
}
|
||||
|
||||
static styles = css`
|
||||
:host {
|
||||
display: block;
|
||||
text-align: center;
|
||||
}
|
||||
img {
|
||||
display: block;
|
||||
margin: 0 auto;
|
||||
max-width: 100%;
|
||||
max-height: var(--more-info-media-max-height, none);
|
||||
}
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -149,12 +149,10 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
|
||||
@property({ type: Boolean, reflect: true }) public large = false;
|
||||
|
||||
// The dialog grows with the camera's or image's picture, as high as there
|
||||
// is room for
|
||||
@state() private _mediaAspectRatio?: number;
|
||||
@state() private _fill = false;
|
||||
|
||||
// An image is not shown larger than it is
|
||||
@state() private _mediaNaturalWidth?: number;
|
||||
// The dialog grows with the camera's picture, as high as there is room for
|
||||
@state() private _cameraAspectRatio?: number;
|
||||
|
||||
// Height of the controls the camera's info shows below the picture
|
||||
@state() private _cameraControlsHeight?: string;
|
||||
@@ -198,6 +196,12 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
}
|
||||
|
||||
public showDialog(params: MoreInfoDialogParams) {
|
||||
// The camera player keeps running for the same entity and doesn't send
|
||||
// its size again
|
||||
if (params.entityId !== this._entityId) {
|
||||
this._cameraAspectRatio = undefined;
|
||||
this._cameraControlsHeight = undefined;
|
||||
}
|
||||
this._entityId = params.entityId;
|
||||
if (!this._entityId) {
|
||||
this.closeDialog();
|
||||
@@ -215,6 +219,7 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
this._detailsYamlMode = false;
|
||||
|
||||
this.large = params.large ?? false;
|
||||
this._fill = false;
|
||||
this._open = true;
|
||||
this._loadEntityRegistryEntry();
|
||||
}
|
||||
@@ -260,6 +265,8 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
this._currView = DEFAULT_VIEW;
|
||||
this._childViewStack = [];
|
||||
this._returnUrl = undefined;
|
||||
this._cameraAspectRatio = undefined;
|
||||
this._cameraControlsHeight = undefined;
|
||||
this._isEscapeEnabled = true;
|
||||
window.removeEventListener("dialog-closed", this._enableEscapeKeyClose);
|
||||
window.removeEventListener("show-dialog", this._disableEscapeKeyClose);
|
||||
@@ -684,32 +691,30 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
`
|
||||
: nothing;
|
||||
|
||||
// Also when it was opened from a smaller entity's related view
|
||||
const mediaAspectRatio =
|
||||
(domain === "camera" || domain === "image") && isDefaultView
|
||||
? this._mediaAspectRatio
|
||||
// Also when the camera was opened from a smaller entity's related view
|
||||
const cameraAspectRatio =
|
||||
domain === "camera" && isDefaultView
|
||||
? this._cameraAspectRatio
|
||||
: undefined;
|
||||
// As wide as the picture is when it's as high as there is room for
|
||||
const fullHeightWidth = `var(--more-info-media-max-height) * ${mediaAspectRatio}`;
|
||||
const mediaPictureWidth = this._mediaNaturalWidth
|
||||
? `min(${fullHeightWidth}, ${this._mediaNaturalWidth}px)`
|
||||
: fullHeightWidth;
|
||||
|
||||
return html`
|
||||
<ha-adaptive-dialog
|
||||
.open=${this._open}
|
||||
.width=${this.large || mediaAspectRatio ? "large" : "medium"}
|
||||
class=${classMap({
|
||||
camera: domain === "camera",
|
||||
image: domain === "image",
|
||||
})}
|
||||
.width=${
|
||||
this._fill
|
||||
? "full"
|
||||
: this.large || cameraAspectRatio
|
||||
? "large"
|
||||
: "medium"
|
||||
}
|
||||
class=${classMap({ camera: domain === "camera" })}
|
||||
style=${styleMap({
|
||||
"--more-info-camera-controls-height": this._cameraControlsHeight,
|
||||
"--ha-dialog-width-lg": mediaAspectRatio
|
||||
? `clamp(var(--ha-dialog-width-md, 580px), calc(${mediaPictureWidth} + var(--more-info-media-inline-padding, 0px)), 1920px)`
|
||||
"--ha-dialog-width-lg": cameraAspectRatio
|
||||
? `clamp(var(--ha-dialog-width-md, 580px), calc(var(--video-max-height) * ${cameraAspectRatio}), 1920px)`
|
||||
: undefined,
|
||||
})}
|
||||
@media-size-changed=${this._mediaSizeChanged}
|
||||
@camera-aspect-ratio-changed=${this._cameraAspectRatioChanged}
|
||||
@camera-controls-height-changed=${this._cameraControlsHeightChanged}
|
||||
.accessibleLabel=${title}
|
||||
@closed=${this._dialogClosed}
|
||||
@@ -742,7 +747,7 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
></ha-icon-button-prev>
|
||||
`
|
||||
}
|
||||
<span slot="headerTitle" class="title">
|
||||
<span slot="headerTitle" @click=${this._enlarge} class="title">
|
||||
${
|
||||
breadcrumb.length > 0
|
||||
? !__DEMO__ && isAdmin
|
||||
@@ -1066,17 +1071,6 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
`;
|
||||
}
|
||||
|
||||
protected willUpdate(changedProps: PropertyValues) {
|
||||
super.willUpdate(changedProps);
|
||||
// Also when going to a related entity or back. The camera player or image
|
||||
// of the same entity keeps running and doesn't send its size again.
|
||||
if (changedProps.has("_entityId")) {
|
||||
this._mediaAspectRatio = undefined;
|
||||
this._mediaNaturalWidth = undefined;
|
||||
this._cameraControlsHeight = undefined;
|
||||
}
|
||||
}
|
||||
|
||||
protected firstUpdated(changedProps: PropertyValues<this>) {
|
||||
super.firstUpdated(changedProps);
|
||||
this.addEventListener("close-dialog", () => this.closeDialog());
|
||||
@@ -1146,11 +1140,10 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
this._entry = ev.detail;
|
||||
}
|
||||
|
||||
private _mediaSizeChanged(
|
||||
ev: HASSDomEvent<HASSDomEvents["media-size-changed"]>
|
||||
private _cameraAspectRatioChanged(
|
||||
ev: HASSDomEvent<HASSDomEvents["camera-aspect-ratio-changed"]>
|
||||
) {
|
||||
this._mediaAspectRatio = ev.detail.aspectRatio;
|
||||
this._mediaNaturalWidth = ev.detail.naturalWidth;
|
||||
this._cameraAspectRatio = ev.detail.aspectRatio;
|
||||
}
|
||||
|
||||
private _cameraControlsHeightChanged(
|
||||
@@ -1159,6 +1152,12 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
this._cameraControlsHeight = ev.detail.height;
|
||||
}
|
||||
|
||||
private _enlarge() {
|
||||
withViewTransition(() => {
|
||||
this._fill = !this._fill;
|
||||
});
|
||||
}
|
||||
|
||||
private _handleOpened() {
|
||||
window.addEventListener("dialog-closed", this._enableEscapeKeyClose);
|
||||
window.addEventListener("show-dialog", this._disableEscapeKeyClose);
|
||||
@@ -1217,14 +1216,12 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
--dialog-content-padding: 0;
|
||||
}
|
||||
|
||||
/* The dialog's margin, the safe area like the dialog's height limit,
|
||||
its header of about 68px and what the info shows besides the
|
||||
picture */
|
||||
ha-adaptive-dialog.camera,
|
||||
ha-adaptive-dialog.image {
|
||||
--more-info-media-max-height: calc(
|
||||
100vh - var(--ha-space-20) - var(--safe-area-inset-y, 0px) -
|
||||
68px - var(--more-info-media-reserved-height, 0px)
|
||||
/* The dialog's margin, its header of about 68px and the controls
|
||||
below the picture */
|
||||
ha-adaptive-dialog.camera {
|
||||
--video-max-height: calc(
|
||||
100vh - var(--ha-space-20) -
|
||||
68px - var(--more-info-camera-controls-height, 0px)
|
||||
);
|
||||
/* Along with the height of the picture */
|
||||
--ha-dialog-width-transition:
|
||||
@@ -1235,33 +1232,14 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
|
||||
/* A custom property takes any value, so it can't fall back to the
|
||||
declaration before it. svh like the height limit of the dialog. */
|
||||
@supports (height: 1svh) {
|
||||
ha-adaptive-dialog.camera,
|
||||
ha-adaptive-dialog.image {
|
||||
--more-info-media-max-height: calc(
|
||||
100svh - var(--ha-space-20) - var(--safe-area-inset-y, 0px) -
|
||||
68px - var(--more-info-media-reserved-height, 0px)
|
||||
ha-adaptive-dialog.camera {
|
||||
--video-max-height: calc(
|
||||
100svh - var(--ha-space-20) -
|
||||
68px - var(--more-info-camera-controls-height, 0px)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
ha-adaptive-dialog.camera {
|
||||
--more-info-media-reserved-height: var(
|
||||
--more-info-camera-controls-height,
|
||||
0px
|
||||
);
|
||||
--video-max-height: var(--more-info-media-max-height);
|
||||
}
|
||||
|
||||
/* The info's padding around the picture and the entity's row of 40px
|
||||
above it, with 16px between them */
|
||||
ha-adaptive-dialog.image {
|
||||
--more-info-media-reserved-height: calc(
|
||||
var(--ha-space-6) +
|
||||
max(var(--safe-area-inset-bottom, 0px), var(--ha-space-6)) + 56px
|
||||
);
|
||||
--more-info-media-inline-padding: calc(var(--ha-space-6) * 2);
|
||||
}
|
||||
|
||||
.content-wrapper {
|
||||
flex: 1 1 auto;
|
||||
min-height: 0;
|
||||
|
||||
@@ -95,23 +95,6 @@ class DialogStartupProgress extends DialogMixin(LitElement) {
|
||||
.slice(0, MAX_SLOWEST);
|
||||
});
|
||||
}
|
||||
if (changedProps.has("_progress") || changedProps.has("_setups")) {
|
||||
this._loadTitles();
|
||||
}
|
||||
}
|
||||
|
||||
private _loadTitles() {
|
||||
const progress = this._progress
|
||||
? this._computeProgress(this._progress, this._config.config.state)
|
||||
: undefined;
|
||||
const domains = [
|
||||
...(progress?.active.map(([domain]) => domain) ?? []),
|
||||
...(progress?.failed ?? []),
|
||||
...(this._setups?.map((setup) => setup.domain) ?? []),
|
||||
];
|
||||
if (domains.length) {
|
||||
this._i18n.loadBackendTranslation("title", domains);
|
||||
}
|
||||
}
|
||||
|
||||
protected render() {
|
||||
|
||||
@@ -1,21 +1,9 @@
|
||||
import { supportsFeatureFromAttributes } from "../../common/entity/supports-feature";
|
||||
import {
|
||||
CLIMATE_HVAC_ACTION_TO_MODE,
|
||||
ClimateEntityFeature,
|
||||
} from "../../data/climate";
|
||||
import { ClimateEntityFeature } from "../../data/climate";
|
||||
import type { HvacAction } from "../../data/climate";
|
||||
import { MockBaseEntity } from "./base-entity";
|
||||
import type { EntityAttributes } from "./types";
|
||||
|
||||
// Reverse mapping: mode → action (e.g. "cool" → "cooling")
|
||||
const HVAC_MODE_TO_ACTION: Partial<Record<string, HvacAction>> =
|
||||
Object.fromEntries(
|
||||
Object.entries(CLIMATE_HVAC_ACTION_TO_MODE).map(([action, mode]) => [
|
||||
mode,
|
||||
action as HvacAction,
|
||||
])
|
||||
);
|
||||
|
||||
export class MockClimateEntity extends MockBaseEntity {
|
||||
public async handleService(
|
||||
domain: string,
|
||||
@@ -243,10 +231,13 @@ export class MockClimateEntity extends MockBaseEntity {
|
||||
return "off";
|
||||
}
|
||||
|
||||
// Use the reverse mapping for direct mode → action (e.g. "fan_only" → "fan", "dry" → "drying")
|
||||
const directAction = HVAC_MODE_TO_ACTION[state];
|
||||
if (directAction && directAction !== "idle" && directAction !== "off") {
|
||||
return directAction;
|
||||
// Heat and cool get their action from the temperatures below
|
||||
if (state === "dry") {
|
||||
return "drying";
|
||||
}
|
||||
|
||||
if (state === "fan_only") {
|
||||
return "fan";
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -276,13 +267,17 @@ export class MockClimateEntity extends MockBaseEntity {
|
||||
const current = attrs.current_temperature;
|
||||
const lowTarget = attrs.target_temp_low;
|
||||
const highTarget = attrs.target_temp_high;
|
||||
// Heat mode can only heat and cool mode only cool, while auto and
|
||||
// heat_cool use both ends of the range
|
||||
if (current != null) {
|
||||
if (lowTarget != null && lowTarget > current) {
|
||||
if (state !== "cool" && lowTarget != null && lowTarget > current) {
|
||||
return "heating";
|
||||
}
|
||||
if (highTarget != null && highTarget < current) {
|
||||
|
||||
if (state !== "heat" && highTarget != null && highTarget < current) {
|
||||
return "cooling";
|
||||
}
|
||||
|
||||
return "idle";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -607,6 +607,22 @@ export const ENTITY_COMPONENT_ICONS: Record<string, ComponentIcons> = {
|
||||
atmospheric_pressure: {
|
||||
default: "mdi:thermometer-lines",
|
||||
},
|
||||
battery: {
|
||||
default: "mdi:battery-unknown",
|
||||
range: {
|
||||
"0": "mdi:battery-alert",
|
||||
"10": "mdi:battery-10",
|
||||
"20": "mdi:battery-20",
|
||||
"30": "mdi:battery-30",
|
||||
"40": "mdi:battery-40",
|
||||
"50": "mdi:battery-50",
|
||||
"60": "mdi:battery-60",
|
||||
"70": "mdi:battery-70",
|
||||
"80": "mdi:battery-80",
|
||||
"90": "mdi:battery-90",
|
||||
"100": "mdi:battery",
|
||||
},
|
||||
},
|
||||
carbon_dioxide: {
|
||||
default: "mdi:molecule-co2",
|
||||
},
|
||||
|
||||
@@ -27,6 +27,12 @@ import {
|
||||
import { updateHassGroups } from "../data/context/updateContext";
|
||||
import type { IconCategory } from "../data/icons";
|
||||
import type { EntityRegistryDisplayEntry } from "../data/entity/entity_registry";
|
||||
import { evaluateConditionsLocally } from "../common/condition/evaluate-locally";
|
||||
import {
|
||||
isLogicalCondition,
|
||||
logicalChildren,
|
||||
} from "../common/condition/translate";
|
||||
import type { VisibilityCondition } from "../panels/lovelace/common/validate-condition";
|
||||
import {
|
||||
DateFormat,
|
||||
FirstWeekday,
|
||||
@@ -53,6 +59,24 @@ import type { EntityInput } from "./entities/types";
|
||||
const ensureArray = <T>(val: T | T[]): T[] =>
|
||||
Array.isArray(val) ? val : [val];
|
||||
|
||||
// Core's `not` passes when none of its conditions pass, and the frontend's
|
||||
// unless all of them pass, so each `not` gets one `or` of its conditions
|
||||
const withCoreNot = (condition: VisibilityCondition): VisibilityCondition => {
|
||||
if (!isLogicalCondition(condition) || condition.conditions === undefined) {
|
||||
return condition;
|
||||
}
|
||||
|
||||
const conditions = logicalChildren(condition).map(withCoreNot);
|
||||
|
||||
return {
|
||||
...condition,
|
||||
conditions:
|
||||
condition.condition === "not"
|
||||
? [{ condition: "or", conditions }]
|
||||
: conditions,
|
||||
};
|
||||
};
|
||||
|
||||
type MockServiceCallback = (
|
||||
data: Record<string, any> | undefined,
|
||||
target: Record<string, any> | undefined,
|
||||
@@ -221,6 +245,8 @@ export const provideHass = (
|
||||
return lazyLoaderPromise;
|
||||
};
|
||||
const eventListeners: Record<string, ((event) => void)[]> = {};
|
||||
// Checks each subscribed condition again, for when the states change.
|
||||
const conditionChecks = new Set<() => void>();
|
||||
const entities = {};
|
||||
let localResources: Resources = {};
|
||||
|
||||
@@ -664,6 +690,51 @@ export const provideHass = (
|
||||
resources: category === "entity_component" ? ENTITY_COMPONENT_ICONS : {},
|
||||
}));
|
||||
|
||||
// Core answers the visibility conditions of cards and rows that depend on
|
||||
// states. Here they are checked against the mock states, as the frontend
|
||||
// does itself before Core answers, and again each time the states change.
|
||||
// A condition only Core can check, such as a template, gets an error, so
|
||||
// a `not` around it can't show the card.
|
||||
hassObj.mockWS(
|
||||
"subscribe_condition",
|
||||
({ condition }: { condition: VisibilityCondition }, _hass, onChange) => {
|
||||
const check = () => {
|
||||
const result = evaluateConditionsLocally(
|
||||
[withCoreNot(condition)],
|
||||
hass(),
|
||||
{}
|
||||
);
|
||||
|
||||
onChange?.(
|
||||
result === undefined
|
||||
? {
|
||||
error: {
|
||||
code: "not_supported",
|
||||
message: "The demo can't check this condition",
|
||||
},
|
||||
}
|
||||
: { result }
|
||||
);
|
||||
};
|
||||
|
||||
conditionChecks.add(check);
|
||||
check();
|
||||
|
||||
return () => conditionChecks.delete(check);
|
||||
}
|
||||
);
|
||||
|
||||
// Check the conditions again after each state update, also when the host
|
||||
// passed its own updateHass, as the demo does
|
||||
const applyUpdate = hassObj.updateHass;
|
||||
hassObj.updateHass = (obj: Partial<MockHomeAssistant>) => {
|
||||
applyUpdate(obj);
|
||||
|
||||
if (obj.states) {
|
||||
conditionChecks.forEach((check) => check());
|
||||
}
|
||||
};
|
||||
|
||||
// Set hass if required
|
||||
if (setHassProperty) {
|
||||
elements.forEach((el) => {
|
||||
|
||||
+46
-5
@@ -16,14 +16,12 @@ import "../../../../../components/item/ha-list-item-base";
|
||||
import "../../../../../components/item/ha-list-item-button";
|
||||
import "../../../../../components/list/ha-list-base";
|
||||
import type {
|
||||
BluetoothAdapterDevice,
|
||||
BluetoothAllocationsData,
|
||||
BluetoothScannerState,
|
||||
BluetoothScannersDetails,
|
||||
HaScannerType,
|
||||
} from "../../../../../data/bluetooth";
|
||||
import {
|
||||
getBluetoothAdapters,
|
||||
isScannerStateMismatch,
|
||||
subscribeBluetoothConnectionAllocations,
|
||||
subscribeBluetoothScannerState,
|
||||
@@ -178,11 +176,52 @@ export class BluetoothAdapterInfoPage extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
private _getBluetoothAdapters = memoizeOne(getBluetoothAdapters);
|
||||
private _getBluetoothDevices = memoizeOne(
|
||||
(devices: HomeAssistant["devices"], configEntries: ConfigEntry[]) => {
|
||||
const entryMap = new Map(configEntries.map((e) => [e.entry_id, e]));
|
||||
|
||||
const enabledDevices: {
|
||||
device: DeviceRegistryEntry;
|
||||
entry: ConfigEntry;
|
||||
}[] = [];
|
||||
const disabledDevices: {
|
||||
device: DeviceRegistryEntry;
|
||||
entry: ConfigEntry;
|
||||
}[] = [];
|
||||
const matchedEntryIds = new Set<string>();
|
||||
|
||||
for (const device of Object.values(devices)) {
|
||||
const btConnection = device.connections.find(
|
||||
(c) => c[0] === "bluetooth"
|
||||
);
|
||||
if (!btConnection) {
|
||||
continue;
|
||||
}
|
||||
const entry = device.config_entries
|
||||
.map((id) => entryMap.get(id))
|
||||
.find((e) => e !== undefined);
|
||||
if (!entry) {
|
||||
continue;
|
||||
}
|
||||
matchedEntryIds.add(entry.entry_id);
|
||||
if (entry.disabled_by !== null) {
|
||||
disabledDevices.push({ device, entry });
|
||||
} else {
|
||||
enabledDevices.push({ device, entry });
|
||||
}
|
||||
}
|
||||
|
||||
const disabledEntriesWithoutDevice = configEntries.filter(
|
||||
(e) => e.disabled_by !== null && !matchedEntryIds.has(e.entry_id)
|
||||
);
|
||||
|
||||
return { enabledDevices, disabledDevices, disabledEntriesWithoutDevice };
|
||||
}
|
||||
);
|
||||
|
||||
protected render(): TemplateResult {
|
||||
const { enabledDevices, disabledDevices, disabledEntriesWithoutDevice } =
|
||||
this._getBluetoothAdapters(this.hass.devices, this._configEntries);
|
||||
this._getBluetoothDevices(this.hass.devices, this._configEntries);
|
||||
|
||||
return html`
|
||||
<hass-subpage
|
||||
@@ -262,7 +301,9 @@ export class BluetoothAdapterInfoPage extends LitElement {
|
||||
`;
|
||||
}
|
||||
|
||||
private _renderAdaptersList(devices: BluetoothAdapterDevice[]) {
|
||||
private _renderAdaptersList(
|
||||
devices: { device: DeviceRegistryEntry; entry: ConfigEntry }[]
|
||||
) {
|
||||
if (devices.length === 0) {
|
||||
return html`<ha-list-item-base>
|
||||
<div slot="headline">
|
||||
|
||||
+49
-122
@@ -11,24 +11,18 @@ import type { UnsubscribeFunc } from "home-assistant-js-websocket";
|
||||
import type { CSSResultGroup, TemplateResult } from "lit";
|
||||
import { LitElement, css, html } from "lit";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import memoizeOne from "memoize-one";
|
||||
import "../../../../../components/animation/ha-fade-in";
|
||||
import "../../../../../components/ha-alert";
|
||||
import "../../../../../components/ha-button";
|
||||
import "../../../../../components/ha-card";
|
||||
import "../../../../../components/ha-icon-next";
|
||||
import "../../../../../components/ha-svg-icon";
|
||||
import "../../../../../components/item/ha-list-item-button";
|
||||
import "../../../../../components/list/ha-list-nav";
|
||||
import "../../../../../components/skeleton/ha-skeleton";
|
||||
import "../../../../../components/skeleton/ha-skeleton-text";
|
||||
import type {
|
||||
BluetoothAllocationsData,
|
||||
BluetoothDeviceData,
|
||||
BluetoothScannerState,
|
||||
} from "../../../../../data/bluetooth";
|
||||
import {
|
||||
getBluetoothAdapters,
|
||||
isScannerStateMismatch,
|
||||
subscribeBluetoothAdvertisements,
|
||||
subscribeBluetoothConnectionAllocations,
|
||||
@@ -40,7 +34,6 @@ import "../../../../../layouts/hass-subpage";
|
||||
import { haStyle } from "../../../../../resources/styles";
|
||||
import type { HomeAssistant, Route } from "../../../../../types";
|
||||
import { brandsUrl } from "../../../../../util/brands-url";
|
||||
import { getWsErrorMessage } from "../../../../../util/ws-error";
|
||||
|
||||
@customElement("bluetooth-config-dashboard")
|
||||
export class BluetoothConfigDashboard extends LitElement {
|
||||
@@ -52,9 +45,7 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
|
||||
@property({ attribute: "is-wide", type: Boolean }) public isWide = false;
|
||||
|
||||
@state() private _configEntries?: ConfigEntry[];
|
||||
|
||||
@state() private _configEntriesError?: string;
|
||||
@state() private _configEntries: ConfigEntry[] = [];
|
||||
|
||||
@state() private _connectionAllocationData: BluetoothAllocationsData[] = [];
|
||||
|
||||
@@ -78,17 +69,11 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
private _loadConfigEntries = async (): Promise<void> => {
|
||||
this._configEntriesError = undefined;
|
||||
try {
|
||||
this._configEntries = await getConfigEntries(this.hass, {
|
||||
domain: "bluetooth",
|
||||
});
|
||||
} catch (err: unknown) {
|
||||
this._configEntriesError =
|
||||
getWsErrorMessage(err) || this.hass.localize("ui.common.unknown_error");
|
||||
}
|
||||
};
|
||||
private async _loadConfigEntries(): Promise<void> {
|
||||
this._configEntries = await getConfigEntries(this.hass, {
|
||||
domain: "bluetooth",
|
||||
});
|
||||
}
|
||||
|
||||
private async _subscribeBluetoothConnectionAllocations(): Promise<void> {
|
||||
if (this._unsubConnectionAllocations) {
|
||||
@@ -146,17 +131,11 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
}
|
||||
}
|
||||
|
||||
private _getBluetoothAdapters = memoizeOne(getBluetoothAdapters);
|
||||
|
||||
protected render(): TemplateResult {
|
||||
// The device registry is null until it has loaded.
|
||||
const adapterCount =
|
||||
this._configEntries && this.hass.devices
|
||||
? this._getBluetoothAdapters(this.hass.devices, this._configEntries)
|
||||
.enabledDevices.length
|
||||
: undefined;
|
||||
const error = this._configEntriesError;
|
||||
const loading = adapterCount === undefined && !error;
|
||||
const enabledEntries = this._configEntries.filter(
|
||||
(e) => e.disabled_by === null
|
||||
);
|
||||
const adapterCount = enabledEntries.length;
|
||||
const totalSlots = this._connectionAllocationData.reduce(
|
||||
(sum, a) => sum + a.slots,
|
||||
0
|
||||
@@ -184,67 +163,40 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
back-path="/config/connectivity"
|
||||
>
|
||||
<div class="container">
|
||||
${
|
||||
error
|
||||
? html`<ha-alert alert-type="error" class="content">
|
||||
${error}
|
||||
<ha-button
|
||||
slot="action"
|
||||
appearance="plain"
|
||||
@click=${this._loadConfigEntries}
|
||||
>
|
||||
${this.hass.localize("ui.common.retry")}
|
||||
</ha-button>
|
||||
</ha-alert>`
|
||||
: html`<ha-card class="content network-status">
|
||||
<div class="card-content">
|
||||
<div class="heading">
|
||||
${
|
||||
loading
|
||||
? html`<ha-fade-in .duration=${300} easing="ease-in">
|
||||
<ha-skeleton
|
||||
class="status-icon"
|
||||
role="progressbar"
|
||||
aria-label=${this.hass.localize("ui.common.loading")}
|
||||
></ha-skeleton>
|
||||
</ha-fade-in>`
|
||||
: html`<div class="icon ${status}">
|
||||
<ha-svg-icon .path=${statusIcon}></ha-svg-icon>
|
||||
</div>`
|
||||
}
|
||||
<div class="details">
|
||||
${
|
||||
loading
|
||||
? this._renderTextSkeleton()
|
||||
: this.hass.localize(
|
||||
`ui.panel.config.bluetooth.status_${status}`
|
||||
)
|
||||
}<br />
|
||||
<small>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.bluetooth.connections_summary",
|
||||
{ used: usedSlots, total: totalSlots }
|
||||
)}
|
||||
</small>
|
||||
</div>
|
||||
<img
|
||||
class="logo"
|
||||
alt="Bluetooth"
|
||||
crossorigin="anonymous"
|
||||
referrerpolicy="no-referrer"
|
||||
src=${brandsUrl(
|
||||
{
|
||||
domain: "bluetooth",
|
||||
type: "icon",
|
||||
darkOptimized: this.hass.themes?.darkMode,
|
||||
},
|
||||
this.hass.auth.data.hassUrl
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</ha-card>`
|
||||
}
|
||||
<ha-card class="content network-status">
|
||||
<div class="card-content">
|
||||
<div class="heading">
|
||||
<div class="icon ${status}">
|
||||
<ha-svg-icon .path=${statusIcon}></ha-svg-icon>
|
||||
</div>
|
||||
<div class="details">
|
||||
${this.hass.localize(
|
||||
`ui.panel.config.bluetooth.status_${status}`
|
||||
)}<br />
|
||||
<small>
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.bluetooth.connections_summary",
|
||||
{ used: usedSlots, total: totalSlots }
|
||||
)}
|
||||
</small>
|
||||
</div>
|
||||
<img
|
||||
class="logo"
|
||||
alt="Bluetooth"
|
||||
crossorigin="anonymous"
|
||||
referrerpolicy="no-referrer"
|
||||
src=${brandsUrl(
|
||||
{
|
||||
domain: "bluetooth",
|
||||
type: "icon",
|
||||
darkOptimized: this.hass.themes?.darkMode,
|
||||
},
|
||||
this.hass.auth.data.hassUrl
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</ha-card>
|
||||
|
||||
<ha-card class="network-card">
|
||||
<div class="card-header">
|
||||
@@ -272,17 +224,10 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
.path=${mdiAccessPoint}
|
||||
></ha-svg-icon>
|
||||
<div slot="headline">
|
||||
${
|
||||
// A link needs its name, so no skeleton while loading
|
||||
adapterCount === undefined
|
||||
? this.hass.localize(
|
||||
"ui.panel.config.bluetooth.adapter_info_title"
|
||||
)
|
||||
: this.hass.localize(
|
||||
"ui.panel.config.bluetooth.adapters_count",
|
||||
{ count: adapterCount }
|
||||
)
|
||||
}
|
||||
${this.hass.localize(
|
||||
"ui.panel.config.bluetooth.adapters_count",
|
||||
{ count: adapterCount }
|
||||
)}
|
||||
</div>
|
||||
<ha-icon-next slot="end"></ha-icon-next>
|
||||
</ha-list-item-button>
|
||||
@@ -323,15 +268,6 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
`;
|
||||
}
|
||||
|
||||
private _renderTextSkeleton() {
|
||||
return html`<ha-fade-in .duration=${300} easing="ease-in">
|
||||
<ha-skeleton-text
|
||||
role="progressbar"
|
||||
aria-label=${this.hass.localize("ui.common.loading")}
|
||||
></ha-skeleton-text>
|
||||
</ha-fade-in>`;
|
||||
}
|
||||
|
||||
static get styles(): CSSResultGroup {
|
||||
return [
|
||||
haStyle,
|
||||
@@ -340,9 +276,7 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
padding: var(--ha-space-2) var(--ha-content-gutter) var(--ha-space-4);
|
||||
}
|
||||
|
||||
ha-card,
|
||||
ha-alert {
|
||||
display: block;
|
||||
ha-card {
|
||||
margin: 0px auto var(--ha-space-4);
|
||||
max-width: var(--ha-content-width-narrow);
|
||||
}
|
||||
@@ -392,13 +326,6 @@ export class BluetoothConfigDashboard extends LitElement {
|
||||
--icon-color: var(--primary-color);
|
||||
}
|
||||
|
||||
.network-status div.heading .status-icon {
|
||||
display: block;
|
||||
width: var(--ha-space-10);
|
||||
height: var(--ha-space-10);
|
||||
--ha-skeleton-border-radius: var(--ha-border-radius-2xl);
|
||||
}
|
||||
|
||||
.network-status div.heading .icon.online {
|
||||
--icon-color: var(--success-color);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { ResizeController } from "@lit-labs/observers/resize-controller";
|
||||
import type { HassConfig } from "home-assistant-js-websocket";
|
||||
import type { PropertyValues } from "lit";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, state } from "lit/decorators";
|
||||
import { customElement, query, state } from "lit/decorators";
|
||||
import { classMap } from "lit/directives/class-map";
|
||||
import { consume } from "../../../common/decorators/consume";
|
||||
import { transform } from "../../../common/decorators/transform";
|
||||
@@ -29,8 +30,21 @@ import {
|
||||
isValidTimeZone,
|
||||
} from "./hui-date-card-helpers";
|
||||
|
||||
// The smallest size the large date shrinks to, in pixels
|
||||
const MIN_LARGE_DATE_FONT_SIZE = 12;
|
||||
|
||||
@customElement("hui-date-card")
|
||||
export class HuiDateCard extends LitElement implements LovelaceCard {
|
||||
// Each resize of the date updates the card, which fits the large date again.
|
||||
// The card itself is inline, which a resize observer can't follow.
|
||||
private _resizeController = new ResizeController(this, { target: null });
|
||||
|
||||
@query(".date-wrapper") private _wrapper?: HTMLElement;
|
||||
|
||||
@query(".date-title") private _title?: HTMLElement;
|
||||
|
||||
@query(".date-text") private _text?: HTMLElement;
|
||||
|
||||
public static async getConfigElement(): Promise<LovelaceCardEditor> {
|
||||
await import("../editor/config-elements/hui-date-card-editor");
|
||||
return document.createElement("hui-date-card-editor");
|
||||
@@ -160,6 +174,63 @@ export class HuiDateCard extends LitElement implements LovelaceCard {
|
||||
}
|
||||
}
|
||||
|
||||
protected updated(changedProps: PropertyValues) {
|
||||
super.updated(changedProps);
|
||||
this._fitLargeDate();
|
||||
}
|
||||
|
||||
// A long date at the large size can be wider and higher than the card, so
|
||||
// it shrinks until it fits, as large as it can be
|
||||
private _fitLargeDate() {
|
||||
const wrapper = this._wrapper;
|
||||
const text = this._text;
|
||||
|
||||
if (!wrapper || !text) {
|
||||
return;
|
||||
}
|
||||
|
||||
text.style.removeProperty("font-size");
|
||||
|
||||
if (this._config?.date_size !== "large") {
|
||||
return;
|
||||
}
|
||||
|
||||
const wrapperStyle = getComputedStyle(wrapper);
|
||||
|
||||
// The full height of the title, as a large date squeezes it
|
||||
const availableHeight =
|
||||
wrapper.clientHeight -
|
||||
parseFloat(wrapperStyle.paddingTop) -
|
||||
parseFloat(wrapperStyle.paddingBottom) -
|
||||
(this._title
|
||||
? this._title.scrollHeight + parseFloat(wrapperStyle.rowGap)
|
||||
: 0);
|
||||
|
||||
const fits = () =>
|
||||
text.scrollWidth <= text.clientWidth &&
|
||||
text.scrollHeight <= availableHeight;
|
||||
|
||||
if (fits()) {
|
||||
return;
|
||||
}
|
||||
|
||||
let fitting = MIN_LARGE_DATE_FONT_SIZE;
|
||||
let tooLarge = parseFloat(getComputedStyle(text).fontSize);
|
||||
|
||||
while (tooLarge - fitting > 0.5) {
|
||||
const size = (fitting + tooLarge) / 2;
|
||||
text.style.fontSize = `${size}px`;
|
||||
|
||||
if (fits()) {
|
||||
fitting = size;
|
||||
} else {
|
||||
tooLarge = size;
|
||||
}
|
||||
}
|
||||
|
||||
text.style.fontSize = `${fitting}px`;
|
||||
}
|
||||
|
||||
private _clearMidnightTimer() {
|
||||
if (this._midnightTimer) {
|
||||
clearTimeout(this._midnightTimer);
|
||||
@@ -219,6 +290,7 @@ export class HuiDateCard extends LitElement implements LovelaceCard {
|
||||
class="date-wrapper ${
|
||||
this._config.date_size ? `size-${this._config.date_size}` : ""
|
||||
}"
|
||||
${this._resizeController.target()}
|
||||
>
|
||||
${
|
||||
this._config.title !== undefined
|
||||
|
||||
@@ -504,7 +504,7 @@ export class HaGridLayoutSlider extends LitElement {
|
||||
left 180ms ease-in-out,
|
||||
bottom 180ms ease-in-out;
|
||||
--handle-spacing: calc(2 * var(--handle-margin) + var(--handle-size));
|
||||
--slider-tooltip-margin: var(--ha-space-1);
|
||||
--slider-tooltip-margin: 0px;
|
||||
--slider-tooltip-range: 100%;
|
||||
--slider-tooltip-offset: 0px;
|
||||
--slider-tooltip-position: calc(
|
||||
|
||||
@@ -420,7 +420,7 @@ export class HuiCardLayoutEditor extends LitElement {
|
||||
}
|
||||
ha-grid-size-picker {
|
||||
display: block;
|
||||
margin: var(--ha-space-4) auto;
|
||||
margin: 16px auto;
|
||||
direction: ltr;
|
||||
}
|
||||
`,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import type { HassEntity } from "home-assistant-js-websocket";
|
||||
import { css, html, LitElement, nothing } from "lit";
|
||||
import { customElement, state } from "lit/decorators";
|
||||
import { customElement, property, state } from "lit/decorators";
|
||||
import { DOMAINS_TOGGLE } from "../../../common/const";
|
||||
import { computeDomain } from "../../../common/entity/compute_domain";
|
||||
import "../../../components/ha-button";
|
||||
@@ -29,7 +29,7 @@ const EMPTY_STATE_OBJ = {
|
||||
|
||||
@customElement("hui-button-row")
|
||||
export class HuiButtonRow extends LitElement implements LovelaceRow {
|
||||
public hass?: HomeAssistant;
|
||||
@property({ attribute: false }) public hass?: HomeAssistant;
|
||||
|
||||
@state() private _config?: ButtonRowConfig;
|
||||
|
||||
|
||||
@@ -28,20 +28,12 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
|
||||
private _startupToastKey?: string;
|
||||
|
||||
private _startupDetailsOpen = false;
|
||||
|
||||
private _disconnectedTimeout?: number;
|
||||
|
||||
protected firstUpdated(changedProps: PropertyValues<this>) {
|
||||
super.firstUpdated(changedProps);
|
||||
// Need to load in advance because when disconnected, can't dynamically load code.
|
||||
setTimeout(() => import("../managers/notification-manager"), 5000);
|
||||
this.addEventListener("dialog-closed", (ev) => {
|
||||
if (ev.detail.dialog === "dialog-startup-progress") {
|
||||
this._startupDetailsOpen = false;
|
||||
this._updateStartupProgress();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
updated(changedProperties: PropertyValues<this>) {
|
||||
@@ -143,7 +135,6 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
// Wait until the translations are available.
|
||||
if (
|
||||
!this._startupProgressVisible ||
|
||||
this._startupDetailsOpen ||
|
||||
!this.hass!.localize("ui.startup_progress.starting")
|
||||
) {
|
||||
return;
|
||||
@@ -172,19 +163,13 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
? {
|
||||
text: { translationKey: "ui.startup_progress.details" },
|
||||
icon: mdiInformationOutline,
|
||||
action: () => this._showStartupDetails(),
|
||||
keepOpen: true,
|
||||
action: () => showStartupProgressDialog(this),
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
}
|
||||
|
||||
// Toasts always show above dialogs, so the toast is hidden while the details are open.
|
||||
private _showStartupDetails() {
|
||||
this._startupDetailsOpen = true;
|
||||
this._startupToastKey = undefined;
|
||||
showStartupProgressDialog(this);
|
||||
}
|
||||
|
||||
// Keeps the subscription, so the completion toast still reflects late failures.
|
||||
private _hideStartupProgress() {
|
||||
this._startupProgressVisible = false;
|
||||
@@ -208,9 +193,6 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
);
|
||||
this._hideStartupProgress();
|
||||
this._unsubscribeBootstrapProgress();
|
||||
if (this._startupDetailsOpen) {
|
||||
return;
|
||||
}
|
||||
const issues = failed.length;
|
||||
showToast(this, {
|
||||
id: SERVER_STARTUP_TOAST_ID,
|
||||
@@ -223,7 +205,7 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
action: this.hass!.user?.is_admin
|
||||
? {
|
||||
text: this.hass!.localize("ui.notification_toast.details"),
|
||||
action: () => this._showStartupDetails(),
|
||||
action: () => showStartupProgressDialog(this),
|
||||
}
|
||||
: undefined,
|
||||
});
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import type { PropertyValues } from "lit";
|
||||
import type { HASSDomEvent } from "../common/dom/fire_event";
|
||||
import { mainWindow } from "../common/dom/get_main_window";
|
||||
import { computeDomain } from "../common/entity/compute_domain";
|
||||
import { replaceCurrentUrl } from "../common/navigate";
|
||||
import {
|
||||
createMoreInfoUrl,
|
||||
@@ -11,6 +12,8 @@ import type { MoreInfoDialogParams } from "../dialogs/more-info/ha-more-info-dia
|
||||
import type { Constructor } from "../types";
|
||||
import type { HassBaseEl } from "./hass-base-mixin";
|
||||
|
||||
const LARGE_MORE_INFO_DOMAINS = ["camera", "image"];
|
||||
|
||||
declare global {
|
||||
// for fire event
|
||||
interface HASSDomEvents {
|
||||
@@ -44,7 +47,13 @@ export default <T extends Constructor<HassBaseEl>>(superClass: T) =>
|
||||
{
|
||||
entityId: ev.detail.entityId,
|
||||
view,
|
||||
large: ev.detail.large,
|
||||
large:
|
||||
ev.detail.large ??
|
||||
(ev.detail.entityId
|
||||
? LARGE_MORE_INFO_DOMAINS.includes(
|
||||
computeDomain(ev.detail.entityId)
|
||||
)
|
||||
: false),
|
||||
data: ev.detail.data,
|
||||
returnUrl,
|
||||
},
|
||||
|
||||
@@ -2857,7 +2857,6 @@
|
||||
"in_use": "In use",
|
||||
"connecting": "Connecting",
|
||||
"not_supported_count": "Not supported by this camera ({count})",
|
||||
"enhanced_by_cloud": "Enhanced by Home Assistant Link",
|
||||
"description": {
|
||||
"web_rtc": "Real-time video with the lowest delay, usually below a second. The video takes the most direct way from the camera to your device, which can need extra network setup when you are away from home. Needed to talk to the camera.",
|
||||
"hls": "The video is sent in short pieces through Home Assistant. It works on almost every network and device, but is a few seconds behind. Used while WebRTC connects, or when WebRTC is not available.",
|
||||
|
||||
@@ -1,12 +1,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import type { BluetoothScannerState } from "../../src/data/bluetooth";
|
||||
import {
|
||||
getBluetoothAdapters,
|
||||
isScannerStateMismatch,
|
||||
} from "../../src/data/bluetooth";
|
||||
import type { ConfigEntry } from "../../src/data/config_entries";
|
||||
import type { DeviceRegistryEntry } from "../../src/data/device/device_registry";
|
||||
import { isScannerStateMismatch } from "../../src/data/bluetooth";
|
||||
|
||||
const state = (
|
||||
overrides: Partial<BluetoothScannerState>
|
||||
@@ -68,54 +63,3 @@ describe("isScannerStateMismatch", () => {
|
||||
).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getBluetoothAdapters", () => {
|
||||
const entry = (
|
||||
entry_id: string,
|
||||
overrides: Partial<ConfigEntry> = {}
|
||||
): ConfigEntry =>
|
||||
({
|
||||
entry_id,
|
||||
domain: "bluetooth",
|
||||
source: "user",
|
||||
disabled_by: null,
|
||||
...overrides,
|
||||
}) as ConfigEntry;
|
||||
|
||||
const device = (
|
||||
id: string,
|
||||
configEntries: string[],
|
||||
connections: [string, string][] = [["bluetooth", id]]
|
||||
): DeviceRegistryEntry =>
|
||||
({
|
||||
id,
|
||||
config_entries: configEntries,
|
||||
connections,
|
||||
}) as DeviceRegistryEntry;
|
||||
|
||||
it("only counts entries with a Bluetooth device as adapters", () => {
|
||||
const entries = [
|
||||
entry("proxy"),
|
||||
entry("ignored", { source: "ignore" }),
|
||||
entry("removed"),
|
||||
entry("disabled", { disabled_by: "user" }),
|
||||
entry("disabled-without-device", { disabled_by: "user" }),
|
||||
];
|
||||
const devices = {
|
||||
proxy: device("proxy", ["esphome", "proxy"]),
|
||||
disabled: device("disabled", ["disabled"]),
|
||||
"no-bluetooth": device("no-bluetooth", ["proxy"], [["mac", "x"]]),
|
||||
other: device("other", ["other-integration"]),
|
||||
};
|
||||
|
||||
const result = getBluetoothAdapters(devices, entries);
|
||||
|
||||
expect(result.enabledDevices.map((a) => a.device.id)).toEqual(["proxy"]);
|
||||
expect(result.disabledDevices.map((a) => a.device.id)).toEqual([
|
||||
"disabled",
|
||||
]);
|
||||
expect(result.disabledEntriesWithoutDevice.map((e) => e.entry_id)).toEqual([
|
||||
"disabled-without-device",
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -1,66 +0,0 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import type { CoverEntity } from "../../src/data/cover";
|
||||
import { CoverEntityFeature, coverCurrentValue } from "../../src/data/cover";
|
||||
|
||||
const TILT_FEATURES =
|
||||
CoverEntityFeature.OPEN_TILT +
|
||||
CoverEntityFeature.CLOSE_TILT +
|
||||
CoverEntityFeature.STOP_TILT;
|
||||
|
||||
const cover = (
|
||||
state: string,
|
||||
supportedFeatures: number,
|
||||
attributes: Partial<CoverEntity["attributes"]> = {}
|
||||
): CoverEntity =>
|
||||
({
|
||||
entity_id: "cover.blind",
|
||||
state,
|
||||
attributes: { supported_features: supportedFeatures, ...attributes },
|
||||
}) as CoverEntity;
|
||||
|
||||
describe("coverCurrentValue", () => {
|
||||
it("uses the state for the tilt of a tilt-only cover without a tilt position", () => {
|
||||
expect(coverCurrentValue(cover("closed", TILT_FEATURES), "tilt")).toBe(0);
|
||||
expect(coverCurrentValue(cover("opening", TILT_FEATURES), "tilt")).toBe(0);
|
||||
expect(coverCurrentValue(cover("open", TILT_FEATURES), "tilt")).toBe(100);
|
||||
expect(coverCurrentValue(cover("closing", TILT_FEATURES), "tilt")).toBe(
|
||||
100
|
||||
);
|
||||
});
|
||||
|
||||
it("has no tilt when the state of a tilt-only cover is unknown", () => {
|
||||
expect(
|
||||
coverCurrentValue(cover("unknown", TILT_FEATURES), "tilt")
|
||||
).toBeUndefined();
|
||||
expect(
|
||||
coverCurrentValue(cover("unavailable", TILT_FEATURES), "tilt")
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("prefers the reported tilt position", () => {
|
||||
expect(
|
||||
coverCurrentValue(
|
||||
cover("closed", TILT_FEATURES, { current_tilt_position: 30 }),
|
||||
"tilt"
|
||||
)
|
||||
).toBe(30);
|
||||
});
|
||||
|
||||
it("does not use the state for the tilt when the cover also moves up and down", () => {
|
||||
expect(
|
||||
coverCurrentValue(
|
||||
cover("closed", TILT_FEATURES + CoverEntityFeature.OPEN),
|
||||
"tilt"
|
||||
)
|
||||
).toBeUndefined();
|
||||
});
|
||||
|
||||
it("does not use the state for the tilt when the cover can set its tilt position", () => {
|
||||
expect(
|
||||
coverCurrentValue(
|
||||
cover("closed", TILT_FEATURES + CoverEntityFeature.SET_TILT_POSITION),
|
||||
"tilt"
|
||||
)
|
||||
).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,63 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { ClimateEntityFeature } from "../../../src/data/climate";
|
||||
import { MockClimateEntity } from "../../../src/fake_data/entities/climate-entity";
|
||||
|
||||
const hvacAction = (state: string, current: number, target: number) =>
|
||||
new MockClimateEntity({
|
||||
entity_id: "climate.demo",
|
||||
state,
|
||||
attributes: {
|
||||
supported_features: ClimateEntityFeature.TARGET_TEMPERATURE,
|
||||
current_temperature: current,
|
||||
temperature: target,
|
||||
},
|
||||
}).toState().attributes.hvac_action;
|
||||
|
||||
// A range of 20° to 24° only, like climate.upstairs in the arsaboo demo
|
||||
const rangeHvacAction = (state: string, current: number) =>
|
||||
new MockClimateEntity({
|
||||
entity_id: "climate.demo",
|
||||
state,
|
||||
attributes: {
|
||||
supported_features:
|
||||
ClimateEntityFeature.TARGET_TEMPERATURE +
|
||||
ClimateEntityFeature.TARGET_TEMPERATURE_RANGE,
|
||||
current_temperature: current,
|
||||
temperature: null,
|
||||
target_temp_low: 20,
|
||||
target_temp_high: 24,
|
||||
},
|
||||
}).toState().attributes.hvac_action;
|
||||
|
||||
describe("MockClimateEntity", () => {
|
||||
it.each([
|
||||
["heat", 18, 21, "heating"],
|
||||
["heat", 21, 21, "idle"],
|
||||
["cool", 25, 21, "cooling"],
|
||||
["cool", 20, 21, "idle"],
|
||||
["dry", 20, 21, "drying"],
|
||||
["fan_only", 20, 21, "fan"],
|
||||
["off", 18, 21, "off"],
|
||||
])(
|
||||
"in %s at %d° with a target of %d° is %s",
|
||||
(state, current, target, action) => {
|
||||
expect(hvacAction(state, current, target)).toBe(action);
|
||||
}
|
||||
);
|
||||
|
||||
it.each([
|
||||
["heat", 18, "heating"],
|
||||
["heat", 25, "idle"],
|
||||
["cool", 25, "cooling"],
|
||||
["cool", 18, "idle"],
|
||||
["heat_cool", 18, "heating"],
|
||||
["heat_cool", 25, "cooling"],
|
||||
["auto", 22, "idle"],
|
||||
])(
|
||||
"in %s at %d° with a range of 20° to 24° is %s",
|
||||
(state, current, action) => {
|
||||
expect(rangeHvacAction(state, current)).toBe(action);
|
||||
}
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,109 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import type { Condition } from "../../src/data/automation";
|
||||
import type { MockHomeAssistant } from "../../src/fake_data/provide_hass";
|
||||
import { provideHass } from "../../src/fake_data/provide_hass";
|
||||
|
||||
type Host = HTMLElement & { hass?: Partial<MockHomeAssistant> };
|
||||
|
||||
// `ownUpdateHass` replaces updateHass as the full demo does, see
|
||||
// demo/src/ha-demo.ts
|
||||
const setup = (ownUpdateHass = false) => {
|
||||
const host: Host = document.createElement("div");
|
||||
|
||||
const overrides: Partial<MockHomeAssistant> = ownUpdateHass
|
||||
? {
|
||||
updateHass: (update: Partial<MockHomeAssistant>) => {
|
||||
host.hass = { ...host.hass, ...update };
|
||||
},
|
||||
}
|
||||
: {};
|
||||
|
||||
const hass = provideHass(host, overrides);
|
||||
|
||||
hass.addEntities([
|
||||
{ entity_id: "light.kitchen", state: "on", attributes: {} },
|
||||
{ entity_id: "light.hallway", state: "off", attributes: {} },
|
||||
]);
|
||||
|
||||
return hass;
|
||||
};
|
||||
|
||||
const subscribe = async (hass: MockHomeAssistant, condition: Condition) => {
|
||||
const messages: unknown[] = [];
|
||||
|
||||
await hass.connection.subscribeMessage(
|
||||
(message) => {
|
||||
messages.push(message);
|
||||
},
|
||||
{ type: "subscribe_condition", condition }
|
||||
);
|
||||
|
||||
return messages;
|
||||
};
|
||||
|
||||
const kitchenOn: Condition = {
|
||||
condition: "state",
|
||||
entity_id: "light.kitchen",
|
||||
state: "on",
|
||||
};
|
||||
|
||||
const hallwayOn: Condition = {
|
||||
condition: "state",
|
||||
entity_id: "light.hallway",
|
||||
state: "on",
|
||||
};
|
||||
|
||||
describe("subscribe_condition in the mock backend", () => {
|
||||
it.each([
|
||||
["its own", false],
|
||||
["the host's", true],
|
||||
])(
|
||||
"checks a condition again when a state changes, with %s updateHass",
|
||||
async (_name, ownUpdateHass) => {
|
||||
const hass = setup(ownUpdateHass);
|
||||
const messages = await subscribe(hass, hallwayOn);
|
||||
|
||||
hass.addEntities({
|
||||
entity_id: "light.hallway",
|
||||
state: "on",
|
||||
attributes: {},
|
||||
});
|
||||
|
||||
expect(messages).toEqual([{ result: false }, { result: true }]);
|
||||
}
|
||||
);
|
||||
|
||||
it("passes a not only when none of its conditions pass, as in Core", async () => {
|
||||
const hass = setup();
|
||||
|
||||
expect(
|
||||
await subscribe(hass, {
|
||||
condition: "not",
|
||||
conditions: [kitchenOn, hallwayOn],
|
||||
})
|
||||
).toEqual([{ result: false }]);
|
||||
});
|
||||
|
||||
it("skips disabled conditions", async () => {
|
||||
const hass = setup();
|
||||
|
||||
expect(
|
||||
await subscribe(hass, {
|
||||
condition: "and",
|
||||
conditions: [kitchenOn, { ...hallwayOn, enabled: false }],
|
||||
})
|
||||
).toEqual([{ result: true }]);
|
||||
});
|
||||
|
||||
it("answers a not around a template with an error", async () => {
|
||||
const hass = setup();
|
||||
|
||||
const [message] = await subscribe(hass, {
|
||||
condition: "not",
|
||||
conditions: [{ condition: "template", value_template: "{{ true }}" }],
|
||||
});
|
||||
|
||||
expect(message).toHaveProperty("error");
|
||||
});
|
||||
});
|
||||
@@ -284,6 +284,13 @@ describe("browseLinkFromUrl", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("filters on no integration category for an empty one", () => {
|
||||
expect(
|
||||
browseLinkFromUrl("?integration_category=")?.filters
|
||||
.integration_category ?? []
|
||||
).toEqual([]);
|
||||
});
|
||||
|
||||
it("keeps what was picked for a link that says nothing about browsing", () => {
|
||||
expect(
|
||||
browseLinkFromUrl("?owner=hacs&repository=integration")
|
||||
@@ -292,6 +299,13 @@ describe("browseLinkFromUrl", () => {
|
||||
});
|
||||
|
||||
describe("filtersOfTab", () => {
|
||||
it("keeps the integration category on every tab", () => {
|
||||
expect(
|
||||
filtersOfTab({ integration_category: ["energy"] }, "installed")
|
||||
.integration_category
|
||||
).toEqual(["energy"]);
|
||||
});
|
||||
|
||||
it("only offers statuses something installed can have on the installed tab", () => {
|
||||
expect(statusesOfTab("installed")).toEqual([
|
||||
"pending-restart",
|
||||
|
||||
Reference in new issue
Block a user