Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use timezone aware objects for RepositoryData.last_fetched #3570

Merged
merged 4 commits into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ jobs:
scripts/install/core
scripts/install/frontend

- name: ⏲️ Set time zone
uses: szenius/[email protected]
with:
timezoneLinux: 'Asia/Singapore'

- name: 🏃 Run tests
env:
PYTEST: true
Expand Down Expand Up @@ -69,6 +74,11 @@ jobs:
scripts/install/core_dev
scripts/install/frontend

- name: ⏲️ Set time zone
uses: szenius/[email protected]
with:
timezoneLinux: 'Asia/Singapore'

- name: 🏃 Run tests
env:
PYTEST: true
Expand Down
8 changes: 4 additions & 4 deletions custom_components/hacs/repositories/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

from asyncio import sleep
from datetime import datetime
from datetime import datetime, UTC
import os
import pathlib
import shutil
Expand Down Expand Up @@ -196,7 +196,7 @@ def update_data(self, data: dict, action: bool = False) -> None:
continue

if key == "last_fetched" and isinstance(value, float):
setattr(self, key, datetime.fromtimestamp(value))
setattr(self, key, datetime.fromtimestamp(value, UTC))
elif key == "id":
setattr(self, key, str(value))
elif key == "country":
Expand Down Expand Up @@ -501,7 +501,7 @@ async def common_registration(self) -> None:

if self.repository_object:
self.data.last_updated = self.repository_object.attributes.get("pushed_at", 0)
self.data.last_fetched = datetime.utcnow()
self.data.last_fetched = datetime.now(UTC)

@concurrent(concurrenttasks=10, backoff_time=5)
async def common_update(self, ignore_issues=False, force=False, skip_releases=False) -> bool:
Expand Down Expand Up @@ -549,7 +549,7 @@ async def common_update(self, ignore_issues=False, force=False, skip_releases=Fa
self.additional_info = await self.async_get_info_file_contents()

# Set last fetch attribute
self.data.last_fetched = datetime.utcnow()
self.data.last_fetched = datetime.now(UTC)

return True

Expand Down
4 changes: 2 additions & 2 deletions custom_components/hacs/utils/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from __future__ import annotations

import asyncio
from datetime import datetime
from datetime import datetime, UTC
from typing import Any

from homeassistant.core import callback
Expand Down Expand Up @@ -308,7 +308,7 @@ def async_restore_repository(self, entry: str, repository_data: dict[str, Any]):
repository.data.manifest_name = repository_data.get("manifest_name")

if last_fetched := repository_data.get("last_fetched"):
repository.data.last_fetched = datetime.fromtimestamp(last_fetched)
repository.data.last_fetched = datetime.fromtimestamp(last_fetched, UTC)

repository.repository_manifest = HacsManifest.from_dict(
repository_data.get("manifest") or repository_data.get("repository_manifest") or {}
Expand Down
Loading