mirror of
https://github.com/python-kasa/python-kasa.git
synced 2025-01-08 22:07:06 +00:00
Fix device_config serialisation of https value (#1196)
This commit is contained in:
parent
e3610cf37e
commit
91e219f467
@ -18,8 +18,8 @@ None
|
|||||||
>>> # DeviceConfig.to_dict() can be used to store for later
|
>>> # DeviceConfig.to_dict() can be used to store for later
|
||||||
>>> print(config_dict)
|
>>> print(config_dict)
|
||||||
{'host': '127.0.0.3', 'timeout': 5, 'credentials': Credentials(), 'connection_type'\
|
{'host': '127.0.0.3', 'timeout': 5, 'credentials': Credentials(), 'connection_type'\
|
||||||
: {'device_family': 'SMART.TAPOBULB', 'encryption_type': 'KLAP', 'login_version': 2},\
|
: {'device_family': 'SMART.TAPOBULB', 'encryption_type': 'KLAP', 'https': False, \
|
||||||
'uses_http': True}
|
'login_version': 2}, 'uses_http': True}
|
||||||
|
|
||||||
>>> later_device = await Device.connect(config=Device.Config.from_dict(config_dict))
|
>>> later_device = await Device.connect(config=Device.Config.from_dict(config_dict))
|
||||||
>>> print(later_device.alias) # Alias is available as connect() calls update()
|
>>> print(later_device.alias) # Alias is available as connect() calls update()
|
||||||
@ -34,7 +34,7 @@ Living Room Bulb
|
|||||||
import logging
|
import logging
|
||||||
from dataclasses import asdict, dataclass, field, fields, is_dataclass
|
from dataclasses import asdict, dataclass, field, fields, is_dataclass
|
||||||
from enum import Enum
|
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 .credentials import Credentials
|
||||||
from .exceptions import KasaException
|
from .exceptions import KasaException
|
||||||
@ -145,7 +145,7 @@ class DeviceConnectionParameters:
|
|||||||
) from ex
|
) from ex
|
||||||
|
|
||||||
@staticmethod
|
@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."""
|
"""Return connection parameters from dict."""
|
||||||
if (
|
if (
|
||||||
isinstance(connection_type_dict, dict)
|
isinstance(connection_type_dict, dict)
|
||||||
@ -158,15 +158,17 @@ class DeviceConnectionParameters:
|
|||||||
device_family,
|
device_family,
|
||||||
encryption_type,
|
encryption_type,
|
||||||
login_version, # type: ignore[arg-type]
|
login_version, # type: ignore[arg-type]
|
||||||
|
connection_type_dict.get("https", False),
|
||||||
)
|
)
|
||||||
|
|
||||||
raise KasaException(f"Invalid connection type data for {connection_type_dict}")
|
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."""
|
"""Convert connection params to dict."""
|
||||||
result: Dict[str, Union[str, int]] = {
|
result: Dict[str, Union[str, int]] = {
|
||||||
"device_family": self.device_family.value,
|
"device_family": self.device_family.value,
|
||||||
"encryption_type": self.encryption_type.value,
|
"encryption_type": self.encryption_type.value,
|
||||||
|
"https": self.https,
|
||||||
}
|
}
|
||||||
if self.login_version:
|
if self.login_version:
|
||||||
result["login_version"] = self.login_version
|
result["login_version"] = self.login_version
|
||||||
|
Loading…
Reference in New Issue
Block a user