Skip to content

Commit

Permalink
more typing
Browse files Browse the repository at this point in the history
  • Loading branch information
jbouwh committed Jan 4, 2025
1 parent e542628 commit b8b5785
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 14 deletions.
7 changes: 5 additions & 2 deletions tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"""Python client library for the InterGas InComfort system (via Lan2RF gateway)."""

from __future__ import annotations
from typing import Any

import aiohttp
from aioresponses import aioresponses
Expand All @@ -20,7 +21,9 @@
)


async def gwy_with_heaterlist(hostname, heaterlist=GATEWAYS_WITH_HEATER[0]) -> Gateway:
async def gwy_with_heaterlist(
hostname: str | None, heaterlist: dict[str, Any]
) -> Gateway:
"""Request the heaterlist from a mocked gateway."""

with aioresponses() as mocked:
Expand All @@ -37,7 +40,7 @@ async def gwy_with_heaterlist(hostname, heaterlist=GATEWAYS_WITH_HEATER[0]) -> G
return gwy


async def heater_with_status(data_heater, heaterlist=GATEWAYS_WITH_HEATER[0]) -> Heater:
async def heater_with_status(data_heater: Any, heaterlist: Any) -> Heater:
"""Update the heater status from a mocked gateway."""

with aioresponses() as mocked:
Expand Down
25 changes: 18 additions & 7 deletions tests/test_gateway.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
from __future__ import annotations

import pytest
from common import HOSTNAME, SERIAL_NO_0, SERIAL_NO_1, gwy_with_heaterlist
from common import (
GATEWAYS_WITH_HEATER,
HOSTNAME,
SERIAL_NO_0,
SERIAL_NO_1,
gwy_with_heaterlist,
)

from incomfortclient import (
HEATERLIST,
Expand All @@ -28,30 +34,35 @@
{HEATERLIST: [None, NULL_SERIAL_NO, None, None, SERIAL_NO_0, None, None, None]},
)

# pylint: disable=protected-access


@pytest.mark.asyncio
async def test_gateway_invalid():
async def test_gateway_invalid() -> None:
"""Test an invalid gateway."""
try:
await gwy_with_heaterlist(None)
await gwy_with_heaterlist(None, GATEWAYS_WITH_HEATER[0])
except InvalidGateway:
return
raise AssertionError


@pytest.mark.asyncio
@pytest.mark.parametrize("index", range(len(GATEWAYS_SANS_HEATERS)))
async def test_heaterlist_empty(index, gateways=GATEWAYS_SANS_HEATERS):
async def test_heaterlist_empty(index: int) -> None:
"""Test the gateway with an empty heater list."""
try:
await gwy_with_heaterlist(HOSTNAME, heaterlist=gateways[index])
await gwy_with_heaterlist(HOSTNAME, heaterlist=GATEWAYS_SANS_HEATERS[index])
except InvalidHeaterList:
return
raise AssertionError


@pytest.mark.asyncio
@pytest.mark.parametrize("index", range(len(GATEWAYS_WITH_HEATERS)))
async def test_heaterlist_valid(index, gateways=GATEWAYS_WITH_HEATERS):
gwy = await gwy_with_heaterlist(HOSTNAME, heaterlist=gateways[index])
async def test_heaterlist_valid(index: int) -> None:
"""Test the gateway with a valid heater list."""
gwy = await gwy_with_heaterlist(HOSTNAME, heaterlist=GATEWAYS_WITH_HEATERS[index])

assert gwy._heaters[0].serial_no == SERIAL_NO_0
assert len(gwy._heaters) < 2 or gwy._heaters[1].serial_no == SERIAL_NO_1
14 changes: 9 additions & 5 deletions tests/test_heater.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
from __future__ import annotations

import pytest
from common import SERIAL_NO_0, heater_with_status
from common import GATEWAYS_WITH_HEATER, SERIAL_NO_0, heater_with_status

# Test data...
HEATER_SANS_ROOMS = (
Expand Down Expand Up @@ -112,14 +112,18 @@


@pytest.mark.asyncio
async def test_heater_sans_rooms():
heater = await heater_with_status(HEATER_SANS_ROOMS[0])
async def test_heater_sans_rooms() -> None:
"""Test heater without rooms."""
heater = await heater_with_status(HEATER_SANS_ROOMS[0], GATEWAYS_WITH_HEATER[0])
assert heater.status == HEATER_SANS_ROOMS[1]
assert len(heater.rooms) == 0


@pytest.mark.asyncio
async def test_heater_with_rooms():
heater = await heater_with_status(HEATER_WITH_ROOMS[0])
async def test_heater_with_rooms() -> None:
"""Test heater with rooms."""
heater = await heater_with_status(
HEATER_WITH_ROOMS[0], heaterlist=GATEWAYS_WITH_HEATER[0]
)
assert heater.status == HEATER_WITH_ROOMS[1]
assert len(heater.rooms) == 1 and heater.rooms[0].status == HEATER_WITH_ROOMS[2]

0 comments on commit b8b5785

Please sign in to comment.