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 pytz from dependencies #43

Merged
merged 1 commit into from
May 14, 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
13 changes: 1 addition & 12 deletions poetry.lock

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

23 changes: 12 additions & 11 deletions pyefergy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
from __future__ import annotations

from asyncio.exceptions import TimeoutError as timeouterr
from datetime import datetime
from datetime import datetime, timedelta
from zoneinfo import ZoneInfo, ZoneInfoNotFoundError
import logging
from typing import Any
from typing import Any, cast

from aiohttp import ClientSession, ClientTimeout
from aiohttp.client_exceptions import ClientConnectorError, ServerDisconnectedError
import iso4217
from pytz import all_timezones, timezone as tz

from . import exceptions

Expand Down Expand Up @@ -109,14 +109,15 @@ def update_params(
break
if CURRENCY not in self.info:
raise exceptions.InvalidCurrency("Provided currency is invalid")
if UTC_OFFSET in kwargs:
if (utc_offset := kwargs[UTC_OFFSET]) in all_timezones:
utc_offset = int(datetime.now(tz(utc_offset)).strftime("%z"))
self._utc_offset = -(int(utc_offset / 100 * 60))
elif utc_offset.isnumeric():
self._utc_offset = utc_offset
else:
raise exceptions.InvalidOffset("Provided offset is invalid")
if (offset := kwargs.get(UTC_OFFSET, "")) and offset.isnumeric():
self._utc_offset = offset
return
try:
z_info = ZoneInfo(offset)
except ZoneInfoNotFoundError as ex:
raise exceptions.InvalidOffset("Provided offset is invalid") from ex
utc_offset = cast(timedelta, z_info.utcoffset(datetime.now())).total_seconds()
self._utc_offset = -int(utc_offset // 60)

async def _async_req(
self, command: str, params: dict[str, str | int | float] | None = None
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ include = ["pyefergy/py.typed"]
python = ">=3.8,<4"
aiohttp = ">=3.6.1"
iso4217 = ">=1.2.20150619"
pytz = ">=2024.1"
types-pytz = ">=2021.3.1"
codecov = "^2.1.13"

Expand Down
9 changes: 5 additions & 4 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@

# pylint:disable=redefined-outer-name
import asyncio
from asyncio import AbstractEventLoop
import json
import pathlib

import pytest
from aresponses.main import ResponsesMockServer as Server
import pytest

from pyefergy import Efergy
import json
import pathlib
from asyncio import AbstractEventLoop

API_KEY = "ur1234567-0abc12de3f456gh7ij89k012"
HOST = "engage.efergy.com"
Expand Down
7 changes: 5 additions & 2 deletions tests/test_init.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
"""Tests for PyEfergy object models."""

# pylint:disable=protected-access, too-many-lines, line-too-long
from datetime import datetime

from aiohttp.client import ClientSession
from freezegun.api import FrozenDateTimeFactory
import pytest

import pyefergy
Expand All @@ -18,9 +21,9 @@ async def test_loop() -> None:


@pytest.mark.asyncio
@pytest.mark.freeze_time("2022-01-03 00:00:00+00:00")
async def test_init(connection: None) -> None:
async def test_init(connection: None, freezer: FrozenDateTimeFactory) -> None:
"""Test init."""
freezer.move_to(datetime(2022, 1, 3))
client = Efergy(API_KEY, utc_offset="America/New_York", currency="USD")

assert client._utc_offset == 300
Expand Down