Skip to content

Commit

Permalink
update matter lib
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollon77 committed Mar 28, 2024
1 parent f91f4fe commit 8145f9c
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 7 deletions.
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@
"url": "https://github.com/ioBroker/ioBroker.matter"
},
"optionalDependencies": {
"@project-chip/matter-node-ble.js": "0.8.0-alpha.0-20240314-ed7b831b"
"@project-chip/matter-node-ble.js": "0.8.0-alpha.0-20240328-858ab599"
},
"dependencies": {
"@iobroker/adapter-core": "^3.0.4",
"@project-chip/matter-node.js": "0.8.0-alpha.0-20240314-ed7b831b",
"@project-chip/matter.js": "0.8.0-alpha.0-20240314-ed7b831b",
"@project-chip/matter-node.js": "0.8.0-alpha.0-20240328-858ab599",
"@project-chip/matter.js": "0.8.0-alpha.0-20240328-858ab599",
"@iobroker/type-detector": "^3.0.5",
"@iobroker/dm-utils": "^0.1.9",
"axios": "^1.6.7",
Expand All @@ -50,7 +50,7 @@
"eslint-plugin-promise": "^6.1.1",
"gulp": "^4.0.2",
"mocha": "^10.3.0",
"typescript": "5.4.2"
"typescript": "~5.4.3"
},
"bugs": {
"url": "https://github.com/ioBroker/ioBroker.matter/issues"
Expand Down
46 changes: 43 additions & 3 deletions src/matter/IoBrokerNodeStorage.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
import { fromJson, Storage, StorageError, SupportedStorageTypes, toJson } from '@project-chip/matter.js/storage';
import {
fromJson,
StorageError,
SupportedStorageTypes,
SyncStorage,
toJson
} from '@project-chip/matter.js/storage';

/**
* Class that implements the storage for one Node in the Matter ecosystem
*/
export class IoBrokerNodeStorage implements Storage {
export class IoBrokerNodeStorage implements SyncStorage {
private data: Record<string, any> = {};
private savingNumber: number = 1;
private readonly savingPromises: Record<string, Promise<void>> = {};
Expand Down Expand Up @@ -72,6 +78,22 @@ export class IoBrokerNodeStorage implements Storage {
return value as T;
}

contexts(contexts: string[]): string[] {
const contextKeyStart = this.buildKey(contexts, '');
const len = contextKeyStart.length;

const thisContexts = new Array<string>();
Object.keys(this.data)
.filter(key => key.startsWith(contextKeyStart) && key.indexOf('$$', len) !== -1)
.forEach(key => {
const context = key.substring(len, key.indexOf('$$', len));
if (!thisContexts.includes(context)) {
thisContexts.push(context);
}
});
return thisContexts;
}

keys(contexts: string[]): string[] {
const contextKeyStart = this.buildKey(contexts, '');
const len = contextKeyStart.length;
Expand All @@ -81,6 +103,14 @@ export class IoBrokerNodeStorage implements Storage {
.map(key => key.substring(len));
}

values(contexts: string[]): Record<string, SupportedStorageTypes> {
const values = {} as Record<string, SupportedStorageTypes>;
for (const key in this.keys(contexts)) {
values[key] = this.get(contexts,key);
}
return values;
}

saveKey(oid: string, value: string): void {
const index = this.savingNumber++;
if (this.savingNumber >= 0xFFFFFFFF) {
Expand Down Expand Up @@ -132,7 +162,7 @@ export class IoBrokerNodeStorage implements Storage {
}
}

set<T extends SupportedStorageTypes>(contexts: string[], key: string, value: T): void {
#setKey(contexts: string[], key: string, value: SupportedStorageTypes): void {
if (!key.length) {
throw new StorageError('[STORAGE] Context and key must not be empty strings!');
}
Expand All @@ -142,6 +172,16 @@ export class IoBrokerNodeStorage implements Storage {
this.saveKey(oid, toJson(value));
}

set(contexts: string[], keyOrValue: string | Record<string, SupportedStorageTypes>, value?: SupportedStorageTypes): void {
if (typeof keyOrValue === 'string') {
this.#setKey(contexts, keyOrValue, value as SupportedStorageTypes);
} else {
for (const key in keyOrValue) {
this.#setKey(contexts, key, keyOrValue[key]);
}
}
}

delete(contexts: string[], key: string): void {
if (!key.length) {
throw new StorageError('[STORAGE] Context and key must not be empty strings!');
Expand Down

0 comments on commit 8145f9c

Please sign in to comment.