Compare commits

...

4 Commits

Author SHA1 Message Date
Aidan Timson
ca2344eb10 Show url in label 2025-12-09 16:55:23 +00:00
Aidan Timson
6c9f51071c Reuse device page logic 2025-12-09 16:21:32 +00:00
Aidan Timson
0c1f57e2ce Follow device page link handling 2025-12-09 16:19:32 +00:00
Aidan Timson
e573f2012e Add configuration url link to config entry row 2025-12-09 16:17:55 +00:00
4 changed files with 84 additions and 37 deletions

View File

@@ -0,0 +1,29 @@
export interface ProcessedConfigurationUrl {
url: string;
isLocal: boolean;
}
/**
* Get a processed configuration URL, converting homeassistant:// URLs to local paths
* and determining if it should be opened locally or in a new tab.
*
* @param configurationUrl - The configuration URL to process
* @returns Processed URL and whether it's a local link, or null if URL is empty
*/
export const getConfigurationUrl = (
configurationUrl: string | null | undefined
): ProcessedConfigurationUrl | null => {
if (!configurationUrl) {
return null;
}
const isHomeAssistant = configurationUrl.startsWith("homeassistant://");
const url = isHomeAssistant
? configurationUrl.replace("homeassistant://", "/")
: configurationUrl;
return {
url,
isLocal: isHomeAssistant,
};
};

View File

@@ -27,6 +27,7 @@ export interface ConfigEntry {
reason: string | null; reason: string | null;
error_reason_translation_key: string | null; error_reason_translation_key: string | null;
error_reason_translation_placeholders: Record<string, string> | null; error_reason_translation_placeholders: Record<string, string> | null;
configuration_url?: string | null;
} }
export interface SubEntry { export interface SubEntry {

View File

@@ -26,6 +26,7 @@ import { computeStateName } from "../../../common/entity/compute_state_name";
import { stringCompare } from "../../../common/string/compare"; import { stringCompare } from "../../../common/string/compare";
import { slugify } from "../../../common/string/slugify"; import { slugify } from "../../../common/string/slugify";
import { groupBy } from "../../../common/util/group-by"; import { groupBy } from "../../../common/util/group-by";
import { getConfigurationUrl } from "../../../common/util/configuration-url";
import "../../../components/entity/ha-battery-icon"; import "../../../components/entity/ha-battery-icon";
import "../../../components/ha-alert"; import "../../../components/ha-alert";
import "../../../components/ha-button"; import "../../../components/ha-button";
@@ -1090,17 +1091,12 @@ export class HaConfigDevicePage extends LitElement {
const deviceActions: DeviceAction[] = []; const deviceActions: DeviceAction[] = [];
const configurationUrlIsHomeAssistant = const processedUrl = getConfigurationUrl(device.configuration_url);
device.configuration_url?.startsWith("homeassistant://") || false;
const configurationUrl = configurationUrlIsHomeAssistant if (processedUrl) {
? device.configuration_url!.replace("homeassistant://", "/")
: device.configuration_url;
if (configurationUrl) {
deviceActions.push({ deviceActions.push({
href: configurationUrl, href: processedUrl.url,
target: configurationUrlIsHomeAssistant ? undefined : "_blank", target: processedUrl.isLocal ? undefined : "_blank",
icon: mdiCog, icon: mdiCog,
label: this.hass.localize( label: this.hass.localize(
"ui.panel.config.devices.open_configuration_url" "ui.panel.config.devices.open_configuration_url"

View File

@@ -8,6 +8,7 @@ import {
mdiDotsVertical, mdiDotsVertical,
mdiDownload, mdiDownload,
mdiHandExtendedOutline, mdiHandExtendedOutline,
mdiOpenInNew,
mdiPlayCircleOutline, mdiPlayCircleOutline,
mdiPlus, mdiPlus,
mdiProgressHelper, mdiProgressHelper,
@@ -73,6 +74,7 @@ import "./ha-config-entry-device-row";
import { renderConfigEntryError } from "./ha-config-integration-page"; import { renderConfigEntryError } from "./ha-config-integration-page";
import "./ha-config-sub-entry-row"; import "./ha-config-sub-entry-row";
import { copyToClipboard } from "../../../common/util/copy-clipboard"; import { copyToClipboard } from "../../../common/util/copy-clipboard";
import { getConfigurationUrl } from "../../../common/util/configuration-url";
import { showToast } from "../../../util/toast"; import { showToast } from "../../../util/toast";
@customElement("ha-config-entry-row") @customElement("ha-config-entry-row")
@@ -213,7 +215,24 @@ class HaConfigEntryRow extends LitElement {
? html`<ha-button slot="end" @click=${this._handleEnable}> ? html`<ha-button slot="end" @click=${this._handleEnable}>
${this.hass.localize("ui.common.enable")} ${this.hass.localize("ui.common.enable")}
</ha-button>` </ha-button>`
: configPanel && : (() => {
const processedUrl = getConfigurationUrl(item.configuration_url);
return html`
${processedUrl
? html`<a
slot="end"
href=${processedUrl.url}
target=${processedUrl.isLocal ? undefined : "_blank"}
rel=${processedUrl.isLocal ? undefined : "noreferrer"}
>
<ha-icon-button
.path=${mdiOpenInNew}
.label=${processedUrl.url}
></ha-icon-button>
</a>`
: nothing}
${configPanel &&
(item.domain !== "matter" || (item.domain !== "matter" ||
isDevVersion(this.hass.config.version)) && isDevVersion(this.hass.config.version)) &&
!stateText !stateText
@@ -241,6 +260,8 @@ class HaConfigEntryRow extends LitElement {
</ha-icon-button> </ha-icon-button>
` `
: nothing} : nothing}
`;
})()}
<ha-md-button-menu positioning="popover" slot="end"> <ha-md-button-menu positioning="popover" slot="end">
<ha-icon-button <ha-icon-button
slot="trigger" slot="trigger"