display values as hex so that they match the zigbee spec docs (#2751)

This commit is contained in:
David F. Mulcahey 2019-02-14 15:34:32 -05:00 committed by Paulus Schoutsen
parent 3f6bbffcd6
commit 8bf2a2f8db
4 changed files with 21 additions and 5 deletions

View File

@ -0,0 +1,7 @@
export const formatAsPaddedHex = (value: string | number): string => {
let hex = value;
if (typeof value === "string") {
hex = parseInt(value, 16);
}
return "0x" + hex.toString(16).padStart(4, "0");
};

View File

@ -28,6 +28,7 @@ import {
ItemSelectedEvent,
SetAttributeServiceData,
} from "./types";
import { formatAsPaddedHex } from "./functions";
export class ZHAClusterAttributes extends LitElement {
public hass?: HomeAssistant;
@ -102,7 +103,10 @@ export class ZHAClusterAttributes extends LitElement {
${this._attributes.map(
(entry) => html`
<paper-item
>${entry.name + " (id: " + entry.id + ")"}</paper-item
>${entry.name +
" (id: " +
formatAsPaddedHex(entry.id) +
")"}</paper-item
>
`
)}

View File

@ -24,6 +24,7 @@ import {
IssueCommandServiceData,
ItemSelectedEvent,
} from "./types";
import { formatAsPaddedHex } from "./functions";
export class ZHAClusterCommands extends LitElement {
public hass?: HomeAssistant;
@ -94,7 +95,10 @@ export class ZHAClusterCommands extends LitElement {
${this._commands.map(
(entry) => html`
<paper-item
>${entry.name + " (id: " + entry.id + ")"}</paper-item
>${entry.name +
" (id: " +
formatAsPaddedHex(entry.id) +
")"}</paper-item
>
`
)}

View File

@ -16,6 +16,7 @@ import { haStyle } from "../../../resources/ha-style";
import { HomeAssistant } from "../../../types";
import "../ha-config-section";
import { ItemSelectedEvent } from "./types";
import { formatAsPaddedHex } from "./functions";
declare global {
// for fire event
@ -27,9 +28,9 @@ declare global {
}
const computeClusterKey = (cluster: Cluster): string => {
return `${cluster.name} (Endpoint id: ${cluster.endpoint_id}, Id: ${
cluster.id
}, Type: ${cluster.type})`;
return `${cluster.name} (Endpoint id: ${
cluster.endpoint_id
}, Id: ${formatAsPaddedHex(cluster.id)}, Type: ${cluster.type})`;
};
export class ZHAClusters extends LitElement {