@@ -341,23 +341,30 @@ async def connect_single(
341341
342342 :param host: Hostname of device to query
343343 :param device_type: Device type to use for the device.
344+ If not given, the device type is discovered by querying the device.
345+ If the device type is already known, it is preferred to pass it
346+ to avoid the extra query to the device to discover its type.
344347 :rtype: SmartDevice
345348 :return: Object for querying/controlling found device.
346349 """
347350 if device_type and (klass := DEVICE_TYPE_TO_CLASS .get (device_type )):
348- dev = klass (host = host , port = port , credentials = credentials , timeout = timeout )
349- else :
350- unknown_dev = SmartDevice (
351- host = host , port = port , credentials = credentials , timeout = timeout
352- )
353- await unknown_dev .update ()
354- device_class = Discover ._get_device_class (unknown_dev .internal_state )
355- dev = device_class (
351+ dev : SmartDevice = klass (
356352 host = host , port = port , credentials = credentials , timeout = timeout
357353 )
358- # Reuse the connection from the unknown device
359- # so we don't have to reconnect
360- dev .protocol = unknown_dev .protocol
354+ await dev .update ()
355+ return dev
356+
357+ unknown_dev = SmartDevice (
358+ host = host , port = port , credentials = credentials , timeout = timeout
359+ )
360+ await unknown_dev .update ()
361+ device_class = Discover ._get_device_class (unknown_dev .internal_state )
362+ dev = device_class (
363+ host = host , port = port , credentials = credentials , timeout = timeout
364+ )
365+ # Reuse the connection from the unknown device
366+ # so we don't have to reconnect
367+ dev .protocol = unknown_dev .protocol
361368 await dev .update ()
362369 return dev
363370
0 commit comments