Skip to content

Commit

Permalink
feat: added Python 3.10 support and dev container for testing
Browse files Browse the repository at this point in the history
Signed-off-by: Sven Rueß <[email protected]>
  • Loading branch information
sven-ruess committed Dec 29, 2024
1 parent bb97aa5 commit 6c9acf8
Show file tree
Hide file tree
Showing 7 changed files with 156 additions and 14 deletions.
26 changes: 26 additions & 0 deletions .devcontainer/python_310/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.177.0/containers/python-3/.devcontainer/base.Dockerfile

# [Choice] Python version: 3, 3.9, 3.8, 3.7, 3.6
ARG VARIANT="3.10"
FROM mcr.microsoft.com/vscode/devcontainers/python:1-${VARIANT}

# [Option] Install Node.js
ARG INSTALL_NODE="true"
ARG NODE_VERSION="lts/*"
RUN if [ "${INSTALL_NODE}" = "true" ]; then su vscode -c "umask 0002 && . /usr/local/share/nvm/nvm.sh && nvm install ${NODE_VERSION} 2>&1"; fi

# [Optional] If your pip requirements rarely change, uncomment this section to add them to the image.
RUN pip3 --disable-pip-version-check --no-cache-dir install pre-commit
RUN pip3 --disable-pip-version-check --no-cache-dir install poetry
RUN pip3 --disable-pip-version-check --no-cache-dir install aiohttp
RUN pip3 --disable-pip-version-check --no-cache-dir install bs4

# [Optional] Uncomment this section to install additional OS packages.
# RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
# && apt-get -y install --no-install-recommends <your-package-list-here>

# [Optional] Uncomment this line to install global node packages.
# RUN su vscode -c "source /usr/local/share/nvm/nvm.sh && npm install -g <your-package-here>" 2>&1

# Set the default shell to bash instead of sh
ENV SHELL /bin/bash
30 changes: 30 additions & 0 deletions .devcontainer/python_310/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "Python 3.10",
"build": {
"dockerfile": "Dockerfile",
"context": "..",
"args": {
"VARIANT": "3.10",
"INSTALL_NODE": "true",
"NODE_VERSION": "lts/*"
}
},
"customizations": {
"vscode": {
"settings": {
"terminal.integrated.shell.linux": "/bin/bash",
"python.pythonPath": "/usr/local/bin/python",
"python.languageServer": "Pylance",
"[python]": {
"editor.defaultFormatter": "charliermarsh.ruff"
}
},
"extensions": [
"ms-python.python",
"ms-python.vscode-pylance",
"charliermarsh.ruff"
]
}
},
"remoteUser": "vscode"
}
1 change: 1 addition & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ jobs:
fail-fast: false
matrix:
python-version:
- "3.10"
- "3.11"
- "3.12"
- "3.13"
Expand Down
90 changes: 88 additions & 2 deletions poetry.lock

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

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ packages = [
"Changelog" = "https://github.com/chemelli74/aiovodafone/blob/main/CHANGELOG.md"

[tool.poetry.dependencies]
python = "^3.11"
python = "^3.10"
aiohttp = "*"
beautifulsoup4 = "*"

Expand Down
2 changes: 1 addition & 1 deletion ruff.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
target-version = "py311"
target-version = "py310"

lint.logger-objects = ["aiovodafone.const._LOGGER"]

Expand Down
19 changes: 9 additions & 10 deletions src/aiovodafone/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import urllib.parse
from abc import ABC, abstractmethod
from dataclasses import dataclass
from datetime import UTC, datetime, timedelta
from datetime import datetime, timedelta, timezone
from http import HTTPStatus
from http.cookies import SimpleCookie
from typing import Any, cast
Expand Down Expand Up @@ -82,8 +82,8 @@ async def get_device_type(
if "data" in response_json and "ModelName" in response_json["data"]:
return DeviceType.TECHNICOLOR

for protocol in ["https", "http"]:
try:
try:
for protocol in ["https", "http"]:
async with session.get(
f"{protocol}://{host}/login.html",
headers=HEADERS,
Expand All @@ -97,9 +97,8 @@ async def get_device_type(
and "var csrf_token = " in await response.text()
):
return DeviceType.SERCOMM
except aiohttp.client_exceptions.ClientConnectorSSLError:
_LOGGER.debug("Unable to login using protocol %s", protocol)
continue
except aiohttp.client_exceptions.ClientConnectorSSLError:
_LOGGER.debug("Unable to login using protocol %s", protocol)

return None

Expand Down Expand Up @@ -143,7 +142,7 @@ async def _post_page_result(
) -> aiohttp.ClientResponse:
"""Get data from a web page via POST."""
_LOGGER.debug("POST page %s from host %s", page, self.host)
timestamp = int(datetime.now(tz=UTC).timestamp())
timestamp = int(datetime.now(tz=timezone.utc).timestamp())
url = f"{self.base_url}{page}?_={timestamp}&csrf_token={self.csrf_token}"
return await self.session.post(
url,
Expand All @@ -157,7 +156,7 @@ async def _post_page_result(
async def _get_page_result(self, page: str) -> aiohttp.ClientResponse:
"""Get data from a web page via GET."""
_LOGGER.debug("GET page %s [%s]", page, self.host)
timestamp = int(datetime.now(tz=UTC).timestamp())
timestamp = int(datetime.now(tz=timezone.utc).timestamp())
url = f"{self.base_url}{page}?_={timestamp}&csrf_token={self.csrf_token}"

return await self.session.get(
Expand Down Expand Up @@ -240,7 +239,7 @@ async def _encrypt_string(

def convert_uptime(self, uptime: str) -> datetime:
"""Convert uptime to datetime."""
return datetime.now(tz=UTC) - timedelta(
return datetime.now(tz=timezone.utc) - timedelta(
seconds=int(uptime),
)

Expand Down Expand Up @@ -578,7 +577,7 @@ def convert_uptime(self, uptime: str) -> datetime:
h = int(uptime.split(":")[1])
m = int(uptime.split(":")[2])

return datetime.now(tz=UTC) - timedelta(
return datetime.now(tz=timezone.utc) - timedelta(
days=d,
hours=h,
minutes=m,
Expand Down

0 comments on commit 6c9acf8

Please sign in to comment.