mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-06 10:44:04 +00:00
Update transport close/reset behaviour (#689)
Co-authored-by: J. Nick Koston <nick@koston.org>
This commit is contained in:
@@ -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
|
||||
|
@@ -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):
|
||||
|
@@ -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
|
||||
|
@@ -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):
|
||||
|
@@ -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(),
|
||||
|
@@ -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])
|
||||
|
Reference in New Issue
Block a user