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

Sync LevelControl with chip #33204 #848

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,14 @@ export class LevelControlServerLogic extends LevelControlLogicBase {
);
}

#determineEffectiveMoveRate(rate: number | null) {
const effectiveRate = rate ?? this.state.defaultMoveRate ?? null;
if (effectiveRate === 0) {
throw new StatusResponseError("A move rate of 0 is invalid.", StatusCode.InvalidCommand);
}
return effectiveRate;
}

/**
* Default implementation notes:
* After the options checks it uses the {@link moveLogic} method to set the level.
Expand All @@ -209,7 +217,7 @@ export class LevelControlServerLogic extends LevelControlLogicBase {
return;
}

return this.moveLogic(moveMode, rate, false);
return this.moveLogic(moveMode, this.#determineEffectiveMoveRate(rate), false);
}

/**
Expand All @@ -221,7 +229,7 @@ export class LevelControlServerLogic extends LevelControlLogicBase {
* level is increased or decreased by the step size every second.
*/
override moveWithOnOff({ moveMode, rate }: MoveWithOnOffRequest) {
return this.moveLogic(moveMode, rate, true);
return this.moveLogic(moveMode, this.#determineEffectiveMoveRate(rate), true);
}

/**
Expand All @@ -236,20 +244,14 @@ export class LevelControlServerLogic extends LevelControlLogicBase {
* @protected
*/
protected moveLogic(moveMode: LevelControl.MoveMode, rate: number | null, withOnOff: boolean) {
const effectiveRate = rate ?? this.state.defaultMoveRate ?? null;
if (!this.state.managedTransitionTimeHandling || effectiveRate === null || effectiveRate === 0) {
if (!this.state.managedTransitionTimeHandling || rate === null) {
// If null rate is requested and also no default rate is set, we should move as fast as possible, so we set
// to min/max value directly. If rate 0 is requested no change on level should be done.
const level =
effectiveRate === 0
? this.currentLevel
: moveMode === LevelControl.MoveMode.Up
? this.maxLevel
: this.minLevel;
const level = moveMode === LevelControl.MoveMode.Up ? this.maxLevel : this.minLevel;
this.setRemainingTime(0);
return this.setLevel(level, withOnOff);
}
return this.#initiateTransition(effectiveRate, moveMode as unknown as LevelControl.StepMode, withOnOff);
return this.#initiateTransition(rate, moveMode as unknown as LevelControl.StepMode, withOnOff);
}

/**
Expand Down
Loading