Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update 26.01.25 #2 #361

Merged
merged 2 commits into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,13 @@ 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
* (@Apollon77) Added support to also select folders when adding devices
* (@Apollon77) Fixed Illuminance State type min/max

### 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-admin/src/Tabs/Bridges.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,7 @@ export class Bridges extends BridgesAndDevices<BridgesProps, BridgesState> {
<SelectID
imagePrefix="../.."
dialogName="matter"
types={addDeviceDialog.detectionType === 'device' ? ['device', 'channel'] : ['state']}
types={addDeviceDialog.detectionType === 'device' ? ['device', 'channel', 'folder'] : ['state']}
themeType={this.props.themeType}
socket={this.props.socket}
theme={this.props.theme}
Expand Down
2 changes: 1 addition & 1 deletion src-admin/src/Tabs/Devices.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -592,7 +592,7 @@ class Devices extends BridgesAndDevices<DevicesProps, DevicesState> {
return (
<SelectID
imagePrefix="../.."
types={addDeviceDialog.detectionType === 'device' ? ['device', 'channel'] : ['state']}
types={addDeviceDialog.detectionType === 'device' ? ['device', 'channel', 'folder'] : ['state']}
dialogName="matter"
themeType={this.props.themeType}
socket={this.props.socket}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/devices/Illuminance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export class Illuminance extends GenericDevice {
this.addDeviceStates([
{
name: 'ACTUAL',
valueType: ValueType.NumberPercent,
valueType: ValueType.Number,
accessType: StateAccessType.Read,
type: PropertyType.Brightness,
callback: state => (this.#getBrightnessState = state),
Expand Down
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
Loading