Skip to content

Commit

Permalink
fix: add timezone to convert_uptime functions
Browse files Browse the repository at this point in the history
  • Loading branch information
chemelli74 committed Oct 17, 2023
1 parent 99743c5 commit d37cdbd
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions src/aiovodafone/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import urllib.parse
from abc import ABC, abstractmethod
from dataclasses import dataclass
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from http.cookies import SimpleCookie
from typing import Any

Expand Down Expand Up @@ -99,7 +99,7 @@ async def _get_page_result(self, page: str) -> aiohttp.ClientResponse:
)

@abstractmethod
async def convert_uptime(self, uptime: str) -> datetime:
def convert_uptime(self, uptime: str) -> datetime:
pass

async def close(self) -> None:
Expand Down Expand Up @@ -238,8 +238,10 @@ async def get_sensor_data(self) -> dict[Any, Any]:
data["sys_uptime"] = status_json["data"]["uptime"]
return data

async def convert_uptime(self, uptime: str) -> datetime:
return datetime.utcnow() - timedelta(seconds=int(uptime))
def convert_uptime(self, uptime: str) -> datetime:
return datetime.utcnow().replace(tzinfo=timezone.utc) - timedelta(
seconds=int(uptime)
)

async def logout(self) -> None:
# Logout
Expand Down Expand Up @@ -446,13 +448,15 @@ async def get_devices_data(self) -> dict[str, VodafoneStationDevice]:

return self._devices

async def convert_uptime(self, uptime: str) -> datetime:
def convert_uptime(self, uptime: str) -> datetime:
"""Convert router uptime to last boot datetime."""
d = int(uptime.split(":")[0])
h = int(uptime.split(":")[1])
m = int(uptime.split(":")[2])

return datetime.utcnow() - timedelta(days=d, hours=h, minutes=m)
return datetime.utcnow().replace(tzinfo=timezone.utc) - timedelta(
days=d, hours=h, minutes=m
)

async def login(self) -> bool:
"""Router login."""
Expand Down

0 comments on commit d37cdbd

Please sign in to comment.