mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-21 08:16:36 +00:00
fix area and user given name display (#3033)
This commit is contained in:
parent
7b821aa363
commit
c134464f6a
@ -15,8 +15,8 @@ export interface ZHADevice {
|
||||
entities: ZHAEntityReference[];
|
||||
manufacturer_code: number;
|
||||
device_reg_id: string;
|
||||
user_given_name: string;
|
||||
area_id: string;
|
||||
user_given_name?: string;
|
||||
area_id?: string;
|
||||
}
|
||||
|
||||
export interface Attribute {
|
||||
|
@ -55,6 +55,7 @@ class ZHADeviceCard extends LitElement {
|
||||
@property() private _serviceData?: NodeServiceData;
|
||||
@property() private _areas: AreaRegistryEntry[] = [];
|
||||
@property() private _selectedAreaIndex: number = -1;
|
||||
@property() private _userGivenName?: string;
|
||||
|
||||
public firstUpdated(changedProperties: PropertyValues): void {
|
||||
super.firstUpdated(changedProperties);
|
||||
@ -71,9 +72,15 @@ class ZHADeviceCard extends LitElement {
|
||||
|
||||
protected updated(changedProperties: PropertyValues): void {
|
||||
if (changedProperties.has("device")) {
|
||||
if (!this._areas || !this.device || !this.device.area_id) {
|
||||
this._selectedAreaIndex = 0;
|
||||
} else {
|
||||
this._selectedAreaIndex =
|
||||
this._areas.findIndex((area) => area.area_id === this.device!.area_id) +
|
||||
1;
|
||||
this._areas.findIndex(
|
||||
(area) => area.area_id === this.device!.area_id
|
||||
) + 1;
|
||||
}
|
||||
this._userGivenName = this.device!.user_given_name;
|
||||
}
|
||||
super.update(changedProperties);
|
||||
}
|
||||
@ -150,6 +157,7 @@ class ZHADeviceCard extends LitElement {
|
||||
<paper-input
|
||||
type="string"
|
||||
@change="${this._saveCustomName}"
|
||||
.value="${this._userGivenName}"
|
||||
placeholder="${this.hass!.localize(
|
||||
"ui.panel.config.zha.device_card.device_name_placeholder"
|
||||
)}"
|
||||
@ -265,10 +273,12 @@ class ZHADeviceCard extends LitElement {
|
||||
return;
|
||||
}
|
||||
|
||||
const newAreaId = area ? area.area_id : undefined;
|
||||
await updateDeviceRegistryEntry(this.hass!, this.device.device_reg_id, {
|
||||
area_id: area ? area.area_id : undefined,
|
||||
area_id: newAreaId,
|
||||
name_by_user: this.device!.user_given_name,
|
||||
});
|
||||
this.device!.area_id = newAreaId;
|
||||
}
|
||||
|
||||
static get styles(): CSSResult[] {
|
||||
|
Loading…
x
Reference in New Issue
Block a user