fix area and user given name display (#3033)

This commit is contained in:
David F. Mulcahey 2019-03-29 17:02:13 -04:00 committed by Paulus Schoutsen
parent 7b821aa363
commit c134464f6a
2 changed files with 16 additions and 6 deletions

View File

@ -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 {

View File

@ -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[] {