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

Remove dependency on pytz #619

Merged
merged 5 commits into from
Sep 18, 2023
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
26 changes: 2 additions & 24 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ backoff = ">=1.11.1"
beautifulsoup4 = ">=4.11.1"
certifi = ">=2023.07.22"
python = "^3.9.0"
pytz = ">=2019.3"
voluptuous = ">=0.11.7"
websockets = ">=8.1"

Expand Down Expand Up @@ -96,7 +95,6 @@ requests = ">=2.31.0"
ruff = ">=0.0.261,<0.0.291"
safety = "^2.3.1"
sphinx-rtd-theme = "^1.0.0"
types-pytz = ">=2022.1,<2024.0"
vulture = "^2.6"
yamllint = "^1.28.0"

Expand Down
8 changes: 2 additions & 6 deletions simplipy/util/dt.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,5 @@
"""Define datetime utilities."""
from datetime import datetime

import pytz

UTC = pytz.utc
from datetime import datetime, timezone


def utc_from_timestamp(timestamp: float) -> datetime:
Expand All @@ -15,4 +11,4 @@ def utc_from_timestamp(timestamp: float) -> datetime:
Returns:
A parsed ``datetime.datetime`` object.
"""
return UTC.localize(datetime.utcfromtimestamp(timestamp))
return datetime.fromtimestamp(timestamp, tz=timezone.utc)
9 changes: 5 additions & 4 deletions tests/system/test_v3.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
"""Define tests for v3 System objects."""
# pylint: disable=too-many-lines
import logging
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import Any, cast
from unittest.mock import Mock

import aiohttp
import pytest
import pytz
from aresponses import ResponsesMockServer

from simplipy import API
Expand Down Expand Up @@ -54,7 +53,9 @@ async def test_as_dict(
"category": "error",
"code": "2000",
"timestamp": 1581823228,
"received_dt": datetime(2020, 2, 16, 3, 20, 28, tzinfo=pytz.UTC),
"received_dt": datetime(
2020, 2, 16, 3, 20, 28, tzinfo=timezone.utc
),
"link": "http://link.to.info",
"link_label": "More Info",
}
Expand Down Expand Up @@ -1680,7 +1681,7 @@ async def test_system_notifications(
assert notification1.category == "error"
assert notification1.code == "2000"
assert notification1.received_dt == datetime(
2020, 2, 16, 3, 20, 28, tzinfo=pytz.UTC
2020, 2, 16, 3, 20, 28, tzinfo=timezone.utc
)
assert notification1.link == "http://link.to.info"
assert notification1.link_label == "More Info"
Expand Down
5 changes: 2 additions & 3 deletions tests/test_websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
import asyncio
import logging
from collections import deque
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from time import time
from typing import Any
from unittest.mock import AsyncMock, Mock

import pytest
import pytz
from aiohttp.client_exceptions import (
ClientError,
ServerDisconnectedError,
Expand Down Expand Up @@ -142,7 +141,7 @@ def test_create_event(ws_message_event: dict[str, Any]) -> None:
assert event.event_type == EVENT_DISARMED_BY_MASTER_PIN
assert event.info == "System Disarmed by Master PIN"
assert event.system_id == 12345
assert event.timestamp == datetime(2021, 9, 29, 23, 14, 46, tzinfo=pytz.UTC)
assert event.timestamp == datetime(2021, 9, 29, 23, 14, 46, tzinfo=timezone.utc)
assert event.changed_by == "Master PIN"
assert event.sensor_name == ""
assert event.sensor_serial == "abcdef12"
Expand Down