Skip to content
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
2 changes: 2 additions & 0 deletions kasa/aestransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ def hash_credentials(self, login_v2):

async def client_post(self, url, params=None, data=None, json=None, headers=None):
"""Send an http post request to the device."""
if not self._http_client:
self._http_client = httpx.AsyncClient()
response_data = None
cookies = None
if self._session_cookie:
Expand Down
2 changes: 2 additions & 0 deletions kasa/klaptransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ def __init__(

async def client_post(self, url, params=None, data=None):
"""Send an http post request to the device."""
if not self._http_client:
self._http_client = httpx.AsyncClient()
response_data = None
cookies = None
if self._session_cookie:
Expand Down
10 changes: 5 additions & 5 deletions kasa/tests/test_klapprotocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def __init__(self, status_code, content: bytes):
async def test_protocol_retries(mocker, retry_count, protocol_class, transport_class):
host = "127.0.0.1"
conn = mocker.patch.object(
transport_class, "client_post", side_effect=Exception("dummy exception")
httpx.AsyncClient, "post", side_effect=Exception("dummy exception")
)
with pytest.raises(SmartDeviceException):
await protocol_class(host, transport=transport_class(host)).query(
Expand All @@ -49,8 +49,8 @@ async def test_protocol_no_retry_on_connection_error(
):
host = "127.0.0.1"
conn = mocker.patch.object(
transport_class,
"client_post",
httpx.AsyncClient,
"post",
side_effect=httpx.ConnectError("foo"),
)
with pytest.raises(SmartDeviceException):
Expand All @@ -68,8 +68,8 @@ async def test_protocol_retry_recoverable_error(
):
host = "127.0.0.1"
conn = mocker.patch.object(
transport_class,
"client_post",
httpx.AsyncClient,
"post",
side_effect=httpx.CloseError("foo"),
)
with pytest.raises(SmartDeviceException):
Expand Down