diff --git a/.flake8 b/.flake8 new file mode 100644 index 0000000..321e96b --- /dev/null +++ b/.flake8 @@ -0,0 +1,5 @@ +[flake8] +max-line-length = 88 +extend-ignore = E203 +per-file-ignores = + */__init__.py: F401 \ No newline at end of file diff --git a/.github/workflows/checks.yaml b/.github/workflows/checks.yaml new file mode 100644 index 0000000..53d7b12 --- /dev/null +++ b/.github/workflows/checks.yaml @@ -0,0 +1,31 @@ +name: Python Lint and Type Check + +on: + pull_request: + push: + branches: + - master + +jobs: + build: + runs-on: ubuntu-latest + container: + image: python:3.11-buster + steps: + - uses: actions/checkout@v2 + - name: Set up Python 3.x + uses: actions/setup-python@v2 + with: + python-version: '3.x' + - name: Install dependencies + run: | + pip install -r requirements.txt + pip install -r requirements-dev.txt + - name: Set execute permission for build.sh and dist.sh + run: | + chmod +x ./scripts/lint.sh + chmod +x ./scripts/type_check.sh + - name: Run Linting + run: ./scripts/lint.sh + - name: Run Type Checks + run: ./scripts/type_check.sh diff --git a/.github/workflows/python_publish.yaml b/.github/workflows/publish.yaml similarity index 100% rename from .github/workflows/python_publish.yaml rename to .github/workflows/publish.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..8b9f8e9 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,18 @@ +repos: + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.0.1 + hooks: + - id: check-yaml + - id: end-of-file-fixer + - id: trailing-whitespace + + - repo: https://github.com/pycqa/flake8 + rev: 4.0.1 + hooks: + - id: flake8 + + - repo: https://github.com/pre-commit/mirrors-mypy + rev: v0.910-1 + hooks: + - id: mypy + additional_dependencies: [types-requests] diff --git a/requirements-dev.txt b/requirements-dev.txt new file mode 100644 index 0000000..e1059a0 --- /dev/null +++ b/requirements-dev.txt @@ -0,0 +1,4 @@ +flake8 +mypy +black +pre-commit \ No newline at end of file diff --git a/requirements.txt b/requirements.txt index 1c801e3..f79c569 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1,4 @@ aiohttp==3.8.2 -pytest-asyncio==0.21.1 \ No newline at end of file +pytest-asyncio==0.21.1 +pytz==2023.3 +types-pytz==2023.3.1.1 diff --git a/scripts/format.sh b/scripts/format.sh new file mode 100644 index 0000000..f87fde6 --- /dev/null +++ b/scripts/format.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +black ./tessie_api \ No newline at end of file diff --git a/scripts/lint.sh b/scripts/lint.sh new file mode 100644 index 0000000..b3336d4 --- /dev/null +++ b/scripts/lint.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +flake8 ./tessie_api \ No newline at end of file diff --git a/scripts/type_check.sh b/scripts/type_check.sh new file mode 100644 index 0000000..ea9bd53 --- /dev/null +++ b/scripts/type_check.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +mypy ./tessie_api \ No newline at end of file diff --git a/tessie_api/battery_health.py b/tessie_api/battery_health.py index 60710f0..de24871 100644 --- a/tessie_api/battery_health.py +++ b/tessie_api/battery_health.py @@ -9,8 +9,8 @@ async def get_battery_health( session: aiohttp.ClientSession, vin: str, api_key: str, - from_time: int = None, - to_time: int = None, + from_time: int, + to_time: int, distance_format: DistanceFormat = "km", ) -> Dict[str, Any]: params = { diff --git a/tessie_api/current_state.py b/tessie_api/current_state.py index 74a03a2..1cecfcb 100644 --- a/tessie_api/current_state.py +++ b/tessie_api/current_state.py @@ -23,7 +23,7 @@ async def get_state_of_all_vehicles( return await tessieRequest( session, "GET", - f"/vehicles", + "/vehicles", api_key, params={"only_active": str(only_active).lower()}, ) diff --git a/tessie_api/idles.py b/tessie_api/idles.py index ff35cfd..5585e40 100644 --- a/tessie_api/idles.py +++ b/tessie_api/idles.py @@ -17,7 +17,7 @@ async def get_idles( distance_format: DistanceFormat = "km", format: Format = "json", timezone: str = "UTC", - exclude_origin: str = False, + exclude_origin: bool = False, ) -> Dict[str, Any]: return await tessieRequest( session, diff --git a/tessie_api/literals.py b/tessie_api/literals.py index d387dac..48aab1b 100644 --- a/tessie_api/literals.py +++ b/tessie_api/literals.py @@ -1,25 +1,25 @@ -from typing import Literal -from enum import Enum - - -MapStyle = Literal["light", "dark"] -DistanceFormat = Literal["mi", "km"] -TemperatureFormat = Literal["c", "f"] -Format = Literal["json", "csv"] -Seat = Literal[ - "all", - "front_left", - "front_right", - "rear_left", - "rear_center", - "rear_right", - "third_row_left", - "third_row_right", -] - - -class ClimateKeeperMode(Enum): - DISABLE = 0 - KEEP_MODE = 1 - DOG_MODE = 2 - CAMP_MODE = 3 +from typing import Literal +from enum import Enum + + +MapStyle = Literal["light", "dark"] +DistanceFormat = Literal["mi", "km"] +TemperatureFormat = Literal["c", "f"] +Format = Literal["json", "csv"] +Seat = Literal[ + "all", + "front_left", + "front_right", + "rear_left", + "rear_center", + "rear_right", + "third_row_left", + "third_row_right", +] + + +class ClimateKeeperMode(Enum): + DISABLE = 0 + KEEP_MODE = 1 + DOG_MODE = 2 + CAMP_MODE = 3 diff --git a/tessie_api/tessie_wrapper.py b/tessie_api/tessie_wrapper.py index 29229e0..ee6c548 100644 --- a/tessie_api/tessie_wrapper.py +++ b/tessie_api/tessie_wrapper.py @@ -15,5 +15,5 @@ async def tessieRequest( "Content-Type": "application/json", } async with session.request(method, url, headers=headers, params=params) as response: - response.raise_for_status() # Will raise aiohttp.ClientResponseError on 4xx or 5xx + response.raise_for_status() return await response.json()