adjust per review

This commit is contained in:
J. Nick Koston 2023-11-02 18:01:09 -05:00
parent 6573ee0f8a
commit bcdcd5f982
No known key found for this signature in database

View File

@ -341,23 +341,30 @@ class Discover:
:param host: Hostname of device to query :param host: Hostname of device to query
:param device_type: Device type to use for the device. :param device_type: Device type to use for the device.
If not given, the device type is discovered by querying the device.
If the device type is already known, it is preferred to pass it
to avoid the extra query to the device to discover its type.
:rtype: SmartDevice :rtype: SmartDevice
:return: Object for querying/controlling found device. :return: Object for querying/controlling found device.
""" """
if device_type and (klass := DEVICE_TYPE_TO_CLASS.get(device_type)): if device_type and (klass := DEVICE_TYPE_TO_CLASS.get(device_type)):
dev = klass(host=host, port=port, credentials=credentials, timeout=timeout) dev: SmartDevice = klass(
else:
unknown_dev = SmartDevice(
host=host, port=port, credentials=credentials, timeout=timeout host=host, port=port, credentials=credentials, timeout=timeout
) )
await unknown_dev.update() await dev.update()
device_class = Discover._get_device_class(unknown_dev.internal_state) return dev
dev = device_class(
host=host, port=port, credentials=credentials, timeout=timeout unknown_dev = SmartDevice(
) host=host, port=port, credentials=credentials, timeout=timeout
# Reuse the connection from the unknown device )
# so we don't have to reconnect await unknown_dev.update()
dev.protocol = unknown_dev.protocol device_class = Discover._get_device_class(unknown_dev.internal_state)
dev = device_class(
host=host, port=port, credentials=credentials, timeout=timeout
)
# Reuse the connection from the unknown device
# so we don't have to reconnect
dev.protocol = unknown_dev.protocol
await dev.update() await dev.update()
return dev return dev