Skip to content

Commit

Permalink
Use finishes_at in timer remaining calculation (#22169)
Browse files Browse the repository at this point in the history
* Use finishes_at in timer remaining calculation

* lint

* fix test
  • Loading branch information
karwosts authored Oct 1, 2024
1 parent 4c2044e commit ce9993f
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/data/timer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export const timerTimeRemaining = (

if (stateObj.state === "active") {
const now = new Date().getTime();
const madeActive = new Date(stateObj.last_changed).getTime();
timeRemaining = Math.max(timeRemaining - (now - madeActive) / 1000, 0);
const finishes = new Date(stateObj.attributes.finishes_at).getTime();
timeRemaining = Math.max((finishes - now) / 1000, 0);
}

return timeRemaining;
Expand Down
2 changes: 1 addition & 1 deletion test/common/entity/timer_time_remaining_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ describe("timerTimeRemaining", () => {
state: "active",
attributes: {
remaining: "0:01:05",
finishes_at: "2018-01-17T16:16:17+00:00",
},
last_changed: "2018-01-17T16:15:12Z",
} as any),
47
);
Expand Down

0 comments on commit ce9993f

Please sign in to comment.