diff --git a/src/helpers/hardware_types.ts b/src/helpers/module_properties.ts similarity index 64% rename from src/helpers/hardware_types.ts rename to src/helpers/module_properties.ts index 195e409..65fb5af 100644 --- a/src/helpers/hardware_types.ts +++ b/src/helpers/module_properties.ts @@ -1,3 +1,27 @@ +export interface LcnSerial { + year: number; + month: number; + day: number; + serial?: number; +} + +const serialRegExp = + /(?[A-F0-9]{2}).(?[A-F0-9])(?[A-F0-9]{2})(?[A-F0-9]{4})?/; + +export function parseSerialNumber(serial_number: number): LcnSerial { + const result = serialRegExp.exec(serial_number.toString(16).toUpperCase()); + if (!result) throw new Error("Wrong serial number"); + + const is_software_serial = result![4] === undefined; + + return { + year: Number("0x" + result![1]) + 1990, + month: Number("0x" + result![2]), + day: Number("0x" + result![3]), + serial: is_software_serial ? undefined : Number("0x" + result![4]), + }; +} + export function getHardwareType(hardwareId: number): string | undefined { switch (hardwareId) { case 1: diff --git a/src/lcn-devices-page.ts b/src/lcn-devices-page.ts index dbc1a1a..0c26a29 100644 --- a/src/lcn-devices-page.ts +++ b/src/lcn-devices-page.ts @@ -1,6 +1,7 @@ import { consume } from "@lit-labs/context"; import { deviceConfigsContext } from "components/context"; import { haStyle } from "@ha/resources/styles"; +import "@lrnwebcomponents/simple-tooltip/simple-tooltip"; import "@material/mwc-button"; import "@ha/components/ha-clickable-list-item"; import "@ha/components/ha-fab"; @@ -9,7 +10,6 @@ import "@ha/components/ha-list-item"; import "@ha/components/ha-md-menu-item"; import "@ha/components/ha-help-tooltip"; import "@ha/components/ha-icon-button"; -import "@ha/components/ha-switch"; import "@ha/components/ha-checkbox"; import "@ha/components/ha-formfield"; import { stopPropagation } from "@ha/common/dom/stop_propagation"; @@ -36,7 +36,7 @@ import { navigate } from "@ha/common/navigate"; import type { HASSDomEvent } from "@ha/common/dom/fire_event"; import { updateDeviceConfigs, updateEntityConfigs } from "components/events"; import { renderBrandLogo } from "helpers/brand_logo"; -import { getHardwareType } from "helpers/hardware_types"; +import { getHardwareType, parseSerialNumber, LcnSerial } from "helpers/module_properties"; import { ProgressDialog } from "./dialogs/progress-dialog"; import { loadLCNCreateDeviceDialog, @@ -162,16 +162,14 @@ export class LCNConfigDashboard extends LitElement { sortable: true, filterable: true, defaultHidden: true, - template: (entry) => - entry.hardware_serial !== -1 ? entry.hardware_serial.toString(16).toUpperCase() : "-", + template: (entry) => this.renderHardwareSerial(entry.hardware_serial), }, software_serial: { title: this.lcn.localize("software-serial"), sortable: true, filterable: true, defaultHidden: true, - template: (entry) => - entry.software_serial !== -1 ? entry.software_serial.toString(16).toUpperCase() : "-", + template: (entry) => this.renderSoftwareSerial(entry.software_serial), }, hardware_type: { title: this.lcn.localize("hardware-type"), @@ -213,6 +211,48 @@ export class LCNConfigDashboard extends LitElement { this._dataTable.then(renderBrandLogo); } + protected renderSoftwareSerial(software_serial: number) { + let serial: LcnSerial; + try { + serial = parseSerialNumber(software_serial); + } catch (error) { + return html`-`; + } + + return html` + ${software_serial.toString(16).toUpperCase()} + + ${this.lcn.localize("firmware-date", { + year: serial.year, + month: serial.month, + day: serial.day, + })} + + `; + } + + protected renderHardwareSerial(hardware_serial: number) { + let serial: LcnSerial; + try { + serial = parseSerialNumber(hardware_serial); + } catch (error) { + return html`-`; + } + + return html` + ${hardware_serial.toString(16).toUpperCase()} + + ${this.lcn.localize("hardware-date", { + year: serial.year, + month: serial.month, + day: serial.day, + })} +
+ ${this.lcn.localize("hardware-number", { serial: serial.serial })} +
+ `; + } + protected render() { if (!(this.hass && this.lcn && this._deviceConfigs)) { return nothing; diff --git a/src/localize/languages/de.json b/src/localize/languages/de.json index a18349e..0b46140 100644 --- a/src/localize/languages/de.json +++ b/src/localize/languages/de.json @@ -23,6 +23,10 @@ "addresses": "Adressen", "modulesgroups": "Module / Gruppen", + "firmware-date": "Firmware Datum: {day}.{month}.{year}", + "hardware-date": "Modul Datum: {day}.{month}.{year}", + "hardware-number": "Nummer: {serial}", + "domain": "Domäne", "binary-sensor": "Binärsensor", "climate": "Klima", diff --git a/src/localize/languages/en.json b/src/localize/languages/en.json index 72829a6..5be0afb 100644 --- a/src/localize/languages/en.json +++ b/src/localize/languages/en.json @@ -23,6 +23,10 @@ "addresses": "Addresses", "modulesgroups": "Modules / Groups", + "firmware-date": "Firmware date: {month}/{day}/{year}", + "hardware-date": "Module date: {month}/{day}/{year}", + "hardware-number": "Module number: {serial}", + "domain": "Domain", "binary-sensor": "Binary sensor", "climate": "Climate",