Convert pytuya to asyncio

This commit is contained in:
Pierre Ståhl
2020-10-01 09:40:12 +02:00
committed by rospogrigio
parent 084b3a741a
commit cad31f1ffe
8 changed files with 457 additions and 308 deletions

View File

@@ -159,22 +159,23 @@ def config_schema():
async def validate_input(hass: core.HomeAssistant, data):
"""Validate the user input allows us to connect."""
tuyainterface = pytuya.TuyaInterface(
data[CONF_DEVICE_ID],
data[CONF_HOST],
data[CONF_LOCAL_KEY],
float(data[CONF_PROTOCOL_VERSION]),
)
detected_dps = {}
try:
detected_dps = await hass.async_add_executor_job(
tuyainterface.detect_available_dps
interface = await pytuya.connect(
data[CONF_HOST],
data[CONF_DEVICE_ID],
data[CONF_LOCAL_KEY],
float(data[CONF_PROTOCOL_VERSION]),
)
detected_dps = await interface.detect_available_dps()
except (ConnectionRefusedError, ConnectionResetError):
raise CannotConnect
except ValueError:
raise InvalidAuth
finally:
interface.close()
return dps_string_list(detected_dps)