Skip to content

Commit

Permalink
feat: Prevent setting NaN for Remaining Duration
Browse files Browse the repository at this point in the history
  • Loading branch information
QuickSander committed Dec 19, 2021
1 parent 7471d77 commit df4a902
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/mieleCharacteristics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ export class MieleRemainingDurationCharacteristic extends MieleBaseCharacteristi
//-------------------------------------------------------------------------------------------------
update(response: MieleStatusResponse): void {
let value = response.remainingTime[0]*3600 + response.remainingTime[1]*60;
this.platform.log.debug(`${this.deviceName}: Remaing Duration update received: ${value}[s]`);
this.platform.log.debug(`${this.deviceName}: Remaining Duration update received: ${value}[s]`);

// Clip to min and max value.
const characteristic = this.service.getCharacteristic(this.platform.Characteristic.RemainingDuration);
Expand All @@ -313,6 +313,12 @@ export class MieleRemainingDurationCharacteristic extends MieleBaseCharacteristi
value = value < minValue ? minValue : value;
}

// DO not allow any invalid value to pass through.
if(typeof(value)!=='number' || Number.isNaN(value)) {
this.platform.log.debug(`${this.deviceName}: Prevented setting NaN or another non-number type for Remaining Duration.`);
value = 0;
}

this.updateCharacteristic(value, false);
}

Expand Down

0 comments on commit df4a902

Please sign in to comment.