Skip to content

Commit

Permalink
Fix rotation speed percentage
Browse files Browse the repository at this point in the history
  • Loading branch information
JobDoesburg committed Aug 1, 2024
1 parent d98c26c commit 9491472
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/accessory/characteristic/RotationSpeed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,20 @@ export function configureRotationSpeedLevel(
range.push(value);
}

const props = { minValue: 0, maxValue: range.length, minStep: 1, unit: 'speed' };
const props = { minValue: 0, maxValue: 100, minStep: Math.floor(100/range.length), unit: 'speed' };
accessory.log.debug('Set props for RotationSpeed:', props);

const onGetHandler = () => {
const status = accessory.getStatus(schema.code)!;
const index = range.indexOf(status.value as string);
return limit(index + 1, props.minValue, props.maxValue);
return limit((Math.floor(100/range.length) * (index + 1)), props.minValue, props.maxValue);
};

service.getCharacteristic(accessory.Characteristic.RotationSpeed)
.onGet(onGetHandler)
.onSet(async value => {
accessory.log.debug('Set RotationSpeed to:', value);
const index = Math.round(value as number - 1);
const index = Math.round((value as number)/Math.floor(100/range.length)) - 1;
if (index < 0 || index >= range.length) {
accessory.log.debug('Out of range, return.');
return;
Expand Down

0 comments on commit 9491472

Please sign in to comment.