From 642d1e4b38bdc8e582ffb4c91c9384fc5eaa9a83 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Wed, 16 Apr 2025 08:09:17 -1000 Subject: [PATCH] Add initial DHCP discovery panel --- .../device-detail/ha-device-info-card.ts | 16 +++++++++++--- .../dhcp/dhcp-config-panel.ts | 21 +++++++++++++++++-- 2 files changed, 32 insertions(+), 5 deletions(-) diff --git a/src/panels/config/devices/device-detail/ha-device-info-card.ts b/src/panels/config/devices/device-detail/ha-device-info-card.ts index 0602d6fa00..dba2bbfa66 100644 --- a/src/panels/config/devices/device-detail/ha-device-info-card.ts +++ b/src/panels/config/devices/device-detail/ha-device-info-card.ts @@ -8,6 +8,7 @@ import type { DeviceRegistryEntry } from "../../../../data/device_registry"; import { haStyle } from "../../../../resources/styles"; import type { HomeAssistant } from "../../../../types"; import { createSearchParam } from "../../../../common/url/search-params"; +import { isComponentLoaded } from "../../../../common/config/is_component_loaded"; @customElement("ha-device-info-card") export class HaDeviceCard extends LitElement { @@ -103,7 +104,8 @@ export class HaDeviceCard extends LitElement { ${this._getAddresses().map( ([type, value]) => html`
- ${type === "bluetooth" + ${type === "bluetooth" && + isComponentLoaded(this.hass, "bluetooth") ? html`${titleCase(type)} ${value.toUpperCase()}` - : html`${type === "mac" ? "MAC" : titleCase(type)}: - ${value.toUpperCase()}`} + : type === "mac" && isComponentLoaded(this.hass, "dhcp") + ? html`${titleCase(type)} + ${value.toUpperCase()}` + : html`${type === "mac" ? "MAC" : titleCase(type)}: + ${value.toUpperCase()}`}
` )} diff --git a/src/panels/config/integrations/integration-panels/dhcp/dhcp-config-panel.ts b/src/panels/config/integrations/integration-panels/dhcp/dhcp-config-panel.ts index 124028cc7e..70fa5ece10 100644 --- a/src/panels/config/integrations/integration-panels/dhcp/dhcp-config-panel.ts +++ b/src/panels/config/integrations/integration-panels/dhcp/dhcp-config-panel.ts @@ -1,10 +1,11 @@ -import type { CSSResultGroup, TemplateResult } from "lit"; +import type { CSSResultGroup, TemplateResult, PropertyValues } from "lit"; import { html, LitElement } from "lit"; import { customElement, property, state } from "lit/decorators"; import memoizeOne from "memoize-one"; import type { UnsubscribeFunc } from "home-assistant-js-websocket"; import type { LocalizeFunc } from "../../../../../common/translations/localize"; import type { DataTableColumnContainer } from "../../../../../components/data-table/ha-data-table"; +import { extractSearchParamsObject } from "../../../../../common/url/search-params"; import "../../../../../components/ha-fab"; import "../../../../../components/ha-icon-button"; import "../../../../../layouts/hass-tabs-subpage-data-table"; @@ -20,6 +21,8 @@ export class DHCPConfigPanel extends LitElement { @property({ attribute: false }) public route!: Route; + @property({ attribute: false }) public mac_address?: string; + @property({ type: Boolean }) public narrow = false; @property({ attribute: "is-wide", type: Boolean }) public isWide = false; @@ -82,6 +85,20 @@ export class DHCPConfigPanel extends LitElement { })) ); + protected willUpdate(changedProps: PropertyValues) { + super.willUpdate(changedProps); + + if (this.hasUpdated) { + return; + } + + const searchParams = extractSearchParamsObject(); + const mac_address = searchParams.mac_address; + if (mac_address) { + this.mac_address = mac_address; + } + } + protected render(): TemplateResult { return html` `; }