You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

35 lines
1.0 KiB

import { deepFreeze, isFiniteNumber } from "../../utils/index.js";
import { CyclingPowerCapabilities } from "./cyclingPower.js";
export class Control {
constructor({
supportsERG = false,
controlCharacteristic,
maxPowerWatts,
minPowerWatts,
ergRampRateWattsPerSec,
cyclingPower,
} = {}) {
this.supportsERG = Boolean(supportsERG);
this.controlCharacteristic = controlCharacteristic;
this.maxPowerWatts = isFiniteNumber(maxPowerWatts)
? Number(maxPowerWatts)
: undefined;
this.minPowerWatts = isFiniteNumber(minPowerWatts)
? Number(minPowerWatts)
: undefined;
this.ergRampRateWattsPerSec = isFiniteNumber(ergRampRateWattsPerSec)
? Number(ergRampRateWattsPerSec)
: undefined;
this.cyclingPower =
cyclingPower instanceof CyclingPowerCapabilities
? cyclingPower
: cyclingPower
? new CyclingPowerCapabilities(cyclingPower)
: undefined;
deepFreeze(this);
}
merge = (partial) => new Control(Object.assign({}, this, partial));
}