Skip to content

Commit

Permalink
Sensor bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
vrnagy committed Oct 6, 2020
1 parent caa19d9 commit 3674ef8
Showing 1 changed file with 12 additions and 9 deletions.
21 changes: 12 additions & 9 deletions custom_components/prusa_mini/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,16 +89,19 @@ def time_est(self, state):
if state is None or state == "":
return ""

delta = timedelta(seconds=state)
delta = timedelta(seconds=int(state))
days = delta.days
hours, remainder = divmod(delta.seconds, 3600)
minutes, seconds = divmod(remainder, 60)
parts = []

if delta.days > 0:
parts.append(f"{delta.days}d")
if delta.hours > 0:
parts.append(f"{delta.days}h")
if delta.minutes > 0:
parts.append(f"{delta.minutes}m")
if delta.seconds > 0:
parts.append(f"{delta.seconds}s")
if days > 0:
parts.append(f"{days}d")
if hours > 0:
parts.append(f"{hours}h")
if minutes > 0:
parts.append(f"{minutes}m")
if seconds > 0:
parts.append(f"{seconds}s")

return " ".join(parts)

0 comments on commit 3674ef8

Please sign in to comment.