mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-10-20 06:18:01 +00:00
Update transport close/reset behaviour
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):
|
||||
|
@@ -7,6 +7,7 @@ import pytest
|
||||
from ..deviceconfig import DeviceConfig
|
||||
from ..exceptions import (
|
||||
ConnectionException,
|
||||
DisconnectedException,
|
||||
SmartDeviceException,
|
||||
TimeoutException,
|
||||
)
|
||||
@@ -18,8 +19,8 @@ from ..httpclient import HttpClient
|
||||
[
|
||||
(
|
||||
aiohttp.ServerDisconnectedError(),
|
||||
ConnectionException,
|
||||
"Unable to connect to the device: ",
|
||||
DisconnectedException,
|
||||
"Disconnected from the device: ",
|
||||
),
|
||||
(
|
||||
aiohttp.ClientOSError(),
|
||||
|
@@ -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", "SmartDeviceException", "DisconnectError", "ConnectError"),
|
||||
)
|
||||
@pytest.mark.parametrize("transport_class", [AesTransport, KlapTransport])
|
||||
@pytest.mark.parametrize("protocol_class", [IotProtocol, SmartProtocol])
|
||||
|
Reference in New Issue
Block a user