improve handling
This commit is contained in:
@@ -37,7 +37,7 @@ export class TidalService extends BaseService<TidalClient> {
|
||||
const response = await this.getClient().get<TidalGetCurrent>("current");
|
||||
|
||||
return this.getSuccessfulResult(
|
||||
this.decimalToPercentage(response.volume),
|
||||
response.volume * 100, // * 100 because it's a decimal and we want a percentage
|
||||
);
|
||||
} catch {
|
||||
const error_message = "error getting volume from tidal";
|
||||
@@ -47,18 +47,18 @@ export class TidalService extends BaseService<TidalClient> {
|
||||
}
|
||||
|
||||
clamp(value: number): number {
|
||||
return Math.min(Math.max(value, 0.0), 1.0);
|
||||
return Math.min(Math.max(value, 0), 100);
|
||||
}
|
||||
|
||||
async setVolume(argument: string): Promise<ServiceResult<number | string>> {
|
||||
const value = this.percentageToDecimal(parseInt(argument, 10));
|
||||
const value = parseInt(argument, 10);
|
||||
// relative
|
||||
const adjustMatch = argument.match(/^([+-])/);
|
||||
if (adjustMatch) {
|
||||
const req = await this.getVolume();
|
||||
if (req.successful) {
|
||||
const volume = req.result as number;
|
||||
const wantedVolume = this.percentageToDecimal(volume) + value;
|
||||
const wantedVolume = volume + value;
|
||||
const clampWantedVolume = this.clamp(wantedVolume);
|
||||
return await this.setVolumeToTidal(clampWantedVolume);
|
||||
}
|
||||
@@ -80,21 +80,16 @@ export class TidalService extends BaseService<TidalClient> {
|
||||
volume: number,
|
||||
): Promise<ServiceResult<number | string>> {
|
||||
try {
|
||||
await this.getClient().put<number>(`player/volume?volume=${volume}`, {});
|
||||
await this.getClient().put<number>(
|
||||
`player/volume?volume=${volume / 100}`, // / 100 because it's a decimal and we want a percentage
|
||||
{},
|
||||
);
|
||||
|
||||
return this.getSuccessfulResult(this.decimalToPercentage(volume));
|
||||
return this.getSuccessfulResult(volume.toFixed());
|
||||
} catch {
|
||||
const error_message = "error setting volume from tidal";
|
||||
logWarning(error_message);
|
||||
return this.getErrorResult(error_message);
|
||||
}
|
||||
}
|
||||
|
||||
decimalToPercentage(decimal: number): number {
|
||||
return decimal * 100;
|
||||
}
|
||||
|
||||
percentageToDecimal(percentage: number): number {
|
||||
return percentage / 100;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user