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, ItemSelectedEvent,
SetAttributeServiceData, SetAttributeServiceData,
} from "./types"; } from "./types";
import { formatAsPaddedHex } from "./functions";
export class ZHAClusterAttributes extends LitElement { export class ZHAClusterAttributes extends LitElement {
public hass?: HomeAssistant; public hass?: HomeAssistant;
@ -102,7 +103,10 @@ export class ZHAClusterAttributes extends LitElement {
${this._attributes.map( ${this._attributes.map(
(entry) => html` (entry) => html`
<paper-item <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, IssueCommandServiceData,
ItemSelectedEvent, ItemSelectedEvent,
} from "./types"; } from "./types";
import { formatAsPaddedHex } from "./functions";
export class ZHAClusterCommands extends LitElement { export class ZHAClusterCommands extends LitElement {
public hass?: HomeAssistant; public hass?: HomeAssistant;
@ -94,7 +95,10 @@ export class ZHAClusterCommands extends LitElement {
${this._commands.map( ${this._commands.map(
(entry) => html` (entry) => html`
<paper-item <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 { HomeAssistant } from "../../../types";
import "../ha-config-section"; import "../ha-config-section";
import { ItemSelectedEvent } from "./types"; import { ItemSelectedEvent } from "./types";
import { formatAsPaddedHex } from "./functions";
declare global { declare global {
// for fire event // for fire event
@ -27,9 +28,9 @@ declare global {
} }
const computeClusterKey = (cluster: Cluster): string => { const computeClusterKey = (cluster: Cluster): string => {
return `${cluster.name} (Endpoint id: ${cluster.endpoint_id}, Id: ${ return `${cluster.name} (Endpoint id: ${
cluster.id cluster.endpoint_id
}, Type: ${cluster.type})`; }, Id: ${formatAsPaddedHex(cluster.id)}, Type: ${cluster.type})`;
}; };
export class ZHAClusters extends LitElement { export class ZHAClusters extends LitElement {