mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-08-09 20:24:02 +00:00
Update DiscoveryResult to use Mashumaro instead of pydantic (#1231)
Mashumaro is faster and doesn't come with all versioning problems that pydantic does. A basic perf test deserializing all of our discovery results fixtures shows mashumaro as being about 6 times faster deserializing dicts than pydantic. It's much faster parsing from a json string but that's likely because it uses orjson under the hood although that's not really our use case at the moment. ``` PYDANTIC - ms ================= json dict ----------------- 4.7665 1.3268 3.1548 1.5922 3.1130 1.8039 4.2834 2.7606 2.0669 1.3757 2.0163 1.6377 3.1667 1.3561 4.1296 2.7297 2.0132 1.3471 4.0648 1.4105 MASHUMARO - ms ================= json dict ----------------- 0.5977 0.5543 0.5336 0.2983 0.3955 0.2549 0.6516 0.2742 0.5386 0.2706 0.6678 0.2580 0.4120 0.2511 0.3836 0.2472 0.4020 0.2465 0.4268 0.2487 ```
This commit is contained in:
@@ -616,7 +616,7 @@ async def test_credentials(discovery_mock, mocker, runner):
|
||||
|
||||
mocker.patch("kasa.cli.device.state", new=_state)
|
||||
|
||||
dr = DiscoveryResult(**discovery_mock.discovery_data["result"])
|
||||
dr = DiscoveryResult.from_dict(discovery_mock.discovery_data["result"])
|
||||
res = await runner.invoke(
|
||||
cli,
|
||||
[
|
||||
|
@@ -43,7 +43,7 @@ pytestmark = [pytest.mark.requires_dummy]
|
||||
def _get_connection_type_device_class(discovery_info):
|
||||
if "result" in discovery_info:
|
||||
device_class = Discover._get_device_class(discovery_info)
|
||||
dr = DiscoveryResult(**discovery_info["result"])
|
||||
dr = DiscoveryResult.from_dict(discovery_info["result"])
|
||||
|
||||
connection_type = DeviceConnectionParameters.from_values(
|
||||
dr.device_type, dr.mgt_encrypt_schm.encrypt_type
|
||||
|
@@ -391,8 +391,8 @@ async def test_device_update_from_new_discovery_info(discovery_mock):
|
||||
discovery_data = discovery_mock.discovery_data
|
||||
device_class = Discover._get_device_class(discovery_data)
|
||||
device = device_class("127.0.0.1")
|
||||
discover_info = DiscoveryResult(**discovery_data["result"])
|
||||
discover_dump = discover_info.get_dict()
|
||||
discover_info = DiscoveryResult.from_dict(discovery_data["result"])
|
||||
discover_dump = discover_info.to_dict()
|
||||
model, _, _ = discover_dump["device_model"].partition("(")
|
||||
discover_dump["model"] = model
|
||||
device.update_from_discover_info(discover_dump)
|
||||
@@ -652,7 +652,7 @@ async def test_discovery_decryption():
|
||||
"sym_schm": "AES",
|
||||
}
|
||||
info = {**UNSUPPORTED["result"], "encrypt_info": encrypt_info}
|
||||
dr = DiscoveryResult(**info)
|
||||
dr = DiscoveryResult.from_dict(info)
|
||||
Discover._decrypt_discovery_data(dr)
|
||||
assert dr.decrypted_data == data_dict
|
||||
|
||||
|
Reference in New Issue
Block a user