10000 Use get_sysinfo to identify if device is Dimmer · Belval/python-kasa@32dc52a · GitHub
[go: up one dir, main page]

Skip to content

Commit 32dc52a

Browse files
committed
Use get_sysinfo to identify if device is Dimmer
1 parent e2e6627 commit 32dc52a

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

kasa/discover.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,10 @@ class Discover:
137137

138138
DISCOVERY_QUERY = {
139139
"system": {"get_sysinfo": None},
140+
}
141+
142+
COMPLETE_DISCOVERY_QUERY = {
143+
"system": {"get_sysinfo": None},
140144
"emeter": {"get_realtime": None},
141145
"smartlife.iot.dimmer": {"get_dimmer_parameters": None},
142146
"smartlife.iot.common.emeter": {"get_realtime": None},
@@ -198,16 +202,20 @@ async def discover(
198202
return protocol.discovered_devices
199203

200204
@staticmethod
201-
async def discover_single(host: str) -> SmartDevice:
205+
async def discover_single(host: str, complete: bool) -> SmartDevice:
202206
"""Discover a single device by the given IP address.
203207
204208
:param host: Hostname of device to query
209+
:param complete: Whether to discover only with get_sysinfo or all options
205210
:rtype: SmartDevice
206211
:return: Object for querying/controlling found device.
207212
"""
208213
protocol = TPLinkSmartHomeProtocol()
209214

210-
info = await protocol.query(host, Discover.DISCOVERY_QUERY)
215+
if complete:
216+
info = await protocol.query(host, Discover.COMPLETE_DISCOVERY_QUERY)
217+
else:
218+
info = await protocol.query(host, Discover.DISCOVERY_QUERY)
211219

212220
device_class = Discover._get_device_class(info)
213221
if device_class is not None:
@@ -231,10 +239,7 @@ def _get_device_class(info: dict) -> Type[SmartDevice]:
231239
else:
232240
raise SmartDeviceException("No 'system' nor 'get_sysinfo' in response")
233241

234-
if (
235-
"smartlife.iot.dimmer" in info
236-
and "get_dimmer_parameters" in info["smartlife.iot.dimmer"]
237-
):
242+
if "Dimmer" in sysinfo["dev_name"]:
238243
return SmartDimmer
239244

240245
elif "smartplug" in type_.lower() and "children" in sysinfo:

0 commit comments

Comments
 (0)
0