From 0585d7c01622b2b4b2b64f1cd5e18d2e9b028f2b Mon Sep 17 00:00:00 2001 From: Ingo Fischer Date: Sat, 25 Jan 2025 14:41:55 +0100 Subject: [PATCH] WC/Blind adjustments --- README.md | 1 + .../to-iobroker/WindowCoveringToIoBroker.ts | 12 ++++---- src/matter/to-matter/BlindsToMatter.ts | 30 ++++++++++--------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 8b3cac0..83d8fc7 100644 --- a/README.md +++ b/README.md @@ -79,6 +79,7 @@ With the ioBroker Matter Adapter it is possible to map the following use cases: ### __WORK IN PROGRESS__ * (@Apollon77) Fixed Thermostat initialization logic and added more logging +* (@Apollon77) Fixed WindowCovering level to match ioBroker definition * (@Apollon77) Updated matter.js for further optimizations ### 0.4.4 (2025-01-24) diff --git a/src/matter/to-iobroker/WindowCoveringToIoBroker.ts b/src/matter/to-iobroker/WindowCoveringToIoBroker.ts index 8ca472b..8654f7a 100644 --- a/src/matter/to-iobroker/WindowCoveringToIoBroker.ts +++ b/src/matter/to-iobroker/WindowCoveringToIoBroker.ts @@ -129,7 +129,7 @@ export class WindowCoveringToIoBroker extends GenericElectricityDataDeviceToIoBr this.updateWorkingStateForLift(value).catch(e => this.ioBrokerDevice.adapter.log.error(`Failed to update working state: ${e}`), ); - return Math.round(value / 100); + return 100 - Math.round(value / 100); }, changeHandler: async value => { if ( @@ -138,7 +138,7 @@ export class WindowCoveringToIoBroker extends GenericElectricityDataDeviceToIoBr throw new Error('Position aware lift not supported. Can not set lift target percentage'); } await this.appEndpoint.getClusterClient(WindowCovering.Complete)?.goToLiftPercentage({ - liftPercent100thsValue: Math.round(value * 100), + liftPercent100thsValue: Math.round(100 - value) * 100, }); }, }); @@ -146,7 +146,7 @@ export class WindowCoveringToIoBroker extends GenericElectricityDataDeviceToIoBr endpointId: this.appEndpoint.getNumber(), clusterId: WindowCovering.Cluster.id, attributeName: 'currentPositionLiftPercent100ths', - convertValue: value => Math.round(value / 100), + convertValue: value => 100 - Math.round(value / 100), }); this.enableDeviceTypeStateForAttribute(PropertyType.Stop, { @@ -184,7 +184,7 @@ export class WindowCoveringToIoBroker extends GenericElectricityDataDeviceToIoBr this.updateWorkingStateForTilt(value).catch(e => this.ioBrokerDevice.adapter.log.error(`Failed to update working state: ${e}`), ); - return Math.round(value / 100); + return 100 - Math.round(value / 100); }, changeHandler: async value => { if ( @@ -193,7 +193,7 @@ export class WindowCoveringToIoBroker extends GenericElectricityDataDeviceToIoBr throw new Error('Position aware tilt not supported. Can not set tilt target percentage'); } await this.appEndpoint.getClusterClient(WindowCovering.Complete)?.goToTiltPercentage({ - tiltPercent100thsValue: Math.round(value * 100), + tiltPercent100thsValue: Math.round(100 - value) * 100, }); }, }); @@ -201,7 +201,7 @@ export class WindowCoveringToIoBroker extends GenericElectricityDataDeviceToIoBr endpointId: this.appEndpoint.getNumber(), clusterId: WindowCovering.Cluster.id, attributeName: 'currentPositionTiltPercent100ths', - convertValue: value => Math.round(value / 100), + convertValue: value => 100 - Math.round(value / 100), }); } diff --git a/src/matter/to-matter/BlindsToMatter.ts b/src/matter/to-matter/BlindsToMatter.ts index 9e9635a..db0c688 100644 --- a/src/matter/to-matter/BlindsToMatter.ts +++ b/src/matter/to-matter/BlindsToMatter.ts @@ -92,8 +92,8 @@ export class BlindsToMatter extends GenericDeviceToMatter { ) { await this.#matterEndpoint.setStateOf(EventedWindowCoveringServer, { // @ts-expect-error Workaround a matter.js instancing/typing error - currentPositionTiltPercent100ths: (this.#ioBrokerDevice.getTiltLevel() ?? 0) * 100, - targetPositionTiltPercent100ths: (this.#ioBrokerDevice.getTiltLevel() ?? 0) * 100, + currentPositionTiltPercent100ths: Math.round(100 - (this.#ioBrokerDevice.getTiltLevel() ?? 0)) * 100, + targetPositionTiltPercent100ths: Math.round(100 - (this.#ioBrokerDevice.getTiltLevel() ?? 0)) * 100, }); } if ( @@ -102,8 +102,10 @@ export class BlindsToMatter extends GenericDeviceToMatter { ) { await this.#matterEndpoint.setStateOf(EventedWindowCoveringServer, { // @ts-expect-error Workaround a matter.js instancing/typing error - currentPositionLiftPercent100ths: ((this.#ioBrokerDevice as Blind).getLevel() ?? 0) * 100, - targetPositionLiftPercent100ths: ((this.#ioBrokerDevice as Blind).getLevel() ?? 0) * 100, + currentPositionLiftPercent100ths: + Math.round(100 - ((this.#ioBrokerDevice as Blind).getLevel() ?? 0)) * 100, + targetPositionLiftPercent100ths: + Math.round(100 - ((this.#ioBrokerDevice as Blind).getLevel() ?? 0)) * 100, }); } @@ -121,19 +123,19 @@ export class BlindsToMatter extends GenericDeviceToMatter { targetPercent100ths !== undefined && this.#ioBrokerDevice.hasLiftLevel() ) { - await (this.#ioBrokerDevice as Blind).setLevel(Math.round(targetPercent100ths / 100)); + await (this.#ioBrokerDevice as Blind).setLevel(100 - Math.round(targetPercent100ths / 100)); } else { if (direction === MovementDirection.Open || reversed) { if (this.#ioBrokerDevice.hasLiftButtons()) { await (this.#ioBrokerDevice as BlindButtons).setOpen(); } else if (this.#ioBrokerDevice.hasLiftLevel()) { - await (this.#ioBrokerDevice as Blind).setLevel(reversed ? 100 : 0); + await (this.#ioBrokerDevice as Blind).setLevel(reversed ? 0 : 100); } } else { if (this.#ioBrokerDevice.hasLiftButtons()) { await (this.#ioBrokerDevice as BlindButtons).setClose(); } else if (this.#ioBrokerDevice.hasLiftLevel()) { - await (this.#ioBrokerDevice as Blind).setLevel(reversed ? 0 : 100); + await (this.#ioBrokerDevice as Blind).setLevel(reversed ? 100 : 0); } } } @@ -146,19 +148,19 @@ export class BlindsToMatter extends GenericDeviceToMatter { targetPercent100ths !== undefined && this.#ioBrokerDevice.hasTiltLevel() ) { - await this.#ioBrokerDevice.setTiltLevel(Math.round(targetPercent100ths / 100)); + await this.#ioBrokerDevice.setTiltLevel(100 - Math.round(targetPercent100ths / 100)); } else { if (direction === MovementDirection.Open || reversed) { if (this.#ioBrokerDevice.hasTiltButtons()) { await (this.#ioBrokerDevice as BlindButtons).setTiltOpen(); } else if (this.#ioBrokerDevice.hasTiltLevel()) { - await (this.#ioBrokerDevice as Blind).setLevel(reversed ? 100 : 0); + await (this.#ioBrokerDevice as Blind).setLevel(reversed ? 0 : 100); } } else { if (this.#ioBrokerDevice.hasTiltButtons()) { await (this.#ioBrokerDevice as BlindButtons).setTiltClose(); } else if (this.#ioBrokerDevice.hasTiltLevel()) { - await (this.#ioBrokerDevice as Blind).setLevel(reversed ? 0 : 100); + await (this.#ioBrokerDevice as Blind).setLevel(reversed ? 100 : 0); } } } @@ -199,12 +201,12 @@ export class BlindsToMatter extends GenericDeviceToMatter { ) { await this.#matterEndpoint.setStateOf(EventedWindowCoveringServer, { // @ts-expect-error Workaround a matter.js instancing/typing error - currentPositionTiltPercent100ths: (event.value as number) * 100, + currentPositionTiltPercent100ths: Math.round(100 - event.value) * 100, }); if (event.property === PropertyType.TiltLevel) { await this.#matterEndpoint.setStateOf(EventedWindowCoveringServer, { // @ts-expect-error Workaround a matter.js instancing/typing error - targetPositionTiltPercent100ths: (event.value as number) * 100, + targetPositionTiltPercent100ths: Math.round(100 - event.value) * 100, }); } } @@ -217,12 +219,12 @@ export class BlindsToMatter extends GenericDeviceToMatter { ) { await this.#matterEndpoint.setStateOf(EventedWindowCoveringServer, { // @ts-expect-error Workaround a matter.js instancing/typing error - currentPositionLiftPercent100ths: (event.value as number) * 100, + currentPositionLiftPercent100ths: Math.round(100 - event.value) * 100, }); if (event.property === PropertyType.Level) { await this.#matterEndpoint.setStateOf(EventedWindowCoveringServer, { // @ts-expect-error Workaround a matter.js instancing/typing error - targetPositionLiftPercent100ths: (event.value as number) * 100, + targetPositionLiftPercent100ths: Math.round(100 - event.value) * 100, }); } }