diff --git a/io-package.json b/io-package.json index 63c59b28..2f7f436b 100644 --- a/io-package.json +++ b/io-package.json @@ -152,6 +152,9 @@ "sentry": { "dsn": "https://de38f4a20c964ce395d2e236c64aa075@sentry.iobroker.net/234" } + }, + "supportedMessages": { + "deviceManager": true } }, "protectedNative": [ diff --git a/package.json b/package.json index 8677453a..bbdf9bf2 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "@iobroker/adapter-core": "^3.0.4", "@project-chip/matter-node.js": "0.7.2-alpha.0-20231128-db9207d2", "@iobroker/type-detector": "^3.0.5", + "@jey-cee/dm-utils": "^0.0.5", "axios": "^1.6.2", "jsonwebtoken": "^9.0.2" }, diff --git a/src/lib/DeviceManagement.ts b/src/lib/DeviceManagement.ts new file mode 100644 index 00000000..e9fbb073 --- /dev/null +++ b/src/lib/DeviceManagement.ts @@ -0,0 +1,85 @@ +import { MatterAdapter } from '../main'; + +import { DeviceManagement, DeviceInfo, RetVal, DeviceStatus } from '@jey-cee/dm-utils'; + + +class MatterAdapterDeviceManagement extends DeviceManagement { + // contents see in the next chapters + // todo!!: this function must be async + // @ts-ignore + async listDevices(): Promise> { + const devices = await this.adapter.getDevicesAsync(); + // const devices = await this.adapter.getObjectView('system', 'device', { startkey: `system.adapter.matter.${this.instance}.`, endkey: 'system.adapter.matter.999' }); + const arrDevices: DeviceInfo[] = []; + for (const i in devices) { + let status: DeviceStatus = 'disconnected'; + + const alive = await this.adapter.getStateAsync(`${devices[i]._id}.info.connection`); + if (alive !== null && alive !== undefined) { + status = alive.val ? 'connected' : 'disconnected'; + } + + // const manufacturer = await this.adapter.getStateAsync(`${devices[i]._id}._info.brand`); + // + // const product = await this.adapter.getStateAsync(`${devices[i]._id}._info.product`); + // const arch = await this.adapter.getStateAsync(`${devices[i]._id}._info.arch`); + // const model = `${product?.val} ${arch?.val}`; + + const res: DeviceInfo = { + id: devices[i]._id, + name: devices[i].common.name, + // icon: devices[i].common.icon ? devices[i].common.icon : null, + // manufacturer: manufacturer ? manufacturer.val : null, + // model: model ? model : null, + status, + hasDetails: true, + actions: [ + /* { + id: 'delete', + icon: 'fa-solid fa-trash-can', + description: { + en: 'Delete this device', + de: 'Gerät löschen', + ru: 'Удалить это устройство', + pt: 'Excluir este dispositivo', + nl: 'Verwijder dit apparaat', + fr: 'Supprimer cet appareil', + it: 'Elimina questo dispositivo', + es: 'Eliminar este dispositivo', + pl: 'Usuń to urządzenie', + 'zh-cn': '删除此设备', + uk: 'Видалити цей пристрій' + }, + handler: this.handleDeleteDevice.bind(this) + }, + { + id: 'rename', + icon: 'fa-solid fa-pen', + description: { + en: 'Rename this device', + de: 'Gerät umbenennen', + ru: 'Переименовать это устройство', + pt: 'Renomear este dispositivo', + nl: 'Hernoem dit apparaat', + fr: 'Renommer cet appareil', + it: 'Rinomina questo dispositivo', + es: 'Renombrar este dispositivo', + pl: 'Zmień nazwę tego urządzenia', + 'zh-cn': '重命名此设备', + uk: 'Перейменуйте цей пристрій' + }, + handler: this.handleRenameDevice.bind(this) + }*/ + ] + }; + // if id contains gateway remove res.actions + if (devices[i]._id.includes('localhost')) { + res.actions = []; + } + arrDevices.push(res); + } + return arrDevices; + } +} + +export default MatterAdapterDeviceManagement; diff --git a/src/main.ts b/src/main.ts index 1fc9df9b..b891221a 100644 --- a/src/main.ts +++ b/src/main.ts @@ -22,6 +22,8 @@ import { } from './ioBrokerStorageTypes'; import MatterController, {ControllerOptions} from './matter/ControllerNode'; +import MatterAdapterDeviceManagement from './lib/DeviceManagement'; + const IOBROKER_USER_API = 'https://iobroker.pro:3001'; // If the device was created by user and user defined the type of device => use this OID as given name @@ -88,6 +90,7 @@ export class MatterAdapter extends utils.Adapter { private license: { [key: string]: boolean | undefined } = {}; private controller: MatterController | null = null; private sysLanguage: 'en' | 'de' | 'ru' | 'pt' | 'nl' | 'fr' | 'it' | 'es' | 'pl' | 'zh-cn' = 'en'; + private readonly deviceManagement: MatterAdapterDeviceManagement; public constructor(options: Partial = {}) { super({ @@ -109,6 +112,7 @@ export class MatterAdapter extends utils.Adapter { this.on('objectChange', (id /* , object */) => this.onObjectChange(id)); this.on('unload', callback => this.onUnload(callback)); this.on('message', this.onMessage.bind(this)); + this.deviceManagement = new MatterAdapterDeviceManagement(this); this.detector = new ChannelDetector(); } @@ -128,6 +132,10 @@ export class MatterAdapter extends utils.Adapter { } async onMessage(obj: ioBroker.Message): Promise { + if (obj?.command?.startsWith('dm:')) { + return; + } + if (obj?.command === 'reset') { await this.onTotalReset(); } else if (obj?.command === 'nodeStates') { @@ -788,4 +796,4 @@ if (require.main !== module) { } else { // otherwise start the instance directly (() => new MatterAdapter())(); -} \ No newline at end of file +}