Update transport close/reset behaviour (#689)

Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
Steven B
2024-01-23 22:15:18 +00:00
committed by GitHub
parent e576fcdb46
commit 1788c50146
13 changed files with 66 additions and 43 deletions

View File

@@ -15,6 +15,7 @@ from kasa import (
Credentials,
Discover,
SmartBulb,
SmartDevice,
SmartDimmer,
SmartLightStrip,
SmartPlug,
@@ -416,9 +417,15 @@ async def dev(request):
IP_MODEL_CACHE[ip] = model = d.model
if model not in file:
pytest.skip(f"skipping file {file}")
return d if d else await _discover_update_and_close(ip, username, password)
dev: SmartDevice = (
d if d else await _discover_update_and_close(ip, username, password)
)
else:
dev: SmartDevice = await get_device_for_file(file, protocol)
return await get_device_for_file(file, protocol)
yield dev
await dev.disconnect()
@pytest.fixture

View File

@@ -377,6 +377,9 @@ class FakeSmartTransport(BaseTransport):
async def close(self) -> None:
pass
async def reset(self) -> None:
pass
class FakeTransportProtocol(TPLinkSmartHomeProtocol):
def __init__(self, info):

View File

@@ -147,6 +147,7 @@ async def test_login_errors(mocker, inner_error_codes, expectation, call_count):
await transport.send(json_dumps(request))
assert transport._login_token == mock_aes_device.token
assert post_mock.call_count == call_count # Login, Handshake, Login
await transport.close()
@status_parameters

View File

@@ -69,6 +69,8 @@ async def test_connect(
assert dev.config == config
await dev.disconnect()
@pytest.mark.parametrize("custom_port", [123, None])
async def test_connect_custom_port(all_fixture_data: dict, mocker, custom_port):

View File

@@ -19,12 +19,12 @@ from ..httpclient import HttpClient
(
aiohttp.ServerDisconnectedError(),
ConnectionException,
"Unable to connect to the device: ",
"Device connection error: ",
),
(
aiohttp.ClientOSError(),
ConnectionException,
"Unable to connect to the device: ",
"Device connection error: ",
),
(
aiohttp.ServerTimeoutError(),

View File

@@ -54,9 +54,10 @@ class _mock_response:
[
(Exception("dummy exception"), False),
(aiohttp.ServerTimeoutError("dummy exception"), True),
(aiohttp.ServerDisconnectedError("dummy exception"), True),
(aiohttp.ClientOSError("dummy exception"), True),
],
ids=("Exception", "SmartDeviceException", "ConnectError"),
ids=("Exception", "ServerTimeoutError", "ServerDisconnectedError", "ClientOSError"),
)
@pytest.mark.parametrize("transport_class", [AesTransport, KlapTransport])
@pytest.mark.parametrize("protocol_class", [IotProtocol, SmartProtocol])