mirror of
https://github.com/home-assistant/frontend.git
synced 2025-07-28 03:36:44 +00:00
fix sorting and use user given name if available
This commit is contained in:
parent
8df9ac9dfa
commit
5257715145
@ -1,3 +1,5 @@
|
|||||||
|
import { ZHADevice } from "../../../data/zha";
|
||||||
|
|
||||||
export const formatAsPaddedHex = (value: string | number): string => {
|
export const formatAsPaddedHex = (value: string | number): string => {
|
||||||
let hex = value;
|
let hex = value;
|
||||||
if (typeof value === "string") {
|
if (typeof value === "string") {
|
||||||
@ -5,3 +7,9 @@ export const formatAsPaddedHex = (value: string | number): string => {
|
|||||||
}
|
}
|
||||||
return "0x" + hex.toString(16).padStart(4, "0");
|
return "0x" + hex.toString(16).padStart(4, "0");
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const sortZHADevices = (a: ZHADevice, b: ZHADevice): number => {
|
||||||
|
const nameA = a.user_given_name ? a.user_given_name : a.name;
|
||||||
|
const nameb = b.user_given_name ? b.user_given_name : b.name;
|
||||||
|
return nameA.localeCompare(nameb);
|
||||||
|
};
|
||||||
|
@ -20,6 +20,7 @@ import { HASSDomEvent } from "../../../common/dom/fire_event";
|
|||||||
import { Cluster, fetchBindableDevices, ZHADevice } from "../../../data/zha";
|
import { Cluster, fetchBindableDevices, ZHADevice } from "../../../data/zha";
|
||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } from "../../../resources/styles";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
|
import { sortZHADevices } from "./functions";
|
||||||
import { ZHAClusterSelectedParams, ZHADeviceSelectedParams } from "./types";
|
import { ZHAClusterSelectedParams, ZHADeviceSelectedParams } from "./types";
|
||||||
|
|
||||||
export class HaConfigZha extends LitElement {
|
export class HaConfigZha extends LitElement {
|
||||||
@ -99,9 +100,7 @@ export class HaConfigZha extends LitElement {
|
|||||||
this._bindableDevices = (await fetchBindableDevices(
|
this._bindableDevices = (await fetchBindableDevices(
|
||||||
this.hass,
|
this.hass,
|
||||||
this._selectedDevice!.ieee
|
this._selectedDevice!.ieee
|
||||||
)).sort((a, b) => {
|
)).sort(sortZHADevices);
|
||||||
return a.name.localeCompare(b.name);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,6 +22,7 @@ import { bindDevices, unbindDevices, ZHADevice } from "../../../data/zha";
|
|||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } from "../../../resources/styles";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
import { ItemSelectedEvent } from "./types";
|
import { ItemSelectedEvent } from "./types";
|
||||||
|
import "@polymer/paper-item/paper-item";
|
||||||
|
|
||||||
@customElement("zha-binding-control")
|
@customElement("zha-binding-control")
|
||||||
export class ZHABindingControl extends LitElement {
|
export class ZHABindingControl extends LitElement {
|
||||||
@ -64,7 +65,11 @@ export class ZHABindingControl extends LitElement {
|
|||||||
>
|
>
|
||||||
${this.bindableDevices.map(
|
${this.bindableDevices.map(
|
||||||
(device) => html`
|
(device) => html`
|
||||||
<paper-item>${device.name}</paper-item>
|
<paper-item
|
||||||
|
>${device.user_given_name
|
||||||
|
? device.user_given_name
|
||||||
|
: device.name}</paper-item
|
||||||
|
>
|
||||||
`
|
`
|
||||||
)}
|
)}
|
||||||
</paper-listbox>
|
</paper-listbox>
|
||||||
|
@ -24,6 +24,7 @@ import { fireEvent } from "../../../common/dom/fire_event";
|
|||||||
import { fetchDevices, ZHADevice } from "../../../data/zha";
|
import { fetchDevices, ZHADevice } from "../../../data/zha";
|
||||||
import { haStyle } from "../../../resources/styles";
|
import { haStyle } from "../../../resources/styles";
|
||||||
import { HomeAssistant } from "../../../types";
|
import { HomeAssistant } from "../../../types";
|
||||||
|
import { sortZHADevices } from "./functions";
|
||||||
import { ItemSelectedEvent, ZHADeviceRemovedEvent } from "./types";
|
import { ItemSelectedEvent, ZHADeviceRemovedEvent } from "./types";
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
@ -141,9 +142,7 @@ export class ZHANode extends LitElement {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async _fetchDevices() {
|
private async _fetchDevices() {
|
||||||
this._nodes = (await fetchDevices(this.hass!)).sort((a, b) => {
|
this._nodes = (await fetchDevices(this.hass!)).sort(sortZHADevices);
|
||||||
return a.name.localeCompare(b.name);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private _onDeviceRemoved(event: ZHADeviceRemovedEvent): void {
|
private _onDeviceRemoved(event: ZHADeviceRemovedEvent): void {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user