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