Skip to content

Commit

Permalink
mypy, ruff, lint
Browse files Browse the repository at this point in the history
  • Loading branch information
zxdavb committed Aug 20, 2024
1 parent a49e7c4 commit ddc48e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 24 deletions.
31 changes: 15 additions & 16 deletions src/evohomeasync/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from __future__ import annotations

import asyncio
import logging
from datetime import datetime as dt
from http import HTTPMethod
Expand Down Expand Up @@ -35,7 +34,6 @@
SZ_SCHEDULED,
SZ_SESSION_ID,
SZ_SETPOINT,
SZ_STATE,
SZ_STATUS,
SZ_TEMP,
SZ_TEMPORARY,
Expand All @@ -52,7 +50,6 @@
_DhwIdT,
_EvoListT,
_LocationIdT,
_TaskIdT,
_ZoneIdT,
_ZoneNameT,
)
Expand Down Expand Up @@ -96,25 +93,27 @@ async def _wait_for_put_task(self, response: aiohttp.ClientResponse) -> NoReturn

raise exc.DeprecationError("EvohomeClient._wait_for_put_task() is deprecated")

async def get_task_status(task_id: _TaskIdT) -> str: # type: ignore[unreachable]
await self._populate_locn_data()
# # Code fragment left here, as documention of get_task_status()...

url = f"commTasks?commTaskId={task_id}"
response = await self._do_request(HTTPMethod.GET, url)
# async def get_task_status(task_id: _TaskIdT) -> str:
# await self._populate_locn_data()

ret: str = dict(await response.json())[SZ_STATE]
return ret
# url = f"commTasks?commTaskId={task_id}"
# response = await self._do_request(HTTPMethod.GET, url)

task_id: _TaskIdT
# ret: str = dict(await response.json())[SZ_STATE]
# return ret

assert response.method == HTTPMethod.PUT
# task_id: _TaskIdT

ret = await response.json()
task_id = ret[0][SZ_ID] if isinstance(ret, list) else ret[SZ_ID]
# assert response.method == HTTPMethod.PUT

# FIXME: could wait forvever?
while await get_task_status(task_id) != "Succeeded":
await asyncio.sleep(1)
# ret = await response.json()
# task_id = ret[0][SZ_ID] if isinstance(ret, list) else ret[SZ_ID]

# # FIXME: could wait forvever?
# while await get_task_status(task_id) != "Succeeded":
# await asyncio.sleep(1)

async def _do_request(self, *args, **kwargs) -> NoReturn: # type: ignore[no-untyped-def]
raise exc.DeprecationError(
Expand Down
13 changes: 5 additions & 8 deletions tests/tests_rf/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,25 +282,22 @@ async def should_fail(
return content


async def wait_for_comm_task(
evo: evo2.EvohomeClient,
task_id: str,
timeout: int = 3,
) -> bool | None:
async def wait_for_comm_task(evo: evo2.EvohomeClient, task_id: str) -> bool | None:
"""Wait for a communication task (API call) to complete."""

# invoke via:
# async with asyncio.timeout(2):
# await wait_for_comm_task()

await asyncio.sleep(0.5)

url = f"commTasks?commTaskId={task_id}"

start_time = dt.now()
while True:
response = await should_work(evo, HTTPMethod.GET, url)
assert isinstance(response, dict | list), response
if response["state"] == "Succeeded": # type: ignore[call-overload]
return True
if (dt.now() - start_time).total_seconds() > timeout:
return False
if response["state"] in ("Created", "Running"): # type: ignore[call-overload]
await asyncio.sleep(0.3)
continue
Expand Down

0 comments on commit ddc48e0

Please sign in to comment.