Skip to content

Commit

Permalink
WC/Blind adjustments
Browse files Browse the repository at this point in the history
  • Loading branch information
Apollon77 committed Jan 25, 2025
1 parent 06cf69e commit 0585d7c
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 20 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 6 additions & 6 deletions src/matter/to-iobroker/WindowCoveringToIoBroker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -138,15 +138,15 @@ 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,
});
},
});
this.enableDeviceTypeStateForAttribute(PropertyType.LevelActual, {
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, {
Expand Down Expand Up @@ -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 (
Expand All @@ -193,15 +193,15 @@ 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,
});
},
});
this.enableDeviceTypeStateForAttribute(PropertyType.TiltLevelActual, {
endpointId: this.appEndpoint.getNumber(),
clusterId: WindowCovering.Cluster.id,
attributeName: 'currentPositionTiltPercent100ths',
convertValue: value => Math.round(value / 100),
convertValue: value => 100 - Math.round(value / 100),
});
}

Expand Down
30 changes: 16 additions & 14 deletions src/matter/to-matter/BlindsToMatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -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,
});
}

Expand All @@ -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);
}
}
}
Expand All @@ -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);
}
}
}
Expand Down Expand Up @@ -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,
});
}
}
Expand All @@ -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,
});
}
}
Expand Down

0 comments on commit 0585d7c

Please sign in to comment.