Skip to content

Commit

Permalink
Merge pull request #231 from snoack/python-3.9
Browse files Browse the repository at this point in the history
Backport to Python 3.9
  • Loading branch information
robbinjanssen committed Mar 1, 2024
2 parents 1b824ec + 61491c2 commit c9fc48c
Show file tree
Hide file tree
Showing 9 changed files with 69 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/tests.yaml
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
python: ["3.11", "3.12"]
python: ["3.9", "3.10", "3.11", "3.12"]

steps:
- name: Checkout repository
Expand Down
6 changes: 3 additions & 3 deletions ojmicroline_thermostat/models/schedule.py
Expand Up @@ -3,7 +3,7 @@
from __future__ import annotations

from dataclasses import dataclass
from datetime import UTC, datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import Any


Expand Down Expand Up @@ -47,7 +47,7 @@ def from_json(cls, data: dict[str, Any]) -> Schedule:
"""
result = {}
now = datetime.now(tz=UTC)
now = datetime.now(tz=timezone.utc)
current_day = now.weekday()
for item in data["Days"]:
# Define the week days.
Expand Down Expand Up @@ -98,7 +98,7 @@ def get_active_temperature(self) -> int:
The currently active temperature based on the schedule.
"""
now = datetime.now(tz=UTC)
now = datetime.now(tz=timezone.utc)
current_day = now.weekday()

temperature = 0
Expand Down
7 changes: 4 additions & 3 deletions ojmicroline_thermostat/ojmicroline.py
@@ -1,14 +1,15 @@
"""Asynchronous Python client communicating with the OJ Microline API."""
from __future__ import annotations

import asyncio
import json
import socket
from dataclasses import dataclass
from typing import TYPE_CHECKING, Any, Self
from typing import TYPE_CHECKING, Any

import async_timeout
from aiohttp import ClientError, ClientSession, hdrs
from typing_extensions import Protocol
from typing_extensions import Protocol, Self
from yarl import URL

from .const import COMFORT_DURATION
Expand Down Expand Up @@ -187,7 +188,7 @@ async def _request(
ssl=True,
)
response.raise_for_status()
except TimeoutError as exception:
except asyncio.TimeoutError as exception:
msg = "Timeout occurred while connecting to the OJ Microline API."
raise OJMicrolineTimeoutError(msg) from exception
except (ClientError, socket.gaierror) as exception:
Expand Down
6 changes: 3 additions & 3 deletions ojmicroline_thermostat/wd5.py
Expand Up @@ -4,7 +4,7 @@
from __future__ import annotations

from dataclasses import dataclass
from datetime import UTC, datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import Any

