Skip to content

Commit

Permalink
Update 26.01.25 #2
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollon77 committed Jan 26, 2025
1 parent 826f6e3 commit c6a65d6
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 25 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions src-admin/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
11 changes: 7 additions & 4 deletions src/matter/BridgedDevicesNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -402,19 +402,22 @@ 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,
};
} else {
// 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.`,
Expand Down
39 changes: 21 additions & 18 deletions src/matter/to-iobroker/GenericDeviceToIoBroker.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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: {
Expand All @@ -404,15 +405,15 @@ export abstract class GenericDeviceToIoBroker {
}): Promise<void> {
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;
}
Expand All @@ -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);
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions src/matter/to-matter/GenericDeviceToMatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit c6a65d6

Please sign in to comment.