From 5221fc07ca26153584bb88d59ef46a567225e1e3 Mon Sep 17 00:00:00 2001 From: "Steven B." <51370195+sdb9696@users.noreply.github.com> Date: Thu, 21 Nov 2024 18:18:04 +0000 Subject: [PATCH] Simplify omit http_client in DeviceConfig serialization (#1292) Related explanation: https://github.com/Fatal1ty/mashumaro/issues/264 --- kasa/deviceconfig.py | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/kasa/deviceconfig.py b/kasa/deviceconfig.py index 56e97f5e..1156cf25 100644 --- a/kasa/deviceconfig.py +++ b/kasa/deviceconfig.py @@ -33,12 +33,11 @@ from __future__ import annotations import logging from dataclasses import dataclass, field, replace from enum import Enum -from typing import TYPE_CHECKING, Any, Self, TypedDict +from typing import TYPE_CHECKING, TypedDict from aiohttp import ClientSession -from mashumaro import field_options +from mashumaro import field_options, pass_through from mashumaro.config import BaseConfig -from mashumaro.types import SerializationStrategy from .credentials import Credentials from .exceptions import KasaException @@ -122,14 +121,6 @@ class DeviceConnectionParameters(_DeviceConfigBaseMixin): ) from ex -class _DoNotSerialize(SerializationStrategy): - def serialize(self, value: Any) -> None: - return None # pragma: no cover - - def deserialize(self, value: Any) -> None: - return None # pragma: no cover - - @dataclass class DeviceConfig(_DeviceConfigBaseMixin): """Class to represent paramaters that determine how to connect to devices.""" @@ -163,7 +154,7 @@ class DeviceConfig(_DeviceConfigBaseMixin): http_client: ClientSession | None = field( default=None, compare=False, - metadata=field_options(serialization_strategy=_DoNotSerialize()), + metadata=field_options(serialize="omit", deserialize=pass_through), ) aes_keys: KeyPairDict | None = None @@ -174,9 +165,6 @@ class DeviceConfig(_DeviceConfigBaseMixin): DeviceFamily.IotSmartPlugSwitch, DeviceEncryptionType.Xor ) - def __pre_serialize__(self) -> Self: - return replace(self, http_client=None) - def to_dict_control_credentials( self, *,