Compare commits

..
22 changed files with 468 additions and 2415 deletions

No files matched your search

+1 -11
View File
@@ -185,8 +185,6 @@ export class HaControlCircularSlider extends LitElement {
private _lastChanging?: number;
private _keyboardChanging = false;
private _getPercentageFromEvent = (e: HammerInput) => {
const bound = this._slider.getBoundingClientRect();
const x = (2 * (e.center.x - bound.left - bound.width / 2)) / bound.width;
@@ -462,7 +460,6 @@ export class HaControlCircularSlider extends LitElement {
this._setActiveValue(this._boundedValue(this.max));
break;
}
this._keyboardChanging = true;
fireEvent(this, `${this._activeSlider}-changing`, {
value: this._getActiveValue(),
});
@@ -471,14 +468,8 @@ export class HaControlCircularSlider extends LitElement {
private _handleKeyUp(e: KeyboardEvent) {
if (this.disabled || !A11Y_KEY_CODES.has(e.code)) return;
e.preventDefault();
this._endKeyboardChange(e);
}
private _endKeyboardChange(e: Event) {
if (!this._keyboardChanging) return;
this._keyboardChanging = false;
this._activeSlider = (e.currentTarget as any).id as ActiveSlider;
e.preventDefault();
fireEvent(this, `${this._activeSlider}-changing`, {
value: undefined,
});
@@ -620,7 +611,6 @@ export class HaControlCircularSlider extends LitElement {
)}
@keydown=${this._handleKeyDown}
@keyup=${this._handleKeyUp}
@blur=${this._endKeyboardChange}
/>
`
: nothing
-10
View File
@@ -82,8 +82,6 @@ export class HaControlScrubber extends LitElement {
private _mc?: HammerManager;
private _keyboardChanging = false;
private get _range() {
return this.max - this.min;
}
@@ -280,19 +278,12 @@ export class HaControlScrubber extends LitElement {
e.code === "ArrowLeft" || e.code === "ArrowDown" ? -1 : 1;
this.value = this.normalizedValue(current + this.step * multiplier);
}
this._keyboardChanging = true;
fireEvent(this, "slider-moved", { value: this.value });
}
private _handleKeyUp(e: KeyboardEvent) {
if (this.disabled || !A11Y_KEY_CODES.has(e.code)) return;
e.preventDefault();
this._endKeyboardChange();
}
private _endKeyboardChange() {
if (!this._keyboardChanging) return;
this._keyboardChanging = false;
fireEvent(this, "slider-moved", { value: undefined });
fireEvent(this, "value-changed", { value: this.value });
}
@@ -332,7 +323,6 @@ export class HaControlScrubber extends LitElement {
aria-orientation="horizontal"
@keydown=${this._handleKeyDown}
@keyup=${this._handleKeyUp}
@blur=${this._endKeyboardChange}
>
<div class="rail"></div>
<div class="track" @transitionend=${this._handleTransitionEnd}></div>
-10
View File
@@ -308,23 +308,14 @@ export class HaControlSlider extends LitElement {
);
}
this._showTooltip();
this._keyboardChanging = true;
fireEvent(this, "slider-moved", { value: this.value });
}
private _tooltipTimeout?: number;
private _keyboardChanging = false;
private _handleKeyUp(e: KeyboardEvent) {
if (!A11Y_KEY_CODES.has(e.code)) return;
e.preventDefault();
this._endKeyboardChange();
}
private _endKeyboardChange() {
if (!this._keyboardChanging) return;
this._keyboardChanging = false;
this._hideTooltip(500);
fireEvent(this, "value-changed", { value: this.value });
}
@@ -414,7 +405,6 @@ export class HaControlSlider extends LitElement {
aria-orientation=${this.vertical ? "vertical" : "horizontal"}
@keydown=${this._handleKeyDown}
@keyup=${this._handleKeyUp}
@blur=${this._endKeyboardChange}
>
<div class="slider-track-background"></div>
<slot name="background"></slot>
-5
View File
@@ -21,11 +21,6 @@ export class HaIconButtonPrev extends LitElement {
@property() download?: string;
static shadowRootOptions: ShadowRootInit = {
...LitElement.shadowRootOptions,
delegatesFocus: true,
};
@state() private _icon =
mainWindow.document.dir === "rtl" ? mdiChevronRight : mdiChevronLeft;
+2 -37
View File
@@ -245,17 +245,7 @@ type ConditionIcons = Record<
>;
export type IconCategory =
| "entity"
| "entity_component"
| "services"
| "triggers"
| "conditions"
| "integration_category";
export type IntegrationCategoryIcons = Record<
string,
{ default: string; subcategory?: Record<string, { default: string }> }
>;
"entity" | "entity_component" | "services" | "triggers" | "conditions";
interface CategoryType {
entity: PlatformIcons;
@@ -263,7 +253,6 @@ interface CategoryType {
services: ServiceIcons;
triggers: TriggerIcons;
conditions: ConditionIcons;
integration_category: IntegrationCategoryIcons;
}
export const getHassIcons = async <T extends IconCategory>(
@@ -332,10 +321,7 @@ export const getComponentIcons = async (
};
export const getCategoryIcons = async <
T extends Exclude<
IconCategory,
"entity" | "entity_component" | "integration_category"
>,
T extends Exclude<IconCategory, "entity" | "entity_component">,
>(
connection: Connection,
hassConfig: HomeAssistant["config"],
@@ -754,24 +740,3 @@ export const domainIcon = async (
return undefined;
};
let integrationCategoryIcons:
ReturnType<typeof getHassIcons<"integration_category">> | undefined;
export const getIntegrationCategoryIcons = async (
connection: Connection
): Promise<IntegrationCategoryIcons | undefined> => {
// Cache the request itself, so callers while it loads share it
integrationCategoryIcons ??= getHassIcons(
connection,
"integration_category",
"homeassistant"
);
try {
const result = await integrationCategoryIcons;
return result.resources.homeassistant;
} catch (_err) {
integrationCategoryIcons = undefined;
return undefined;
}
};
-2
View File
@@ -78,8 +78,6 @@ export interface IntegrationManifest {
)[];
homekit?: { models?: string[] };
integration_type?: IntegrationType;
// Categories like `energy` or subcategories like `energy.ev_charging`
categories?: string[];
loggers?: string[];
quality_scale?:
| "bronze"
-2
View File
@@ -13,8 +13,6 @@ export interface Integration {
is_built_in?: boolean;
overwrites_built_in?: boolean;
single_config_entry?: boolean;
// Categories like `energy` or subcategories like `energy.ev_charging`
categories?: string[];
}
export type Integrations = Record<string, Integration>;
+1 -2
View File
@@ -76,8 +76,7 @@ export type TranslationCategory =
| "selector"
| "services"
| "triggers"
| "conditions"
| "integration_category";
| "conditions";
export const subscribeTranslationPreferences = (
hass: HomeAssistant,
@@ -7,7 +7,6 @@ import { watchAudioLevel } from "../../../common/audio/watch-audio-level";
import { consume } from "../../../common/decorators/consume";
import { consumeLocalize } from "../../../common/decorators/consume-context-entry";
import type { HASSDomEvent } from "../../../common/dom/fire_event";
import { fireEvent } from "../../../common/dom/fire_event";
import type { LocalizeFunc } from "../../../common/translations/localize";
import "../../../components/ha-button";
import "../../../components/camera/ha-camera-player";
@@ -33,9 +32,6 @@ import type {
} from "../../../external_app/external_messaging";
import { showToast } from "../../../util/toast";
// The padding of the microphone row around its 40px button
const MICROPHONE_ROW_HEIGHT = "calc(var(--ha-space-4) * 2 + 40px)";
@customElement("more-info-camera")
class MoreInfoCamera extends LitElement {
@state()
@@ -97,11 +93,6 @@ class MoreInfoCamera extends LitElement {
protected updated(changedProps: PropertyValues) {
super.updated(changedProps);
if (changedProps.has("_supportsTwoWayAudio")) {
fireEvent(this, "camera-controls-height-changed", {
height: this._supportsTwoWayAudio ? MICROPHONE_ROW_HEIGHT : undefined,
});
}
if (changedProps.has("_microphoneState")) {
this._stopMicrophoneMeter();
const track = this._cameraStream?.microphoneTrack;
@@ -399,7 +390,4 @@ declare global {
interface HTMLElementTagNameMap {
"more-info-camera": MoreInfoCamera;
}
interface HASSDomEvents {
"camera-controls-height-changed": { height?: string };
}
}
+13 -11
View File
@@ -154,8 +154,8 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
// 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;
// The camera's info shows microphone controls below the picture then
@state() private _cameraTwoWayAudio = false;
@state() private _open = false;
@@ -200,7 +200,7 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
// its size again
if (params.entityId !== this._entityId) {
this._cameraAspectRatio = undefined;
this._cameraControlsHeight = undefined;
this._cameraTwoWayAudio = false;
}
this._entityId = params.entityId;
if (!this._entityId) {
@@ -266,7 +266,7 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
this._childViewStack = [];
this._returnUrl = undefined;
this._cameraAspectRatio = undefined;
this._cameraControlsHeight = undefined;
this._cameraTwoWayAudio = false;
this._isEscapeEnabled = true;
window.removeEventListener("dialog-closed", this._enableEscapeKeyClose);
window.removeEventListener("show-dialog", this._disableEscapeKeyClose);
@@ -709,13 +709,15 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
}
class=${classMap({ camera: domain === "camera" })}
style=${styleMap({
"--more-info-camera-controls-height": this._cameraControlsHeight,
"--more-info-camera-controls-height": this._cameraTwoWayAudio
? "72px"
: undefined,
"--ha-dialog-width-lg": cameraAspectRatio
? `clamp(var(--ha-dialog-width-md, 580px), calc(var(--video-max-height) * ${cameraAspectRatio}), 1920px)`
: undefined,
})}
@camera-aspect-ratio-changed=${this._cameraAspectRatioChanged}
@camera-controls-height-changed=${this._cameraControlsHeightChanged}
@camera-capabilities-changed=${this._cameraCapabilitiesChanged}
.accessibleLabel=${title}
@closed=${this._dialogClosed}
@opened=${this._handleOpened}
@@ -1146,10 +1148,10 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
this._cameraAspectRatio = ev.detail.aspectRatio;
}
private _cameraControlsHeightChanged(
ev: HASSDomEvent<HASSDomEvents["camera-controls-height-changed"]>
private _cameraCapabilitiesChanged(
ev: HASSDomEvent<HASSDomEvents["camera-capabilities-changed"]>
) {
this._cameraControlsHeight = ev.detail.height;
this._cameraTwoWayAudio = ev.detail.capabilities?.two_way_audio ?? false;
}
private _enlarge() {
@@ -1216,8 +1218,8 @@ export class MoreInfoDialog extends DirtyStateProviderMixin<
--dialog-content-padding: 0;
}
/* The dialog's margin, its header of about 68px and the controls
below the picture */
/* The dialog's margin, its header of about 68px and the microphone
controls of about 72px when the camera has them */
ha-adaptive-dialog.camera {
--video-max-height: calc(
100vh - var(--ha-space-20) -
+16 -1
View File
@@ -75,11 +75,26 @@ const clearUrlParams = () => {
}
};
// The login page is never cached, so check the server is up before getAuth redirects to it.
const loadTokensOrCheckServer = async () => {
const tokens = loadTokens();
if (!tokens || tokens.hassUrl !== hassUrl) {
const response = await fetch(`${hassUrl}/manifest.json`, {
mode: "no-cors",
cache: "no-store",
});
if (response.status >= 500) {
throw new Error(`Home Assistant responded with ${response.status}`);
}
}
return tokens;
};
const authOptions = {
hassUrl,
limitHassInstance: true,
saveTokens,
loadTokens: () => Promise.resolve(loadTokens()),
loadTokens: loadTokensOrCheckServer,
};
const getAuthDroppingStaleCallback = async () => {
@@ -1,84 +0,0 @@
import type { IFuseOptions } from "fuse.js";
import type { HaListVirtualizedItem } from "../../../components/list/ha-list-virtualized";
export interface IntegrationListItem extends HaListVirtualizedItem {
name: string;
domain: string;
config_flow?: boolean;
is_helper?: boolean;
integrations?: string[];
domains?: string[];
iot_standards?: string[];
supported_by?: string;
cloud?: boolean;
is_built_in?: boolean;
overwrites_built_in?: boolean;
is_add?: boolean;
single_config_entry?: boolean;
// A brand title row, not pickable
is_header?: boolean;
is_end_space?: boolean;
result?: "brand" | "category" | "more";
category?: string;
subcategory?: string;
section?: SearchSection;
icon?: string;
description?: string;
categories?: string[];
}
export type BrowseBy = "category" | "brand";
export type Connection = "local" | "cloud";
export const CONNECTIONS: Connection[] = ["local", "cloud"];
export const ofConnection = (
item: IntegrationListItem,
connection?: Connection
) => !connection || (connection === "cloud") === !!item.cloud;
export type SearchSection = "brand" | "category" | "integration" | "helper";
export const SEARCH_SECTIONS: SearchSection[] = [
"brand",
"category",
"integration",
"helper",
];
export const MAX_SEARCH_ITEMS_PER_SECTION = 5;
export const searchOptions = (
filter: string
): IFuseOptions<IntegrationListItem> => ({
keys: [
{ name: "name", weight: 5 },
{ name: "domain", weight: 5 },
{ name: "integrations", weight: 2 },
"supported_by",
"iot_standards",
],
isCaseSensitive: false,
minMatchCharLength: Math.min(filter.length, 2),
threshold: 0.2,
ignoreDiacritics: true,
});
export interface IntegrationCategory {
slug: string;
name: string;
subcategories: { slug: string; name: string }[];
}
export const inCategory = (
categories: string[] | undefined,
category?: string,
subcategory?: string
) =>
!category ||
(categories || []).some((slug) =>
subcategory
? slug === `${category}.${subcategory}`
: slug === category || slug.startsWith(`${category}.`)
);
File diff suppressed because it is too large. Load diff
@@ -1,5 +1,4 @@
import "@home-assistant/webawesome/dist/components/divider/divider";
import { mdiPlus } from "@mdi/js";
import { css, html, LitElement, nothing } from "lit";
import { customElement, property } from "lit/decorators";
import { isComponentLoaded } from "../../../common/config/is_component_loaded";
@@ -12,8 +11,6 @@ import {
} from "../../../common/integrations/protocolIntegrationPicked";
import { navigate } from "../../../common/navigate";
import { caseInsensitiveStringCompare } from "../../../common/string/compare";
import "../../../components/ha-button";
import "../../../components/ha-svg-icon";
import "../../../components/item/ha-list-item-button";
import "../../../components/list/ha-list-base";
import { localizeConfigFlowTitle } from "../../../data/config_flow";
@@ -30,7 +27,7 @@ import { brandsUrl } from "../../../util/brands-url";
import "./ha-integration-list-item";
import { showYamlIntegrationDialog } from "./show-add-integration-dialog";
export const standardToDomain = { zigbee: "zha", zwave: "zwave_js" } as const;
const standardToDomain = { zigbee: "zha", zwave: "zwave_js" } as const;
@customElement("ha-domain-integrations")
class HaDomainIntegrations extends LitElement {
@@ -49,86 +46,26 @@ class HaDomainIntegrations extends LitElement {
@property({ attribute: false })
public showManageLink = false;
@property({ type: Boolean, reflect: true }) public boxed = false;
protected render() {
// Only show manage link if not already on the integrations dashboard
const manage =
this.showManageLink &&
!location.pathname.startsWith("/config/integrations");
return html`<div class="box">
<ha-list-base>
${
this.flowsInProgress?.length
? html`<h3>
${this.hass.localize("ui.panel.config.integrations.discovered")}
</h3>
${this.flowsInProgress.map(
(flow) =>
html`<ha-list-item-button
.flow=${flow}
@click=${this._flowInProgressPicked}
>
<img
alt=""
slot="start"
loading="lazy"
src=${brandsUrl(
{
domain: flow.handler,
type: "icon",
darkOptimized: this.hass.themes?.darkMode,
},
this.hass.auth.data.hassUrl
)}
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
<span slot="headline"
>${localizeConfigFlowTitle(this.hass.localize, flow)}</span
>
<span slot="supporting-text"
>${domainToName(this.hass.localize, flow.handler)}</span
>
<ha-svg-icon slot="end" .path=${mdiPlus}></ha-svg-icon>
</ha-list-item-button>`
)}
<wa-divider></wa-divider>
${
this.integration &&
"integrations" in this.integration &&
this.integration.integrations
? html`<h3>
${this.hass.localize(
"ui.panel.config.integrations.available_integrations"
)}
</h3>`
: nothing
}`
: nothing
}
${
this.integration?.iot_standards
? this.integration.iot_standards
.filter((standard) =>
(PROTOCOL_INTEGRATIONS as readonly string[]).includes(
standardToDomain[standard] || standard
)
)
.map((standard) => {
const domain: (typeof PROTOCOL_INTEGRATIONS)[number] =
standardToDomain[standard] || standard;
return html`<ha-list-item-button
.domain=${domain}
@click=${this._standardPicked}
return html`<ha-list-base>
${
this.flowsInProgress?.length
? html`<h3>
${this.hass.localize("ui.panel.config.integrations.discovered")}
</h3>
${this.flowsInProgress.map(
(flow) =>
html`<ha-list-item-button
.flow=${flow}
@click=${this._flowInProgressPicked}
>
<img
alt=""
slot="start"
loading="lazy"
alt=""
src=${brandsUrl(
{
domain,
domain: flow.handler,
type: "icon",
darkOptimized: this.hass.themes?.darkMode,
},
@@ -138,169 +75,204 @@ class HaDomainIntegrations extends LitElement {
referrerpolicy="no-referrer"
/>
<span slot="headline"
>${this.hass.localize(
`ui.panel.config.integrations.add_${domain}_device`
)}</span
>${localizeConfigFlowTitle(this.hass.localize, flow)}</span
>
<span slot="supporting-text"
>${domainToName(this.hass.localize, flow.handler)}</span
>
<ha-icon-next slot="end"></ha-icon-next>
</ha-list-item-button>`;
})
: nothing
}
${
this.integration &&
"integrations" in this.integration &&
this.integration.integrations
? Object.entries(this.integration.integrations)
.filter(([, val]) => val.integration_type !== "hardware")
.sort((a, b) => {
if (a[1].config_flow && !b[1].config_flow) {
return -1;
}
if (b[1].config_flow && !a[1].config_flow) {
return 0;
}
return caseInsensitiveStringCompare(
a[1].name || domainToName(this.hass.localize, a[0]),
b[1].name || domainToName(this.hass.localize, b[0]),
this.hass.locale.language
);
})
.map(
([dom, val]) =>
html`<ha-integration-list-item
.domain=${dom}
.integration=${{
...val,
domain: dom,
name: val.name || domainToName(this.hass.localize, dom),
is_built_in: val.is_built_in !== false,
cloud: val.iot_class?.startsWith("cloud_"),
}}
.opensFlow=${!val.iot_standards}
@click=${this._integrationPicked}
>
</ha-integration-list-item>`
)
: nothing
}
${
(PROTOCOL_INTEGRATIONS as readonly string[]).includes(this.domain)
? html`<ha-list-item-button
.domain=${this.domain}
@click=${this._standardPicked}
>
<img
slot="start"
loading="lazy"
alt=""
src=${brandsUrl(
{
domain: this.domain,
type: "icon",
darkOptimized: this.hass.themes?.darkMode,
},
this.hass.auth.data.hassUrl
)}
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
<span slot="headline"
>${this.hass.localize(
`ui.panel.config.integrations.add_${
this.domain as (typeof PROTOCOL_INTEGRATIONS)[number]
}_device`
)}</span
>
<ha-icon-next slot="end"></ha-icon-next>
</ha-list-item-button>`
: nothing
}
${
this.integration &&
"config_flow" in this.integration &&
this.integration.config_flow
? html`${
this.flowsInProgress?.length
? html`<ha-list-item-button
.domain=${this.domain}
@click=${this._integrationPicked}
.integration=${{
...this.integration,
domain: this.domain,
name:
this.integration.name ||
domainToName(this.hass.localize, this.domain),
is_built_in: this.integration.is_built_in !== false,
cloud: this.integration.iot_class?.startsWith("cloud_"),
}}
>
<span slot="headline">
${this.hass.localize(
"ui.panel.config.integrations.new_flow",
{
integration:
this.integration.name ||
domainToName(this.hass.localize, this.domain),
}
)}
</span>
<ha-svg-icon slot="end" .path=${mdiPlus}></ha-svg-icon>
</ha-list-item-button>`
: html`<ha-integration-list-item
.domain=${this.domain}
.integration=${{
...this.integration,
domain: this.domain,
name:
this.integration.name ||
domainToName(this.hass.localize, this.domain),
is_built_in: this.integration.is_built_in !== false,
cloud: this.integration.iot_class?.startsWith("cloud_"),
}}
opens-flow
@click=${this._integrationPicked}
>
</ha-integration-list-item>`
</ha-list-item-button>`
)}
<wa-divider></wa-divider>
${
this.integration &&
"integrations" in this.integration &&
this.integration.integrations
? html`<h3>
${this.hass.localize(
"ui.panel.config.integrations.available_integrations"
)}
</h3>`
: nothing
}`
: nothing
}
${
manage && !this.boxed
? html`<ha-list-item-button @click=${this._manageDiscovered}>
<span slot="headline"
>${this.hass.localize(
"ui.panel.config.integrations.manage_discovered"
)}</span
>
<span slot="supporting-text"
>${this.hass.localize(
"ui.panel.config.integrations.manage_discovered_description"
)}</span
>
<ha-icon-next slot="end"></ha-icon-next>
</ha-list-item-button>`
: nothing
}
</ha-list-base>
${
manage && this.boxed
? html`<div class="footer">
<div class="footer-bar">
<ha-button
appearance="plain"
size="s"
@click=${this._manageDiscovered}
>
${this.hass.localize(
"ui.panel.config.integrations.manage_discovered"
)}
</ha-button>
</div>
</div>`
: nothing
}
</div>`;
${
this.integration?.iot_standards
? this.integration.iot_standards
.filter((standard) =>
(PROTOCOL_INTEGRATIONS as readonly string[]).includes(
standardToDomain[standard] || standard
)
)
.map((standard) => {
const domain: (typeof PROTOCOL_INTEGRATIONS)[number] =
standardToDomain[standard] || standard;
return html`<ha-list-item-button
.domain=${domain}
@click=${this._standardPicked}
>
<img
slot="start"
loading="lazy"
alt=""
src=${brandsUrl(
{
domain,
type: "icon",
darkOptimized: this.hass.themes?.darkMode,
},
this.hass.auth.data.hassUrl
)}
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
<span slot="headline"
>${this.hass.localize(
`ui.panel.config.integrations.add_${domain}_device`
)}</span
>
<ha-icon-next slot="end"></ha-icon-next>
</ha-list-item-button>`;
})
: ""
}
${
this.integration &&
"integrations" in this.integration &&
this.integration.integrations
? Object.entries(this.integration.integrations)
.filter(([, val]) => val.integration_type !== "hardware")
.sort((a, b) => {
if (a[1].config_flow && !b[1].config_flow) {
return -1;
}
if (b[1].config_flow && !a[1].config_flow) {
return 0;
}
return caseInsensitiveStringCompare(
a[1].name || domainToName(this.hass.localize, a[0]),
b[1].name || domainToName(this.hass.localize, b[0]),
this.hass.locale.language
);
})
.map(
([dom, val]) =>
html`<ha-integration-list-item
.domain=${dom}
.integration=${{
...val,
domain: dom,
name: val.name || domainToName(this.hass.localize, dom),
is_built_in: val.is_built_in !== false,
cloud: val.iot_class?.startsWith("cloud_"),
}}
@click=${this._integrationPicked}
>
</ha-integration-list-item>`
)
: ""
}
${
(PROTOCOL_INTEGRATIONS as readonly string[]).includes(this.domain)
? html`<ha-list-item-button
.domain=${this.domain}
@click=${this._standardPicked}
>
<img
slot="start"
loading="lazy"
alt=""
src=${brandsUrl(
{
domain: this.domain,
type: "icon",
darkOptimized: this.hass.themes?.darkMode,
},
this.hass.auth.data.hassUrl
)}
crossorigin="anonymous"
referrerpolicy="no-referrer"
/>
<span slot="headline"
>${this.hass.localize(
`ui.panel.config.integrations.add_${
this.domain as (typeof PROTOCOL_INTEGRATIONS)[number]
}_device`
)}</span
>
<ha-icon-next slot="end"></ha-icon-next>
</ha-list-item-button>`
: ""
}
${
this.integration &&
"config_flow" in this.integration &&
this.integration.config_flow
? html`${
this.flowsInProgress?.length
? html`<ha-list-item-button
.domain=${this.domain}
@click=${this._integrationPicked}
.integration=${{
...this.integration,
domain: this.domain,
name:
this.integration.name ||
domainToName(this.hass.localize, this.domain),
is_built_in: this.integration.is_built_in !== false,
cloud: this.integration.iot_class?.startsWith("cloud_"),
}}
>
<span slot="headline">
${this.hass.localize(
"ui.panel.config.integrations.new_flow",
{
integration:
this.integration.name ||
domainToName(this.hass.localize, this.domain),
}
)}
</span>
<ha-icon-next slot="end"></ha-icon-next>
</ha-list-item-button>`
: html`<ha-integration-list-item
.domain=${this.domain}
.integration=${{
...this.integration,
domain: this.domain,
name:
this.integration.name ||
domainToName(this.hass.localize, this.domain),
is_built_in: this.integration.is_built_in !== false,
cloud: this.integration.iot_class?.startsWith("cloud_"),
}}
@click=${this._integrationPicked}
>
</ha-integration-list-item>`
}`
: ""
}
${
this.showManageLink &&
// Only show manage link if not already on the integrations dashboard
!location.pathname.startsWith("/config/integrations")
? html`<ha-list-item-button @click=${this._manageDiscovered}>
<span slot="headline"
>${this.hass.localize(
"ui.panel.config.integrations.manage_discovered"
)}</span
>
<span slot="supporting-text"
>${this.hass.localize(
"ui.panel.config.integrations.manage_discovered_description"
)}</span
>
<ha-icon-next slot="end"></ha-icon-next>
</ha-list-item-button>`
: nothing
}
</ha-list-base> `;
}
private async _integrationPicked(
@@ -408,86 +380,6 @@ class HaDomainIntegrations extends LitElement {
ha-icon-next {
color: var(--ha-color-text-secondary);
}
ha-svg-icon[slot="end"] {
color: var(--primary-color);
}
.box {
display: contents;
}
:host([boxed]) {
--ha-row-item-padding-inline: var(--ha-space-3);
display: flex;
flex-direction: column;
flex: 1;
height: 100%;
min-height: 0;
}
:host([boxed]) .box {
display: flex;
flex-direction: column;
flex: 1;
min-height: 0;
overflow: auto;
/* Bouncing would move the sticky footer */
overscroll-behavior: none;
}
:host([boxed]) ha-list-base {
flex-shrink: 0;
padding-block-end: var(--ha-space-2);
}
/* hidden would make it a scroll container and break the sticky title */
:host([boxed]) ha-list-base::part(base) {
overflow-x: clip;
}
:host([boxed]) h3 {
position: sticky;
top: 0;
z-index: 1;
display: flex;
align-items: center;
box-sizing: border-box;
min-height: var(--ha-space-10);
margin: 0;
padding-block: var(--ha-space-2);
padding-inline: var(--ha-space-8) var(--ha-space-3);
background-color: var(--card-background-color);
color: var(--primary-text-color);
font-weight: var(--ha-font-weight-medium);
}
:host([boxed]) ha-list-item-button {
padding: 0 var(--ha-space-4) var(--ha-space-2);
box-sizing: border-box;
--ha-list-item-focus-radius: var(--ha-border-radius-lg);
}
:host([boxed]) ha-list-item-button::part(base) {
border: 1px solid var(--ha-color-border-neutral-quiet);
border-radius: var(--ha-border-radius-lg);
overflow: hidden;
}
:host([boxed]) wa-divider {
display: none;
}
.footer {
position: sticky;
bottom: 0;
z-index: 1;
margin-top: auto;
padding: var(--ha-space-6) var(--ha-space-4) var(--ha-space-3);
background: linear-gradient(
to bottom,
transparent,
var(--card-background-color) var(--ha-space-6)
);
pointer-events: none;
}
.footer-bar {
display: flex;
justify-content: center;
padding: var(--ha-space-1);
border-radius: var(--ha-border-radius-xl);
background-color: var(--ha-color-surface-low);
pointer-events: auto;
}
`,
];
}
@@ -1,31 +1,26 @@
import { mdiPackageVariant, mdiPlus, mdiWeb } from "@mdi/js";
import {
mdiDevices,
mdiFileCodeOutline,
mdiPackageVariant,
mdiWeb,
} from "@mdi/js";
import type { CSSResultGroup, TemplateResult } from "lit";
import { css, html, nothing } from "lit";
import { customElement, property, state } from "lit/decorators";
import { consumeLocalize } from "../../../common/decorators/consume-context-entry";
import type { LocalizeFunc } from "../../../common/translations/localize";
import "../../../components/ha-domain-icon";
import "../../../components/ha-icon";
import "../../../components/ha-icon-next";
import "../../../components/ha-label";
import "../../../components/ha-svg-icon";
import "../../../components/ha-tooltip";
import { HaListItemButton } from "../../../components/item/ha-list-item-button";
import { domainToName } from "../../../data/integration";
import type { IntegrationListItem } from "./add-integration-list";
import type { IntegrationListItem } from "./dialog-add-integration";
@customElement("ha-integration-list-item")
export class HaIntegrationListItem extends HaListItemButton {
@property({ attribute: false }) public integration!: IntegrationListItem;
// Padding, not margin, so the virtualized list measures it
@property({ type: Boolean, reflect: true }) public card = false;
@property({ type: Boolean, attribute: "opens-flow" }) public opensFlow =
false;
@property({ type: Boolean }) public discovered = false;
@state()
@consumeLocalize()
private _localize!: LocalizeFunc;
@@ -35,8 +30,11 @@ export class HaIntegrationListItem extends HaListItemButton {
return html`
<div part="start" class="start">
${
integration.icon
? html`<ha-icon .icon=${integration.icon}></ha-icon>`
integration.is_discovered
? html`<ha-svg-icon
class="discovered-icon"
.path=${mdiDevices}
></ha-svg-icon>`
: html`<ha-domain-icon
brand-fallback
.domain=${integration.domain}
@@ -60,13 +58,6 @@ export class HaIntegrationListItem extends HaListItemButton {
: nothing
}
</div>
${
integration.description
? html`<div part="supporting-text" class="supporting">
${integration.description}
</div>`
: nothing
}
</div>
`;
}
@@ -74,26 +65,14 @@ export class HaIntegrationListItem extends HaListItemButton {
protected override _renderEnd(): TemplateResult {
const integration = this.integration;
const yamlOnly =
!integration.result &&
!integration.config_flow &&
!integration.integrations &&
!integration.iot_standards;
return html`
<div part="end" class="end">
${
this.discovered
? html`<ha-label dense>
${this._localize("ui.panel.config.integrations.discovered")}
</ha-label>`
: nothing
}
${
integration.cloud
? html`<ha-svg-icon
id="icon-cloud"
class="status"
.path=${mdiWeb}
></ha-svg-icon>
? html`<ha-svg-icon id="icon-cloud" .path=${mdiWeb}></ha-svg-icon>
<ha-tooltip for="icon-cloud" placement="left">
${this._localize(
"ui.panel.config.integrations.config_entry.depends_on_cloud"
@@ -105,9 +84,9 @@ export class HaIntegrationListItem extends HaListItemButton {
!integration.is_built_in
? html`<ha-svg-icon
id="icon-custom"
class=${`status ${
class=${
integration.overwrites_built_in ? "overwrites" : "custom"
}`}
}
.path=${mdiPackageVariant}
></ha-svg-icon>
<ha-tooltip for="icon-custom" placement="left">
@@ -121,25 +100,17 @@ export class HaIntegrationListItem extends HaListItemButton {
}
${
yamlOnly
? html`<ha-label id="label-yaml" class="yaml" dense>
${this._localize(
"ui.panel.config.integrations.config_entry.yaml_label"
)}
</ha-label>
<ha-tooltip for="label-yaml" placement="left">
? html`<ha-svg-icon
id="icon-yaml"
.path=${mdiFileCodeOutline}
class="open-in-new"
></ha-svg-icon>
<ha-tooltip for="icon-yaml" placement="left">
${this._localize(
"ui.panel.config.integrations.config_entry.yaml_only"
)}
</ha-tooltip>`
: nothing
}
${
this.opensFlow && !yamlOnly
? html`<ha-svg-icon
class="add action"
.path=${mdiPlus}
></ha-svg-icon>`
: html`<ha-icon-next class="action"></ha-icon-next>`
: html`<ha-icon-next></ha-icon-next>`
}
</div>
`;
@@ -148,61 +119,31 @@ export class HaIntegrationListItem extends HaListItemButton {
static styles: CSSResultGroup = [
HaListItemButton.styles,
css`
:host([card]) {
padding: 0 var(--ha-space-4) var(--ha-space-2);
box-sizing: border-box;
--ha-list-item-focus-radius: var(--ha-border-radius-lg);
}
:host([card]) .base {
border: 1px solid var(--ha-color-border-neutral-quiet);
border-radius: var(--ha-border-radius-lg);
overflow: hidden;
}
.start {
--mdc-icon-size: 32px;
height: 32px;
}
/* The inline image's line box pushes it off center */
.start ha-domain-icon {
display: flex;
}
.end {
color: var(--ha-color-text-secondary);
display: flex;
align-items: center;
gap: var(--ha-space-1);
gap: var(--ha-space-2);
}
/* Raise the icons above the row's hit area so their tooltips open */
.end ha-svg-icon {
position: relative;
z-index: 1;
}
.end .status {
--mdc-icon-size: 20px;
}
.end .action {
margin-inline-start: var(--ha-space-2);
}
/* Below the row's hit area */
/* The chevron is decorative, keep it below the row's hit area */
.end ha-icon-next {
z-index: -1;
color: var(--ha-color-on-neutral-quiet);
}
.end ha-label {
border: none;
--ha-label-background-color: var(
--ha-color-fill-primary-normal-resting
);
--ha-label-text-color: var(--ha-color-on-primary-normal);
}
.end .add {
.discovered-icon {
color: var(--primary-color);
}
.end ha-label.yaml {
--ha-label-background-color: var(
--ha-color-fill-neutral-normal-resting
);
--ha-label-text-color: var(--ha-color-on-neutral-normal);
.open-in-new {
--mdc-icon-size: 22px;
padding: 1px;
}
.end .custom {
color: var(--warning-color);
@@ -1,33 +0,0 @@
import { css, html, LitElement } from "lit";
import { customElement } from "lit/decorators";
/**
* @element ha-integration-list-title
* @summary Title above a group of integration cards, like a brand's name.
* @slot - The title text.
*/
@customElement("ha-integration-list-title")
export class HaIntegrationListTitle extends LitElement {
protected render() {
return html`<slot></slot>`;
}
static styles = css`
:host {
display: flex;
align-items: center;
box-sizing: border-box;
min-height: var(--ha-space-10);
padding-block: var(--ha-space-2);
padding-inline: var(--ha-space-8) var(--ha-space-3);
font-weight: var(--ha-font-weight-medium);
background-color: var(--card-background-color);
}
`;
}
declare global {
interface HTMLElementTagNameMap {
"ha-integration-list-title": HaIntegrationListTitle;
}
}
@@ -8,8 +8,6 @@ export interface AddIntegrationDialogParams {
initialFilter?: string;
integrationFilter?: IntegrationFilter;
navigateToResult?: boolean;
// Opens on a category like `ai_voice`, or a subcategory like `ai_voice.ai_models`
category?: string;
}
export interface YamlIntegrationDialogParams {
@@ -65,8 +65,6 @@ export class HaGridLayoutSlider extends LitElement {
private _mc?: HammerManager;
private _keyboardChanging = false;
private get _range() {
return this.range ?? this.max;
}
@@ -188,7 +186,6 @@ export class HaGridLayoutSlider extends LitElement {
this.addEventListener("keydown", this._handleKeyDown);
this.addEventListener("keyup", this._handleKeyUp);
this.addEventListener("blur", this._endKeyboardChange);
}
}
@@ -199,7 +196,6 @@ export class HaGridLayoutSlider extends LitElement {
}
this.removeEventListener("keydown", this._handleKeyDown);
this.removeEventListener("keyup", this._handleKeyUp);
this.removeEventListener("blur", this._endKeyboardChange);
}
private get _tenPercentStep() {
@@ -235,19 +231,12 @@ export class HaGridLayoutSlider extends LitElement {
this.value = this.max;
break;
}
this._keyboardChanging = true;
fireEvent(this, "slider-moved", { value: this.value });
}
private _handleKeyUp(e: KeyboardEvent) {
if (!A11Y_KEY_CODES.has(e.code)) return;
e.preventDefault();
this._endKeyboardChange();
}
private _endKeyboardChange() {
if (!this._keyboardChanging) return;
this._keyboardChanging = false;
fireEvent(this, "value-changed", { value: this.value });
}
+1 -1
View File
@@ -280,7 +280,7 @@ class HUIRoot extends KeyboardShortcutMixin(LitElement) {
subItems: [
{
icon: mdiDevices,
key: "ui.panel.lovelace.menu.add_device_or_integration",
key: "ui.panel.lovelace.menu.add_device",
visible: true,
action: this._addDevice,
overflowAction: this._addDevice,
+4 -28
View File
@@ -8089,6 +8089,7 @@
"description": "Manage integrations with services or devices",
"integration": "integration",
"discovered": "Discovered",
"discovered_devices": "{count, plural,\n one {# discovered device}\n other {# discovered devices}\n}",
"manage_discovered": "Manage discovered devices",
"manage_discovered_description": "Ignore or configure previously discovered devices",
"disabled": "Disabled",
@@ -8096,7 +8097,7 @@
"new_flow": "Set up another instance of {integration}",
"attention": "Attention required",
"configured": "Configured",
"add_device_or_integration": "Add device or integration",
"new": "Select brand",
"confirm_new": "Do you want to set up {integration}?",
"add_integration": "Add integration",
"no_integrations": "Seems like you don't have any integrations configured yet. Press the button below to add your first integration!",
@@ -8117,31 +8118,7 @@
"search": "Search integrations",
"filters": "[%key:ui::components::subpage-data-table::filters%]",
"filters_disabled_hidden": "Filters, {number} disabled {number, plural,\n one {integration}\n other {integrations}\n} hidden",
"all_integrations": "All integrations",
"add_a_device": "Add a device",
"browse": "Browse",
"browse_by": {
"label": "Browse by: {value}",
"brand": "Brand",
"category": "Category"
},
"all_brands": "All brands",
"search_all": "Search all brands and integrations",
"search_section": {
"brand": "Brands",
"category": "Categories",
"integration": "Integrations",
"helper": "Helpers"
},
"search_show_more": "Show {count} more",
"subcategories": "Subcategories",
"connection": {
"label": "Connection: {value}",
"all": "All",
"local": "Local",
"cloud": "Cloud"
},
"search_no_results": "No results for “{term}”",
"search_brand": "Search for a brand name",
"search_helper": "Search for a helper",
"add_zwave_js_device": "Add Z-Wave device",
"add_zha_device": "Add Zigbee device",
@@ -8297,7 +8274,6 @@
"custom_overwrites_core": "Custom integration that replaces a Core component",
"depends_on_cloud": "Requires Internet",
"yaml_only": "This integration cannot be set up from the UI",
"yaml_label": "YAML",
"no_config_flow": "This integration was not set up from the UI",
"disabled_polling": "Automatic polling for updated data disabled",
"debug_logging_enabled": "Debug logging enabled",
@@ -10728,7 +10704,7 @@
"exit_edit_mode": "Done",
"close": "Close",
"add": "Add to Home Assistant",
"add_device_or_integration": "Add device or integration",
"add_device": "Add device",
"create_automation": "Create automation",
"create_area": "Create area",
"create_area_success": "Area created",
-41
View File
@@ -146,44 +146,3 @@ describe("ha-control-slider step bounds", () => {
expect(values).toEqual([99, 1]);
});
});
describe("ha-control-slider keyboard focus", () => {
const dispatch = (el: HaControlSlider, event: Event) =>
el.shadowRoot!.querySelector('[role="slider"]')!.dispatchEvent(event);
const key = (type: string) =>
new KeyboardEvent(type, {
code: "ArrowUp",
bubbles: true,
composed: true,
cancelable: true,
});
const changedValues = (el: HaControlSlider) => {
const values: (number | undefined)[] = [];
el.addEventListener("value-changed", (ev) => {
values.push((ev as CustomEvent).detail.value);
});
return values;
};
it("commits a held key's value when the slider loses focus", async () => {
const el = await mountSlider({ min: 0, max: 100, value: 50 });
const values = changedValues(el);
dispatch(el, key("keydown"));
dispatch(el, key("keydown"));
dispatch(el, new FocusEvent("blur"));
expect(values).toEqual([52]);
dispatch(el, key("keyup"));
expect(values).toEqual([52]);
});
it("does not commit again when the slider loses focus after the key is released", async () => {
const el = await mountSlider({ min: 0, max: 100, value: 50 });
const values = changedValues(el);
dispatch(el, key("keydown"));
dispatch(el, key("keyup"));
dispatch(el, new FocusEvent("blur"));
expect(values).toEqual([51]);
});
});
@@ -1,32 +0,0 @@
import { describe, expect, it } from "vitest";
import {
inCategory,
ofConnection,
} from "../../../../src/panels/config/integrations/add-integration-list";
describe("inCategory", () => {
it("matches a category, its subcategories, and only those", () => {
const categories = ["energy.ev_charging", "climate"];
expect(inCategory(categories)).toBe(true);
expect(inCategory(categories, "energy")).toBe(true);
expect(inCategory(categories, "energy", "ev_charging")).toBe(true);
expect(inCategory(categories, "energy", "solar")).toBe(false);
expect(inCategory(categories, "climate")).toBe(true);
expect(inCategory(categories, "climate", "thermostats")).toBe(false);
expect(inCategory(["energy_storage"], "energy")).toBe(false);
expect(inCategory(undefined, "energy")).toBe(false);
});
});
describe("ofConnection", () => {
it("keeps everything without a connection, else local or cloud", () => {
const local = { id: "a", domain: "a", name: "A" };
const cloud = { ...local, cloud: true };
expect(ofConnection(local)).toBe(true);
expect(ofConnection(cloud)).toBe(true);
expect(ofConnection(local, "local")).toBe(true);
expect(ofConnection(cloud, "local")).toBe(false);
expect(ofConnection(local, "cloud")).toBe(false);
expect(ofConnection(cloud, "cloud")).toBe(true);
});
});