Skip to content

Commit

Permalink
Fix autoupdate time compare (#4897)
Browse files Browse the repository at this point in the history
* Fix autoupdate time compare

Make sure both timestamps are UTC, otherwise Python complains with:
TypeError: can't compare offset-naive and offset-aware datetimes

* Use correect attribute

---------

Co-authored-by: Pascal Vizeli <[email protected]>
  • Loading branch information
agners and pvizeli authored Feb 16, 2024
1 parent 52e0c7e commit a71111b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion supervisor/addons/addon.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import voluptuous as vol
from voluptuous.humanize import humanize_error

from supervisor.utils.dt import utc_from_timestamp

from ..bus import EventListener
from ..const import (
ATTR_ACCESS_TOKEN,
Expand Down Expand Up @@ -349,7 +351,7 @@ def latest_version(self) -> str:
@property
def latest_version_timestamp(self) -> datetime:
"""Return when latest version was first seen."""
return datetime.fromtimestamp(self.data_store[ATTR_VERSION_TIMESTAMP])
return utc_from_timestamp(self.data_store[ATTR_VERSION_TIMESTAMP])

@property
def protected(self) -> bool:
Expand Down
4 changes: 3 additions & 1 deletion supervisor/addons/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

from awesomeversion import AwesomeVersion, AwesomeVersionException

from supervisor.utils.dt import utc_from_timestamp

from ..const import (
ATTR_ADVANCED,
ATTR_APPARMOR,
Expand Down Expand Up @@ -227,7 +229,7 @@ def latest_version(self) -> AwesomeVersion:
@property
def latest_version_timestamp(self) -> datetime:
"""Return when latest version was first seen."""
return datetime.fromtimestamp(self.data[ATTR_VERSION_TIMESTAMP])
return utc_from_timestamp(self.data[ATTR_VERSION_TIMESTAMP])

@property
def version(self) -> AwesomeVersion:
Expand Down

0 comments on commit a71111b

Please sign in to comment.