Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Fix device_config serialisation of https value #1196

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 25, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions kasa/deviceconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down
Loading