From 6e9bb70c18fe58811a87297d29f6ae493b813e71 Mon Sep 17 00:00:00 2001 From: Steven B <51370195+sdb9696@users.noreply.github.com> Date: Fri, 25 Oct 2024 16:16:35 +0100 Subject: [PATCH 1/2] Fix device_config serialisation of https value --- kasa/deviceconfig.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kasa/deviceconfig.py b/kasa/deviceconfig.py index 1bd806f0d..ddc3c3f74 100644 --- a/kasa/deviceconfig.py +++ b/kasa/deviceconfig.py @@ -34,7 +34,7 @@ import logging from dataclasses import asdict, dataclass, field, fields, is_dataclass from enum import Enum -from typing import TYPE_CHECKING, Dict, Optional, TypedDict, Union +from typing import TYPE_CHECKING, Any, Dict, Optional, TypedDict, Union from .credentials import Credentials from .exceptions import KasaException @@ -145,7 +145,7 @@ def from_values( ) from ex @staticmethod - def from_dict(connection_type_dict: Dict[str, str]) -> "DeviceConnectionParameters": + def from_dict(connection_type_dict: Dict[str, Any]) -> "DeviceConnectionParameters": """Return connection parameters from dict.""" if ( isinstance(connection_type_dict, dict) @@ -158,15 +158,17 @@ def from_dict(connection_type_dict: Dict[str, str]) -> "DeviceConnectionParamete device_family, encryption_type, login_version, # type: ignore[arg-type] + connection_type_dict.get("https", False), ) raise KasaException(f"Invalid connection type data for {connection_type_dict}") - def to_dict(self) -> Dict[str, Union[str, int]]: + def to_dict(self) -> Dict[str, Union[str, int, bool]]: """Convert connection params to dict.""" result: Dict[str, Union[str, int]] = { "device_family": self.device_family.value, "encryption_type": self.encryption_type.value, + "https": self.https, } if self.login_version: result["login_version"] = self.login_version From baaa7d65773efb7adade4340a37a1ea07a669404 Mon Sep 17 00:00:00 2001 From: Steven B <51370195+sdb9696@users.noreply.github.com> Date: Fri, 25 Oct 2024 16:50:41 +0100 Subject: [PATCH 2/2] Fix readme test --- kasa/deviceconfig.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/kasa/deviceconfig.py b/kasa/deviceconfig.py index ddc3c3f74..e0fd1725c 100644 --- a/kasa/deviceconfig.py +++ b/kasa/deviceconfig.py @@ -18,8 +18,8 @@ >>> # DeviceConfig.to_dict() can be used to store for later >>> print(config_dict) {'host': '127.0.0.3', 'timeout': 5, 'credentials': Credentials(), 'connection_type'\ -: {'device_family': 'SMART.TAPOBULB', 'encryption_type': 'KLAP', 'login_version': 2},\ - 'uses_http': True} +: {'device_family': 'SMART.TAPOBULB', 'encryption_type': 'KLAP', 'https': False, \ +'login_version': 2}, 'uses_http': True} >>> later_device = await Device.connect(config=Device.Config.from_dict(config_dict)) >>> print(later_device.alias) # Alias is available as connect() calls update()