diff --git a/src/data/device_registry.ts b/src/data/device_registry.ts
index 0a0b961dfe..348f85f8cb 100644
--- a/src/data/device_registry.ts
+++ b/src/data/device_registry.ts
@@ -10,10 +10,12 @@ export interface DeviceRegistryEntry {
sw_version?: string;
hub_device_id?: string;
area_id?: string;
+ name_by_user?: string;
}
export interface DeviceRegistryEntryMutableParams {
- area_id: string;
+ area_id?: string;
+ name_by_user?: string;
}
export const fetchDeviceRegistry = (hass: HomeAssistant) =>
diff --git a/src/data/zha.ts b/src/data/zha.ts
index 30b9cfbfa4..bdb965e5bd 100644
--- a/src/data/zha.ts
+++ b/src/data/zha.ts
@@ -14,6 +14,8 @@ export interface ZHADevice {
quirk_class: string;
entities: ZHAEntityReference[];
manufacturer_code: number;
+ device_reg_id: string;
+ user_given_name: string;
}
export interface Attribute {
diff --git a/src/panels/config/zha/zha-node.ts b/src/panels/config/zha/zha-node.ts
index 0cd4e6777e..959c7bc594 100644
--- a/src/panels/config/zha/zha-node.ts
+++ b/src/panels/config/zha/zha-node.ts
@@ -10,6 +10,7 @@ import {
import "@material/mwc-button";
import "@polymer/paper-card/paper-card";
import "@polymer/paper-icon-button/paper-icon-button";
+import "@polymer/paper-input/paper-input";
import "@polymer/paper-item/paper-item";
import "@polymer/paper-listbox/paper-listbox";
import { fireEvent } from "../../../common/dom/fire_event";
@@ -18,9 +19,13 @@ import "../../../components/ha-service-description";
import { haStyle } from "../../../resources/styles";
import { HomeAssistant } from "../../../types";
import "../ha-config-section";
-import { ItemSelectedEvent, NodeServiceData } from "./types";
+import { ItemSelectedEvent, NodeServiceData, ChangeEvent } from "./types";
import "./zha-clusters";
import "./zha-device-card";
+import {
+ updateDeviceRegistryEntry,
+ DeviceRegistryEntryMutableParams,
+} from "../../../data/device_registry";
import { reconfigureNode, fetchDevices, ZHADevice } from "../../../data/zha";
declare global {
@@ -40,6 +45,7 @@ export class ZHANode extends LitElement {
private _selectedNode?: ZHADevice;
private _serviceData?: {};
private _nodes: ZHADevice[];
+ private _userSelectedName?: string;
constructor() {
super();
@@ -58,6 +64,7 @@ export class ZHANode extends LitElement {
_entities: {},
_serviceData: {},
_nodes: {},
+ _userSelectedName: {},
};
}
@@ -109,7 +116,11 @@ export class ZHANode extends LitElement {
>
${this._nodes.map(
(entry) => html`
- ${entry.name}
+ ${entry.user_given_name
+ ? entry.user_given_name
+ : entry.name}
`
)}
@@ -132,6 +143,18 @@ export class ZHANode extends LitElement {
>
`
: ""}
+ ${this._selectedNodeIndex !== -1
+ ? html`
+
+ `
+ : ""}
${this._selectedNodeIndex !== -1 ? this._renderNodeActions() : ""}
${this._selectedNode ? this._renderClusters() : ""}
@@ -170,6 +193,21 @@ export class ZHANode extends LitElement {
/>
`
: ""}
+ Update Name
+ ${this._showHelp
+ ? html`
+
+ ${this.hass!.localize(
+ "ui.panel.config.zha.services.updateDeviceName"
+ )}
+
+ `
+ : ""}
`;
}
@@ -191,6 +229,7 @@ export class ZHANode extends LitElement {
private _selectedNodeChanged(event: ItemSelectedEvent): void {
this._selectedNodeIndex = event!.target!.selected;
this._selectedNode = this._nodes[this._selectedNodeIndex];
+ this._userSelectedName = "";
fireEvent(this, "zha-node-selected", { node: this._selectedNode });
this._serviceData = this._computeNodeServiceData();
}
@@ -201,6 +240,27 @@ export class ZHANode extends LitElement {
}
}
+ private _onUserSelectedNameChanged(value: ChangeEvent): void {
+ this._userSelectedName = value.detail!.value;
+ }
+
+ private async _onUpdateDeviceNameClick(): Promise {
+ if (this.hass) {
+ const values: DeviceRegistryEntryMutableParams = {
+ name_by_user: this._userSelectedName,
+ };
+
+ await updateDeviceRegistryEntry(
+ this.hass,
+ this._selectedNode!.device_reg_id,
+ values
+ );
+
+ this._selectedNode!.user_given_name = this._userSelectedName!;
+ this._userSelectedName = "";
+ }
+ }
+
private _computeNodeServiceData(): NodeServiceData {
return {
ieee_address: this._selectedNode!.ieee,
@@ -277,6 +337,7 @@ export class ZHANode extends LitElement {
padding-left: 28px;
padding-right: 28px;
padding-bottom: 10px;
+ word-wrap: break-word;
}
ha-service-description {
@@ -294,6 +355,12 @@ export class ZHANode extends LitElement {
right: 0;
color: var(--primary-color);
}
+
+ .input-text {
+ padding-left: 28px;
+ padding-right: 28px;
+ padding-bottom: 10px;
+ }
`,
];
}
diff --git a/src/translations/en.json b/src/translations/en.json
index d28a834f45..e9bcbd461a 100644
--- a/src/translations/en.json
+++ b/src/translations/en.json
@@ -874,7 +874,8 @@
"caption": "ZHA",
"description": "Zigbee Home Automation network management",
"services": {
- "reconfigure": "Reconfigure ZHA device (heal device). Use this if you are having issues with the device. If the device in question is a battery powered device please ensure it is awake and accepting commands when you use this service."
+ "reconfigure": "Reconfigure ZHA device (heal device). Use this if you are having issues with the device. If the device in question is a battery powered device please ensure it is awake and accepting commands when you use this service.",
+ "updateDeviceName": "Set a custom name for this device in the device registry."
}
},
"zwave": {