From c4141a871edbd9b43249d0e2917df4bce8b36c6a Mon Sep 17 00:00:00 2001 From: David Bonnes Date: Sat, 2 Nov 2024 15:44:24 +0000 Subject: [PATCH] tweaks & fixes --- .pre-commit-config.yaml | 3 +- src/evohomeasync2/__init__.py | 4 +-- src/evohomeasync2/location.py | 2 +- tests/tests_rf/conftest.py | 7 ++-- ...test_token_mgr_v2.py => test_token_mgr.py} | 0 tests/tests_rf/test_v1_apis.py | 20 +++--------- tests/tests_rf/test_v1_xxxx.py | 32 ++++--------------- tests/tests_rf/test_v2_task.py | 3 +- 8 files changed, 21 insertions(+), 50 deletions(-) rename tests/tests_rf/{test_token_mgr_v2.py => test_token_mgr.py} (100%) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 72203ad2..81180ab4 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -67,9 +67,8 @@ repos: - id: secrets name: check secrets - entry: '#.*(secret|password|pwd)' + entry: '#.*(SECRET|PASSWORD|PWD)' language: pygrep - args: [-i] exclude: .pre-commit-config.yaml # avoid false +ve - id: style_1 diff --git a/src/evohomeasync2/__init__.py b/src/evohomeasync2/__init__.py index cb25db55..7d940c43 100644 --- a/src/evohomeasync2/__init__.py +++ b/src/evohomeasync2/__init__.py @@ -76,7 +76,7 @@ async def save_access_token(self) -> None: class EvohomeClientNew: # requires a Token Manager """Provide a client to access the Honeywell TCC API.""" - _installation_config: _EvoListT | None = None # all locations + _installation_config: _EvoListT | None = None # all locations _user_information: _EvoDictT | None = None def __init__( @@ -115,7 +115,7 @@ async def update( information & installation configuration. If `disable_status_update` is True, does not update the status of each location - (but will still retreive configuration data, if required). + (but will still retrieve configuration data, if required). """ if reset_config: diff --git a/src/evohomeasync2/location.py b/src/evohomeasync2/location.py index 8836a510..e9a39a32 100644 --- a/src/evohomeasync2/location.py +++ b/src/evohomeasync2/location.py @@ -91,7 +91,7 @@ def use_daylight_save_switching(self) -> bool: async def update(self) -> _EvoDictT: """Get the latest state of the location and update its status. - Will also update teh status of its gateways, their TCSs, and their DHW/zones. + Will also update the status of its gateways, their TCSs, and their DHW/zones. Returns the raw JSON of the latest state. """ diff --git a/tests/tests_rf/conftest.py b/tests/tests_rf/conftest.py index 74b8aefc..81a014a5 100644 --- a/tests/tests_rf/conftest.py +++ b/tests/tests_rf/conftest.py @@ -138,8 +138,11 @@ async def evohome_v1( try: yield evo - finally: - pass + + except evo1.AuthenticationFailed as err: + if not _DBG_USE_REAL_AIOHTTP: + raise + pytest.skip(f"Unable to authenticate: {err}") @pytest.fixture diff --git a/tests/tests_rf/test_token_mgr_v2.py b/tests/tests_rf/test_token_mgr.py similarity index 100% rename from tests/tests_rf/test_token_mgr_v2.py rename to tests/tests_rf/test_token_mgr.py diff --git a/tests/tests_rf/test_v1_apis.py b/tests/tests_rf/test_v1_apis.py index 0288b47c..36a0ef69 100644 --- a/tests/tests_rf/test_v1_apis.py +++ b/tests/tests_rf/test_v1_apis.py @@ -3,19 +3,14 @@ from __future__ import annotations -from typing import TYPE_CHECKING - import pytest -import evohomeasync as evohome +import evohomeasync as evo1 from .conftest import _DBG_USE_REAL_AIOHTTP -if TYPE_CHECKING: - import aiohttp - -async def _test_client_apis(evo: evohome.EvohomeClient) -> None: +async def _test_client_apis(evo: evo1.EvohomeClient) -> None: """Instantiate a client, and logon to the vendor API.""" user_data = await evo._populate_user_data() @@ -34,17 +29,10 @@ async def _test_client_apis(evo: evohome.EvohomeClient) -> None: # _LOGGER.warning("get_temperatures() OK") -async def test_client_apis( - credentials: tuple[str, str], client_session: aiohttp.ClientSession -) -> None: +async def test_client_apis(evohome_v1: evo1.EvohomeClient) -> None: """Test _populate_user_data() & _populate_full_data()""" if not _DBG_USE_REAL_AIOHTTP: pytest.skip("Mocked server not implemented for this API") - try: - await _test_client_apis( - await instantiate_client_v1(*credentials, session=client_session) - ) - except evohome.AuthenticationFailed: - pytest.skip("Unable to authenticate") + await _test_client_apis(evohome_v1) diff --git a/tests/tests_rf/test_v1_xxxx.py b/tests/tests_rf/test_v1_xxxx.py index f47f365e..5f6b3be1 100644 --- a/tests/tests_rf/test_v1_xxxx.py +++ b/tests/tests_rf/test_v1_xxxx.py @@ -4,20 +4,16 @@ from __future__ import annotations from http import HTTPMethod, HTTPStatus -from typing import TYPE_CHECKING import pytest -import evohomeasync as evohome +import evohomeasync as evo1 from .conftest import _DBG_USE_REAL_AIOHTTP from .helpers import should_fail_v1, should_work_v1 -if TYPE_CHECKING: - import aiohttp - -async def _test_url_locations(evo: evohome.EvohomeClient) -> None: +async def _test_url_locations(evo: evo1.EvohomeClient) -> None: # evo.broker._headers["sessionId"] = evo.user_info["sessionId"] # what is this? user_id: int = evo.user_info["userID"] # type: ignore[assignment] @@ -48,7 +44,7 @@ async def _test_url_locations(evo: evohome.EvohomeClient) -> None: ) -async def _test_client_apis(evo: evohome.EvohomeClient) -> None: +async def _test_client_apis(evo: evo1.EvohomeClient) -> None: """Instantiate a client, and logon to the vendor API.""" user_data = await evo._populate_user_data() @@ -62,36 +58,22 @@ async def _test_client_apis(evo: evohome.EvohomeClient) -> None: assert temps -async def test_locations( - credentials: tuple[str, str], client_session: aiohttp.ClientSession -) -> None: +async def test_locations(evohome_v1: evo1.EvohomeClient) -> None: """Test /locations""" if not _DBG_USE_REAL_AIOHTTP: pytest.skip("Mocked server not implemented for this API") - try: - await _test_url_locations( - await instantiate_client_v1(*credentials, session=client_session) - ) - except evohome.AuthenticationFailed as err: - pytest.skip(f"Unable to authenticate: {err}") + await _test_url_locations(evohome_v1) -async def test_client_apis( - credentials: tuple[str, str], client_session: aiohttp.ClientSession -) -> None: +async def test_client_apis(evohome_v1: evo1.EvohomeClient) -> None: """Test _populate_user_data() & _populate_full_data()""" if not _DBG_USE_REAL_AIOHTTP: pytest.skip("Mocked server not implemented for this API") - try: - await _test_client_apis( - await instantiate_client_v1(*credentials, session=client_session) - ) - except evohome.AuthenticationFailed: - pytest.skip("Unable to authenticate") + await _test_client_apis(evohome_v1) USER_DATA = { diff --git a/tests/tests_rf/test_v2_task.py b/tests/tests_rf/test_v2_task.py index ff1aa1e3..488cfcaf 100644 --- a/tests/tests_rf/test_v2_task.py +++ b/tests/tests_rf/test_v2_task.py @@ -36,8 +36,7 @@ async def _test_task_id(evo: evo2.EvohomeClient) -> None: gwy: Gateway tcs: ControlSystem - _ = await evo.user_account() - _ = await evo._installation(disable_status_update=True) + _ = await evo.update(disable_status_update=True) for loc in evo.locations: for gwy in loc.gateways: