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

Do not raise errors if the status is unknown #4

Merged
merged 1 commit into from
Feb 9, 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
5 changes: 1 addition & 4 deletions src/technove/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
from enum import Enum
from typing import Any

from technove.exceptions import TechnoVEError


class Status(Enum):
"""Describes the status of a TechnoVE station."""
Expand All @@ -29,8 +27,7 @@ def build(cls: type[Status], status: int) -> Status:
if status in statuses:
return statuses[status]

error_message = f"The status code {status} is not a valid status."
raise TechnoVEError(error_message)
return Status.UNKNOWN


class Station:
Expand Down
7 changes: 2 additions & 5 deletions tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
"""Tests for `technove.TechnoVE`."""


import pytest

from technove import Status, TechnoVEError
from technove import Status


def test_status_build() -> None:
Expand All @@ -13,5 +11,4 @@ def test_status_build() -> None:

def test_status_build_unknown() -> None:
"""Test status build with an unknown status code."""
with pytest.raises(TechnoVEError):
Status.build(42)
assert Status.build(42) == Status.UNKNOWN
22 changes: 21 additions & 1 deletion tests/test_technove.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import pytest
from aresponses import Response, ResponsesMockServer

from technove import Station, TechnoVE
from technove import Station, Status, TechnoVE
from technove.exceptions import TechnoVEConnectionError, TechnoVEError


Expand Down Expand Up @@ -215,6 +215,26 @@ async def test_update_partial_responses(aresponses: ResponsesMockServer) -> None
assert station.info.name == "testing"


@pytest.mark.asyncio
async def test_update_unknown_status(aresponses: ResponsesMockServer) -> None:
"""Test handling of unknown status received from the API."""
aresponses.add(
"example.com",
"/station/get/info",
"GET",
aresponses.Response(
status=200,
headers={"Content-Type": "application/json"},
text='{"name":"testing", "status":"1234"}',
),
)
async with aiohttp.ClientSession() as session:
technove = TechnoVE("example.com", session=session)
station = await technove.update()
assert station.info.name == "testing"
assert station.info.status == Status.UNKNOWN


@pytest.mark.asyncio
async def test_set_auto_charge(aresponses: ResponsesMockServer) -> None:
"""Test that enabling auto_charge calls the right API."""
Expand Down
Loading