from .const import (
Expand Down Expand Up @@ -96,7 +96,7 @@ def update_regulation_mode_body( # noqa: D102
) -> dict[str, Any]:
if regulation_mode == REGULATION_COMFORT:
comfort_end_time = (
datetime.now(tz=UTC) + timedelta(minutes=duration)
datetime.now(tz=timezone.utc) + timedelta(minutes=duration)
).astimezone()
comfort_temperature = temperature or thermostat.comfort_temperature
else:
Expand All @@ -105,7 +105,7 @@ def update_regulation_mode_body( # noqa: D102

if regulation_mode == REGULATION_BOOST:
boost_end_time: datetime | None = (
datetime.now(tz=UTC) + timedelta(hours=1)
datetime.now(tz=timezone.utc) + timedelta(hours=1)
).astimezone()
else:
boost_end_time = thermostat.boost_end_time
Expand Down
4 changes: 2 additions & 2 deletions ojmicroline_thermostat/wg4.py
Expand Up @@ -4,7 +4,7 @@
from __future__ import annotations

from dataclasses import dataclass
from datetime import UTC, datetime, timedelta
from datetime import datetime, timedelta, timezone
from typing import Any

from .const import REGULATION_COMFORT, REGULATION_MANUAL
Expand Down Expand Up @@ -75,7 +75,7 @@ def update_regulation_mode_body( # noqa: D102
"ManualTemperature": temperature,
}
elif regulation_mode == REGULATION_COMFORT:
end = datetime.now(tz=UTC) + timedelta(minutes=duration)
end = datetime.now(tz=timezone.utc) + timedelta(minutes=duration)
extras = {
"ComfortTemperature": temperature,
"ComfortEndTime": end.strftime("%d/%m/%Y %H:%M:00 +00:00"),
Expand Down
48 changes: 44 additions & 4 deletions poetry.lock

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

6 changes: 4 additions & 2 deletions pyproject.toml
Expand Up @@ -15,6 +15,8 @@ classifiers = [
"Intended Audience :: Developers",
"License :: OSI Approved :: MIT License",
"Natural Language :: English",
"Programming Language :: Python :: 3.9",
"Programming Language :: Python :: 3.10",
"Programming Language :: Python :: 3.11",
"Programming Language :: Python :: 3.12",
"Programming Language :: Python :: 3",
Expand All @@ -26,7 +28,7 @@ packages = [

[tool.poetry.dependencies]
aiohttp = ">=3.0.0"
python = "^3.11"
python = "^3.9"
yarl = ">=1.6.0"

[tool.poetry.urls]
Expand Down Expand Up @@ -122,7 +124,7 @@ addopts = "--cov"
asyncio_mode = "auto"

[tool.ruff]
target-version = "py311"
target-version = "py39"
lint.select = ["ALL"]
lint.ignore = [
"ANN101", # Self... explanatory
Expand Down
2 changes: 2 additions & 0 deletions tests/test_wd5_update.py
@@ -1,5 +1,7 @@
"""Test the update method for a WD5-series thermostat."""

from __future__ import annotations

import json
from datetime import datetime, timedelta

Expand Down
12 changes: 6 additions & 6 deletions tests/test_wg4_update.py
@@ -1,7 +1,7 @@
"""Test the update method for a WD5-series thermostat."""

import json
from datetime import UTC, datetime, timedelta
from datetime import datetime, timedelta, timezone

import pytest
from freezegun import freeze_time
Expand All @@ -28,7 +28,7 @@ async def test_update_regulation_mode_comfort() -> None:
thermostat = Thermostat.from_wg4_json(json.loads(data))

# Check the current times.
assert thermostat.comfort_end_time == datetime(2024, 1, 24, 5, tzinfo=UTC)
assert thermostat.comfort_end_time == datetime(2024, 1, 24, 5, tzinfo=timezone.utc)

# Check the current temperature for comfort.
assert thermostat.comfort_temperature == 2000
Expand All @@ -47,7 +47,7 @@ async def test_update_regulation_mode_comfort() -> None:
# Assert comfort end time is the current date + COMFORT_DURATION minutes.
assert datetime.strptime( # noqa: DTZ007
result["ComfortEndTime"], WG4_DATETIME_FORMAT
) == datetime.now(tz=UTC) + timedelta(minutes=COMFORT_DURATION)
) == datetime.now(tz=timezone.utc) + timedelta(minutes=COMFORT_DURATION)


@pytest.mark.asyncio
Expand All @@ -61,7 +61,7 @@ async def test_update_regulation_mode_comfort_with_temp_and_duration() -> None:
thermostat = Thermostat.from_wg4_json(json.loads(data))

# Check the current times.
assert thermostat.comfort_end_time == datetime(2024, 1, 24, 5, tzinfo=UTC)
assert thermostat.comfort_end_time == datetime(2024, 1, 24, 5, tzinfo=timezone.utc)

# Check the current temperature for comfort.
assert thermostat.comfort_temperature == 2000
Expand All @@ -80,7 +80,7 @@ async def test_update_regulation_mode_comfort_with_temp_and_duration() -> None:
# Assert comfort end time is the current date + 360 minutes.
assert datetime.strptime( # noqa: DTZ007
result["ComfortEndTime"], WG4_DATETIME_FORMAT
) == datetime.now(tz=UTC) + timedelta(minutes=360)
) == datetime.now(tz=timezone.utc) + timedelta(minutes=360)

# Assert the temperature is the same.
assert result["ComfortTemperature"] == 2350
Expand All @@ -97,7 +97,7 @@ async def test_update_regulation_mode_with_temp() -> None:
thermostat = Thermostat.from_wg4_json(json.loads(data))

# Check the current times.
assert thermostat.comfort_end_time == datetime(2024, 1, 24, 5, tzinfo=UTC)
assert thermostat.comfort_end_time == datetime(2024, 1, 24, 5, tzinfo=timezone.utc)

# Check the current temperature for manual.
assert thermostat.manual_temperature == 2600
Expand Down

0 comments on commit c9fc48c

Please sign in to comment.