mirror of
https://github.com/python-kasa/python-kasa.git
synced 2024-12-22 19:23:34 +00:00
Update config to_dict to exclude credentials if the hash is empty string (#626)
* Update config to_dict to exclude credentials if the hash is empty string * Add test
This commit is contained in:
parent
d5a6fd8e73
commit
fd2170c82c
@ -165,7 +165,7 @@ class DeviceConfig:
|
||||
exclude_credentials: bool = False,
|
||||
) -> Dict[str, Dict[str, str]]:
|
||||
"""Convert device config to dict."""
|
||||
if credentials_hash or exclude_credentials:
|
||||
if credentials_hash is not None or exclude_credentials:
|
||||
self.credentials = None
|
||||
if credentials_hash:
|
||||
self.credentials_hash = credentials_hash
|
||||
|
@ -35,7 +35,21 @@ def test_credentials_hash():
|
||||
assert config2.credentials is None
|
||||
|
||||
|
||||
def test_no_credentials_serialization():
|
||||
def test_blank_credentials_hash():
|
||||
config = DeviceConfig(
|
||||
host="Foo",
|
||||
http_client=httpx.AsyncClient(),
|
||||
credentials=Credentials("foo", "bar"),
|
||||
)
|
||||
config_dict = config.to_dict(credentials_hash="")
|
||||
config_json = json_dumps(config_dict)
|
||||
config2_dict = json_loads(config_json)
|
||||
config2 = DeviceConfig.from_dict(config2_dict)
|
||||
assert config2.credentials_hash is None
|
||||
assert config2.credentials is None
|
||||
|
||||
|
||||
def test_exclude_credentials():
|
||||
config = DeviceConfig(
|
||||
host="Foo",
|
||||
http_client=httpx.AsyncClient(),
|
||||
|
Loading…
Reference in New Issue
Block a user