diff --git a/src/main.ts b/src/main.ts index fe3ff1a0..48d8d979 100644 --- a/src/main.ts +++ b/src/main.ts @@ -88,6 +88,7 @@ export class MatterAdapter extends utils.Adapter { getText: (word: string, ...args: (string | number | boolean | null)[]) => ioBroker.Translated; #nodeReSyncInProgress = new Set(); #closing = false; + #version: string = '0.0.0'; public constructor(options: Partial = {}) { super({ @@ -130,6 +131,17 @@ export class MatterAdapter extends utils.Adapter { return this.#controller; } + get versions(): { versionStr: string; versionNum: number } { + const versionParts = this.#version.split('.'); + // Create a numeric version number from the version string, multiply parts from end to start with 100^index + const numVersion = versionParts.reduce((acc, part, index) => acc + parseInt(part) * Math.pow(100, index), 0); + + return { + versionStr: this.#version, + versionNum: numVersion, + }; + } + async shutDownMatterNodes(): Promise { for (const device of this.#devices.values()) { await device.stop(); @@ -411,6 +423,13 @@ export class MatterAdapter extends utils.Adapter { ); } } + + try { + this.#version = require('./package.json').version; + } catch (error) { + this.log.error(`Can not read version from package.json: ${error}`); + } + // init i18n const i18n = await I18n; await i18n.init(`${__dirname}/lib`, this); diff --git a/src/matter/BridgedDevicesNode.ts b/src/matter/BridgedDevicesNode.ts index fb22859c..42136ccb 100644 --- a/src/matter/BridgedDevicesNode.ts +++ b/src/matter/BridgedDevicesNode.ts @@ -140,6 +140,7 @@ class BridgedDevices extends BaseServerNode { return; } + const versions = this.adapter.versions; this.serverNode = await ServerNode.create({ id: this.#parameters.uuid, network: { @@ -158,6 +159,10 @@ class BridgedDevices extends BaseServerNode { productId, serialNumber: uniqueId, uniqueId: md5(uniqueId), + hardwareVersion: versions.versionNum, + hardwareVersionString: versions.versionStr, + softwareVersion: versions.versionNum, + softwareVersionString: versions.versionStr, }, }); diff --git a/src/matter/DeviceNode.ts b/src/matter/DeviceNode.ts index a5c8a8ed..0c32a93a 100644 --- a/src/matter/DeviceNode.ts +++ b/src/matter/DeviceNode.ts @@ -84,6 +84,7 @@ class Device extends BaseServerNode { // The device type to announce we use from the first returned endpoint of the device const deviceType = endpoints[0].type.deviceType; + const versions = this.adapter.versions; try { this.serverNode = await ServerNode.create({ id: this.#parameters.uuid, @@ -103,6 +104,10 @@ class Device extends BaseServerNode { productId, serialNumber: uniqueId, uniqueId: md5(uniqueId), + hardwareVersion: versions.versionNum, + hardwareVersionString: versions.versionStr, + softwareVersion: versions.versionNum, + softwareVersionString: versions.versionStr, }, }); } catch (error) {