Skip to content

Commit

Permalink
fix washer remain duration
Browse files Browse the repository at this point in the history
  • Loading branch information
Jin committed Aug 2, 2021
1 parent 8becee8 commit 5f2261d
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/devices/WasherDryer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,8 @@ export class WasherDryerStatus {

public get remainDuration() {
const currentTimestamp = Math.floor(Date.now() / 1000);
if (!this.isRunning || !this.isPowerOn || (this.accessory.stopTime && this.accessory.stopTime < currentTimestamp)) {
if (!this.isRunning || !this.isPowerOn
|| (this.accessory.stopTime && (currentTimestamp - this.accessory.stopTime) >= currentTimestamp)) {
this.accessory.stopTime = 0;
return 0;
}
Expand All @@ -150,12 +151,12 @@ export class WasherDryerStatus {
this.data.remainTimeHour = 0;
}

const stopTime = currentTimestamp + this.data.remainTimeHour * 60 + this.data.remainTimeMinute * 60;
const stopTime = this.data.remainTimeHour * 3600 + this.data.remainTimeMinute * 60;

if (!this.accessory.stopTime || Math.abs(stopTime - this.accessory.stopTime) > 120 /* 2 min different */) {
this.accessory.stopTime = stopTime;
}

return this.accessory.stopTime - currentTimestamp;
return this.accessory.stopTime;
}
}

0 comments on commit 5f2261d

Please sign in to comment.