10000 Update following review. Do not serialize aliases. · python-kasa/python-kasa@b54dba6 · GitHub
[go: up one dir, main page]

Skip to content

Commit b54dba6

Browse files
committed
Update following review. Do not serialize aliases.
1 parent a077f19 commit b54dba6

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

devtools/dump_devinfo.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import asyncclick as click
1818

1919
from kasa import Credentials, Discover
20+
from kasa.discover import DiscoveryResult
2021

2122
Call = namedtuple("Call", "module method")
2223

@@ -34,8 +35,13 @@ def scrub(res):
3435
"longitude_i",
3536
"latitude",
3637
"longitude",
37-
"device_owner_hash",
38-
"device_id_hash",
38+
"owner",
39+
"device_id",
40+
"ip",
41+
"ssid",
42+
"hw_id",
43+
"fw_id",
44+
"oem_id",
3945
]
4046

4147
for k, v in res.items():
@@ -45,6 +51,8 @@ def scrub(res):
4551
if k in keys_to_scrub:
4652
if k in ["latitude", "latitude_i", "longitude", "longitude_i"]:
4753
v = 0
54+
elif k in ["ip"]:
55+
v = "127.0.0.123"
4856
else:
4957
v = re.sub(r"\w", "0", v)
5058

@@ -135,8 +143,13 @@ async def cli(host, debug, username, password):
135143
)
136144
)
137145

138-
if device.discovery_info:
139-
final["discovery_result"] = device.discovery_info
146+
if device._discovery_info:
147+
# Need to recreate a DiscoverResult here because we don't want the aliases
148+
# in the fixture, we want the actual field names as returned by the device.
149+
dr = DiscoveryResult(**device._discovery_info)
150+
final["discovery_result"] = dr.dict(
151+
by_alias=False, exclude_unset=True, exclude_none=True, exclude_defaults=True
152+
)
140153

141154
click.echo("Got %s successes" % len(successes))
142155
click.echo(click.style("## device info file ##", bold=True))

kasa/smartdevice.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def __init__(
211211
# checks in accessors. the @updated_required decorator does not ensure
212212
# mypy that these are not accessed incorrectly.
213213
self._last_update: Any = None
214-
self.discovery_info: Optional[Dict[str, Any]] = None
214+
self._discovery_info: Optional[Dict[str, Any]] = None
215215

216216
self._sys_info: Any = None # TODO: this is here to avoid changing tests
217217
self._features: Set[str] = set()
@@ -372,7 +372,7 @@ def update_from_discover_info(self, info: Dict[str, Any]) -> None:
372372
# This allows setting of some info properties directly
373373
# from partial discovery info that will then be found
374374
# by the requires_update decorator
375-
self.discovery_info = info
375+
self._discovery_info = info
376376
self._set_sys_info(info)
377377

378378
def _set_sys_info(self, sys_info: Dict[str, Any]) -> None:

kasa/tests/fixtures/HS100(UK)_4.1_1.1.0.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
{
22
"discovery_result": {
3-
"alias": "192.168.1.84",
4-
"device_id_hash": "00000000000000000000000000000000",
5-
"device_owner_hash": "00000000000000000000000000000000",
6-
"device_type_text": "IOT.SMARTPLUGSWITCH",
3+
"device_id": "00000000000000000000000000000000",
4+
"device_model": "HS100(UK)",
5+
"device_type": "IOT.SMARTPLUGSWITCH",
76
"factory_default": true,
87
"hw_ver": "4.1",
8+
"ip": "127.0.0.123",
99
"mac": "00-00-00-00-00-00",
1010
"mgt_encrypt_schm": {
1111
"encrypt_type": "KLAP",
1212
"http_port": 80,
1313
"is_support_https": false
1414
},
15-
"model": "HS100(UK)"
15+
"owner": "00000000000000000000000000000000"
1616
},
1717
"system": {
1818
"get_sysinfo": {
@@ -36,9 +36,9 @@
3636
},
3737
"ntc_state": 0,
3838
"oemId": "00000000000000000000000000000000",
39-
"on_time": 3115,
40-
"relay_state": 1,
41-
"rssi": -63,
39+
"on_time": 0,
40+
"relay_state": 0,
41+
"rssi": -66,
4242
"status": "new",
4343
"sw_ver": "1.1.0 Build 201016 Rel.175121",
4444
"updating": 0

0 commit comments

Comments
 (0)
0