mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-06 10:44:04 +00:00
Let caller handle SMART errors on multi-requests (#754)
* Fix for missing get_device_usage * Fix coverage and add methods to exceptions * Remove unused caplog fixture
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import importlib
|
||||
import inspect
|
||||
import logging
|
||||
import pkgutil
|
||||
import re
|
||||
import sys
|
||||
@@ -21,10 +22,18 @@ from voluptuous import (
|
||||
|
||||
import kasa
|
||||
from kasa import Credentials, Device, DeviceConfig, SmartDeviceException
|
||||
from kasa.exceptions import SmartErrorCode
|
||||
from kasa.iot import IotDevice
|
||||
from kasa.smart import SmartChildDevice, SmartDevice
|
||||
|
||||
from .conftest import device_iot, handle_turn_on, has_emeter_iot, no_emeter_iot, turn_on
|
||||
from .conftest import (
|
||||
device_iot,
|
||||
device_smart,
|
||||
handle_turn_on,
|
||||
has_emeter_iot,
|
||||
no_emeter_iot,
|
||||
turn_on,
|
||||
)
|
||||
from .fakeprotocol_iot import FakeIotProtocol
|
||||
|
||||
|
||||
@@ -300,6 +309,33 @@ async def test_modules_not_supported(dev: IotDevice):
|
||||
assert module.is_supported is not None
|
||||
|
||||
|
||||
@device_smart
|
||||
async def test_update_sub_errors(dev: SmartDevice, caplog):
|
||||
mock_response: dict = {
|
||||
"get_device_info": {},
|
||||
"get_device_usage": SmartErrorCode.PARAMS_ERROR,
|
||||
"get_device_time": {},
|
||||
}
|
||||
caplog.set_level(logging.DEBUG)
|
||||
with patch.object(dev.protocol, "query", return_value=mock_response):
|
||||
await dev.update()
|
||||
msg = "Error PARAMS_ERROR(-1008) getting request get_device_usage for device 127.0.0.123"
|
||||
assert msg in caplog.text
|
||||
|
||||
|
||||
@device_smart
|
||||
async def test_update_no_device_info(dev: SmartDevice):
|
||||
mock_response: dict = {
|
||||
"get_device_usage": {},
|
||||
"get_device_time": {},
|
||||
}
|
||||
msg = f"get_device_info not found in {mock_response} for device 127.0.0.123"
|
||||
with patch.object(dev.protocol, "query", return_value=mock_response), pytest.raises(
|
||||
SmartDeviceException, match=msg
|
||||
):
|
||||
await dev.update()
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"device_class, use_class", kasa.deprecated_smart_devices.items()
|
||||
)
|
||||
|
@@ -60,13 +60,10 @@ async def test_smart_device_errors_in_multiple_request(
|
||||
send_mock = mocker.patch.object(
|
||||
dummy_protocol._transport, "send", return_value=mock_response
|
||||
)
|
||||
with pytest.raises(SmartDeviceException):
|
||||
await dummy_protocol.query(DUMMY_MULTIPLE_QUERY, retry_count=2)
|
||||
if error_code in chain(SMART_TIMEOUT_ERRORS, SMART_RETRYABLE_ERRORS):
|
||||
expected_calls = 3
|
||||
else:
|
||||
expected_calls = 1
|
||||
assert send_mock.call_count == expected_calls
|
||||
|
||||
resp_dict = await dummy_protocol.query(DUMMY_MULTIPLE_QUERY, retry_count=2)
|
||||
assert resp_dict["foobar2"] == error_code
|
||||
assert send_mock.call_count == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize("request_size", [1, 3, 5, 10])
|
||||
|
Reference in New Issue
Block a user