Skip to content

Commit

Permalink
use adapter version as Software/Hardware Version in Matter
Browse files Browse the repository at this point in the history
 partly addresses #175
  • Loading branch information
Apollon77 committed Nov 29, 2024
1 parent aa27e8c commit 85ae1fe
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
19 changes: 19 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class MatterAdapter extends utils.Adapter {
getText: (word: string, ...args: (string | number | boolean | null)[]) => ioBroker.Translated;
#nodeReSyncInProgress = new Set<string>();
#closing = false;
#version: string = '0.0.0';

public constructor(options: Partial<utils.AdapterOptions> = {}) {
super({
Expand Down Expand Up @@ -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<void> {
for (const device of this.#devices.values()) {
await device.stop();
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/matter/BridgedDevicesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ class BridgedDevices extends BaseServerNode {
return;
}

const versions = this.adapter.versions;
this.serverNode = await ServerNode.create({
id: this.#parameters.uuid,
network: {
Expand All @@ -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,
},
});

Expand Down
5 changes: 5 additions & 0 deletions src/matter/DeviceNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down

0 comments on commit 85ae1fe

Please sign in to comment.