diff --git a/README.md b/README.md index b183cd5..93dfbc0 100644 --- a/README.md +++ b/README.md @@ -76,6 +76,11 @@ With the ioBroker Matter Adapter, it is possible to map the following use cases: --> ## Changelog + +### __WORK IN PROGRESS__ +* (@Apollon77) Enhanced error and invalid devices display for UI +* (@Apollon77) Fixed Button Press Controller support + ### 0.4.8 (2025-01-26) * (@Apollon77) Acknowledges Power states also on SET states * (@Apollon77) Fixed Color Temperature handling for devices diff --git a/src-admin/package-lock.json b/src-admin/package-lock.json index 5b86e98..dc30895 100644 --- a/src-admin/package-lock.json +++ b/src-admin/package-lock.json @@ -1,12 +1,12 @@ { "name": "iobroker.matter", - "version": "0.4.7", + "version": "0.4.8", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "iobroker.matter", - "version": "0.4.7", + "version": "0.4.8", "dependencies": { "@foxriver76/iob-component-lib": "^0.2.0", "@iobroker/adapter-react-v5": "^7.4.18", diff --git a/src/main.ts b/src/main.ts index 0eb991b..8a4276e 100644 --- a/src/main.ts +++ b/src/main.ts @@ -624,7 +624,7 @@ export class MatterAdapter extends utils.Adapter { (objParts[0] === 'bridges' && objPartsLength === 2)) && !obj ) { - this.log.warn(`Object ${id} deleted ... trying to also remove it from matter`); + this.log.debug(`Object ${id} deleted ... trying to also remove it from matter`); // We try to restore a minimum object that we can handle the deletion obj = { _id: id, diff --git a/src/matter/BridgedDevicesNode.ts b/src/matter/BridgedDevicesNode.ts index 7c38473..22e5b4c 100644 --- a/src/matter/BridgedDevicesNode.ts +++ b/src/matter/BridgedDevicesNode.ts @@ -402,10 +402,12 @@ class BridgedDevices extends BaseServerNode { if (bridgedDeviceUuid === undefined) { const error = this.error; - if (Array.isArray(error)) { + if (error) { details.error = { __header__error: 'Error information', - __text__info: `${error.length} Bridged Device(s) are in an error state. Fix the errors before enabling it again.`, + __text__info: Array.isArray(error) + ? `${error.length} Bridged Device(s) are in an error state. Fix the errors before enabling it again.` + : `The Bridge could not be initialized. Please check the logfile for more information.`, __text__info2: `Please refer to the error details at the bridged device level.`, uuid: this.uuid, }; @@ -413,8 +415,9 @@ class BridgedDevices extends BaseServerNode { // The error boolean state should never end here because then this object should have not been created } } else { - const { error } = this.#devices.get(bridgedDeviceUuid) ?? {}; - if (error) { + const { error, device } = this.#devices.get(bridgedDeviceUuid) ?? {}; + const isValid = device?.isValid; + if (error || !isValid) { details.error = { __header__error: 'Error information', __text__info: `Bridged Device is in an error state. Fix the error before enabling it again.`, diff --git a/src/matter/to-iobroker/GenericDeviceToIoBroker.ts b/src/matter/to-iobroker/GenericDeviceToIoBroker.ts index c3d7da2..ea10369 100644 --- a/src/matter/to-iobroker/GenericDeviceToIoBroker.ts +++ b/src/matter/to-iobroker/GenericDeviceToIoBroker.ts @@ -1,4 +1,11 @@ -import { type AttributeId, type ClusterId, Diagnostic, EndpointNumber, type EventId, MaybePromise } from '@matter/main'; +import { + type MaybePromise, + type AttributeId, + type ClusterId, + type EventId, + Diagnostic, + EndpointNumber, +} from '@matter/main'; import { BasicInformation, BridgedDeviceBasicInformation, Identify, PowerSource } from '@matter/main/clusters'; import type { DecodedEventData } from '@matter/main/protocol'; import type { Endpoint, PairedNode, DeviceBasicInformation } from '@project-chip/matter.js/device'; @@ -355,10 +362,7 @@ export abstract class GenericDeviceToIoBroker { } const { convertValue } = properties; if (convertValue !== undefined) { - value = convertValue(value); - if (MaybePromise.is(value)) { - value = await value; - } + value = await convertValue(value); } if (value !== undefined) { try { @@ -386,13 +390,10 @@ export abstract class GenericDeviceToIoBroker { return; } if (typeof pathProperty === 'function') { - const result = pathProperty(data.value); - if (MaybePromise.is(result)) { - await result; - } + await pathProperty(data.value); return; } - return this.updateIoBrokerState(pathProperty, data.value); + await this.updateIoBrokerState(pathProperty, data.value); } async handleTriggeredEvent(data: { @@ -404,15 +405,15 @@ export abstract class GenericDeviceToIoBroker { }): Promise { const pathId = eventPathToString(data); const pathProperty = this.#matterMappings.get(pathId); + this.#adapter.log.debug( + `Handle event ${pathId} with property type ${typeof pathProperty === 'function' ? 'function' : pathProperty}`, + ); if (pathProperty === undefined) { return; } if (typeof pathProperty === 'function') { for (const event of data.events) { - const result = pathProperty(event); - if (MaybePromise.is(result)) { - await result; - } + await pathProperty(event); } return; } @@ -422,12 +423,14 @@ export abstract class GenericDeviceToIoBroker { } for (const { convertValue } of propertyHandlers) { for (const event of data.events) { - let value = convertValue(pathProperty, event); + const value = await convertValue(pathProperty, event); if (value !== undefined) { - if (MaybePromise.is(value)) { - value = await value; + this.#adapter.log.debug(`Update state for ${pathId} and type ${pathProperty} with value ${value}`); + try { + await this.ioBrokerDevice.updatePropertyValue(pathProperty, value); + } catch (e) { + this.#adapter.log.error(`Error updating property ${pathProperty} with value ${value}: ${e}`); } - await this.updateIoBrokerState(pathProperty, value); } } } diff --git a/src/matter/to-matter/GenericDeviceToMatter.ts b/src/matter/to-matter/GenericDeviceToMatter.ts index 86b9bc4..134738d 100644 --- a/src/matter/to-matter/GenericDeviceToMatter.ts +++ b/src/matter/to-matter/GenericDeviceToMatter.ts @@ -49,6 +49,9 @@ export abstract class GenericDeviceToMatter { await this.registerHandlersAndInitialize(); this.ioBrokerDevice.on('validChanged', () => { const valid = this.ioBrokerDevice.isValid; + this.ioBrokerDevice.adapter.log.info( + `Device ${this.name} is now ${valid ? 'valid' : 'invalid'} (before: ${this.#valid ? 'valid' : 'invalid'})`, + ); if (valid === this.#valid) { return; }