Bump tuya-iot-py-sdk to 0.5.0 (#57110)
Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
parent
3c074ab865
commit
86852df2fc
7 changed files with 33 additions and 24 deletions
|
@ -4,7 +4,7 @@ import itertools
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from tuya_iot import (
|
from tuya_iot import (
|
||||||
ProjectType,
|
AuthType,
|
||||||
TuyaDevice,
|
TuyaDevice,
|
||||||
TuyaDeviceListener,
|
TuyaDeviceListener,
|
||||||
TuyaDeviceManager,
|
TuyaDeviceManager,
|
||||||
|
@ -22,6 +22,7 @@ from .const import (
|
||||||
CONF_ACCESS_ID,
|
CONF_ACCESS_ID,
|
||||||
CONF_ACCESS_SECRET,
|
CONF_ACCESS_SECRET,
|
||||||
CONF_APP_TYPE,
|
CONF_APP_TYPE,
|
||||||
|
CONF_AUTH_TYPE,
|
||||||
CONF_COUNTRY_CODE,
|
CONF_COUNTRY_CODE,
|
||||||
CONF_ENDPOINT,
|
CONF_ENDPOINT,
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
|
@ -45,28 +46,35 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
"""Async setup hass config entry."""
|
"""Async setup hass config entry."""
|
||||||
hass.data[DOMAIN] = {entry.entry_id: {TUYA_HA_TUYA_MAP: {}, TUYA_HA_DEVICES: set()}}
|
hass.data[DOMAIN] = {entry.entry_id: {TUYA_HA_TUYA_MAP: {}, TUYA_HA_DEVICES: set()}}
|
||||||
|
|
||||||
|
# Project type has been renamed to auth type in the upstream Tuya IoT SDK.
|
||||||
|
# This migrates existing config entries to reflect that name change.
|
||||||
|
if CONF_PROJECT_TYPE in entry.data:
|
||||||
|
data = {**entry.data, CONF_AUTH_TYPE: entry.data[CONF_PROJECT_TYPE]}
|
||||||
|
data.pop(CONF_PROJECT_TYPE)
|
||||||
|
hass.config_entries.async_update_entry(entry, data=data)
|
||||||
|
|
||||||
success = await _init_tuya_sdk(hass, entry)
|
success = await _init_tuya_sdk(hass, entry)
|
||||||
return bool(success)
|
return bool(success)
|
||||||
|
|
||||||
|
|
||||||
async def _init_tuya_sdk(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
async def _init_tuya_sdk(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||||
project_type = ProjectType(entry.data[CONF_PROJECT_TYPE])
|
auth_type = AuthType(entry.data[CONF_AUTH_TYPE])
|
||||||
api = TuyaOpenAPI(
|
api = TuyaOpenAPI(
|
||||||
entry.data[CONF_ENDPOINT],
|
endpoint=entry.data[CONF_ENDPOINT],
|
||||||
entry.data[CONF_ACCESS_ID],
|
access_id=entry.data[CONF_ACCESS_ID],
|
||||||
entry.data[CONF_ACCESS_SECRET],
|
access_secret=entry.data[CONF_ACCESS_SECRET],
|
||||||
project_type,
|
auth_type=auth_type,
|
||||||
)
|
)
|
||||||
|
|
||||||
api.set_dev_channel("hass")
|
api.set_dev_channel("hass")
|
||||||
|
|
||||||
if project_type == ProjectType.INDUSTY_SOLUTIONS:
|
if auth_type == AuthType.CUSTOM:
|
||||||
response = await hass.async_add_executor_job(
|
response = await hass.async_add_executor_job(
|
||||||
api.login, entry.data[CONF_USERNAME], entry.data[CONF_PASSWORD]
|
api.connect, entry.data[CONF_USERNAME], entry.data[CONF_PASSWORD]
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
response = await hass.async_add_executor_job(
|
response = await hass.async_add_executor_job(
|
||||||
api.login,
|
api.connect,
|
||||||
entry.data[CONF_USERNAME],
|
entry.data[CONF_USERNAME],
|
||||||
entry.data[CONF_PASSWORD],
|
entry.data[CONF_PASSWORD],
|
||||||
entry.data[CONF_COUNTRY_CODE],
|
entry.data[CONF_COUNTRY_CODE],
|
||||||
|
|
|
@ -4,7 +4,7 @@ from __future__ import annotations
|
||||||
import logging
|
import logging
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
from tuya_iot import ProjectType, TuyaOpenAPI
|
from tuya_iot import AuthType, TuyaOpenAPI
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
from voluptuous.schema_builder import UNDEFINED
|
from voluptuous.schema_builder import UNDEFINED
|
||||||
|
|
||||||
|
@ -14,10 +14,10 @@ from .const import (
|
||||||
CONF_ACCESS_ID,
|
CONF_ACCESS_ID,
|
||||||
CONF_ACCESS_SECRET,
|
CONF_ACCESS_SECRET,
|
||||||
CONF_APP_TYPE,
|
CONF_APP_TYPE,
|
||||||
|
CONF_AUTH_TYPE,
|
||||||
CONF_COUNTRY_CODE,
|
CONF_COUNTRY_CODE,
|
||||||
CONF_ENDPOINT,
|
CONF_ENDPOINT,
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
CONF_PROJECT_TYPE,
|
|
||||||
CONF_REGION,
|
CONF_REGION,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
@ -44,7 +44,7 @@ class TuyaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
|
|
||||||
data = {
|
data = {
|
||||||
CONF_ENDPOINT: TUYA_REGIONS[user_input[CONF_REGION]],
|
CONF_ENDPOINT: TUYA_REGIONS[user_input[CONF_REGION]],
|
||||||
CONF_PROJECT_TYPE: ProjectType.INDUSTY_SOLUTIONS,
|
CONF_AUTH_TYPE: AuthType.CUSTOM,
|
||||||
CONF_ACCESS_ID: user_input[CONF_ACCESS_ID],
|
CONF_ACCESS_ID: user_input[CONF_ACCESS_ID],
|
||||||
CONF_ACCESS_SECRET: user_input[CONF_ACCESS_SECRET],
|
CONF_ACCESS_SECRET: user_input[CONF_ACCESS_SECRET],
|
||||||
CONF_USERNAME: user_input[CONF_USERNAME],
|
CONF_USERNAME: user_input[CONF_USERNAME],
|
||||||
|
@ -55,19 +55,19 @@ class TuyaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
for app_type in ("", TUYA_SMART_APP, SMARTLIFE_APP):
|
for app_type in ("", TUYA_SMART_APP, SMARTLIFE_APP):
|
||||||
data[CONF_APP_TYPE] = app_type
|
data[CONF_APP_TYPE] = app_type
|
||||||
if data[CONF_APP_TYPE] == "":
|
if data[CONF_APP_TYPE] == "":
|
||||||
data[CONF_PROJECT_TYPE] = ProjectType.INDUSTY_SOLUTIONS
|
data[CONF_AUTH_TYPE] = AuthType.CUSTOM
|
||||||
else:
|
else:
|
||||||
data[CONF_PROJECT_TYPE] = ProjectType.SMART_HOME
|
data[CONF_AUTH_TYPE] = AuthType.SMART_HOME
|
||||||
|
|
||||||
api = TuyaOpenAPI(
|
api = TuyaOpenAPI(
|
||||||
endpoint=data[CONF_ENDPOINT],
|
endpoint=data[CONF_ENDPOINT],
|
||||||
access_id=data[CONF_ACCESS_ID],
|
access_id=data[CONF_ACCESS_ID],
|
||||||
access_secret=data[CONF_ACCESS_SECRET],
|
access_secret=data[CONF_ACCESS_SECRET],
|
||||||
project_type=data[CONF_PROJECT_TYPE],
|
auth_type=data[CONF_AUTH_TYPE],
|
||||||
)
|
)
|
||||||
api.set_dev_channel("hass")
|
api.set_dev_channel("hass")
|
||||||
|
|
||||||
response = api.login(
|
response = api.connect(
|
||||||
username=data[CONF_USERNAME],
|
username=data[CONF_USERNAME],
|
||||||
password=data[CONF_PASSWORD],
|
password=data[CONF_PASSWORD],
|
||||||
country_code=data[CONF_COUNTRY_CODE],
|
country_code=data[CONF_COUNTRY_CODE],
|
||||||
|
@ -97,7 +97,7 @@ class TuyaConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
):
|
):
|
||||||
data[CONF_ENDPOINT] = endpoint
|
data[CONF_ENDPOINT] = endpoint
|
||||||
|
|
||||||
data[CONF_PROJECT_TYPE] = data[CONF_PROJECT_TYPE].value
|
data[CONF_AUTH_TYPE] = data[CONF_AUTH_TYPE].value
|
||||||
|
|
||||||
return self.async_create_entry(
|
return self.async_create_entry(
|
||||||
title=user_input[CONF_USERNAME],
|
title=user_input[CONF_USERNAME],
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
DOMAIN = "tuya"
|
DOMAIN = "tuya"
|
||||||
|
|
||||||
|
CONF_AUTH_TYPE = "auth_type"
|
||||||
CONF_PROJECT_TYPE = "tuya_project_type"
|
CONF_PROJECT_TYPE = "tuya_project_type"
|
||||||
CONF_ENDPOINT = "endpoint"
|
CONF_ENDPOINT = "endpoint"
|
||||||
CONF_ACCESS_ID = "access_id"
|
CONF_ACCESS_ID = "access_id"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
"domain": "tuya",
|
"domain": "tuya",
|
||||||
"name": "Tuya",
|
"name": "Tuya",
|
||||||
"documentation": "https://github.com/tuya/tuya-home-assistant",
|
"documentation": "https://github.com/tuya/tuya-home-assistant",
|
||||||
"requirements": ["tuya-iot-py-sdk==0.4.1"],
|
"requirements": ["tuya-iot-py-sdk==0.5.0"],
|
||||||
"codeowners": ["@Tuya", "@zlinoliver", "@METISU"],
|
"codeowners": ["@Tuya", "@zlinoliver", "@METISU"],
|
||||||
"config_flow": true,
|
"config_flow": true,
|
||||||
"iot_class": "cloud_push"
|
"iot_class": "cloud_push"
|
||||||
|
|
|
@ -2329,7 +2329,7 @@ tp-connected==0.0.4
|
||||||
transmissionrpc==0.11
|
transmissionrpc==0.11
|
||||||
|
|
||||||
# homeassistant.components.tuya
|
# homeassistant.components.tuya
|
||||||
tuya-iot-py-sdk==0.4.1
|
tuya-iot-py-sdk==0.5.0
|
||||||
|
|
||||||
# homeassistant.components.twentemilieu
|
# homeassistant.components.twentemilieu
|
||||||
twentemilieu==0.3.0
|
twentemilieu==0.3.0
|
||||||
|
|
|
@ -1318,7 +1318,7 @@ total_connect_client==0.57
|
||||||
transmissionrpc==0.11
|
transmissionrpc==0.11
|
||||||
|
|
||||||
# homeassistant.components.tuya
|
# homeassistant.components.tuya
|
||||||
tuya-iot-py-sdk==0.4.1
|
tuya-iot-py-sdk==0.5.0
|
||||||
|
|
||||||
# homeassistant.components.twentemilieu
|
# homeassistant.components.twentemilieu
|
||||||
twentemilieu==0.3.0
|
twentemilieu==0.3.0
|
||||||
|
|
|
@ -11,9 +11,9 @@ from homeassistant.components.tuya.const import (
|
||||||
CONF_ACCESS_ID,
|
CONF_ACCESS_ID,
|
||||||
CONF_ACCESS_SECRET,
|
CONF_ACCESS_SECRET,
|
||||||
CONF_APP_TYPE,
|
CONF_APP_TYPE,
|
||||||
|
CONF_AUTH_TYPE,
|
||||||
CONF_ENDPOINT,
|
CONF_ENDPOINT,
|
||||||
CONF_PASSWORD,
|
CONF_PASSWORD,
|
||||||
CONF_PROJECT_TYPE,
|
|
||||||
CONF_REGION,
|
CONF_REGION,
|
||||||
CONF_USERNAME,
|
CONF_USERNAME,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
|
@ -86,7 +86,7 @@ async def test_user_flow(
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "user"
|
||||||
|
|
||||||
tuya().login = MagicMock(side_effect=side_effects)
|
tuya().connect = MagicMock(side_effect=side_effects)
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], user_input=TUYA_INPUT_DATA
|
result["flow_id"], user_input=TUYA_INPUT_DATA
|
||||||
)
|
)
|
||||||
|
@ -101,7 +101,7 @@ async def test_user_flow(
|
||||||
assert result["data"][CONF_ENDPOINT] == MOCK_ENDPOINT
|
assert result["data"][CONF_ENDPOINT] == MOCK_ENDPOINT
|
||||||
assert result["data"][CONF_ENDPOINT] != TUYA_REGIONS[TUYA_INPUT_DATA[CONF_REGION]]
|
assert result["data"][CONF_ENDPOINT] != TUYA_REGIONS[TUYA_INPUT_DATA[CONF_REGION]]
|
||||||
assert result["data"][CONF_APP_TYPE] == app_type
|
assert result["data"][CONF_APP_TYPE] == app_type
|
||||||
assert result["data"][CONF_PROJECT_TYPE] == project_type
|
assert result["data"][CONF_AUTH_TYPE] == project_type
|
||||||
assert not result["result"].unique_id
|
assert not result["result"].unique_id
|
||||||
|
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ async def test_error_on_invalid_credentials(hass, tuya):
|
||||||
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
assert result["type"] == data_entry_flow.RESULT_TYPE_FORM
|
||||||
assert result["step_id"] == "user"
|
assert result["step_id"] == "user"
|
||||||
|
|
||||||
tuya().login = MagicMock(return_value=RESPONSE_ERROR)
|
tuya().connect = MagicMock(return_value=RESPONSE_ERROR)
|
||||||
result = await hass.config_entries.flow.async_configure(
|
result = await hass.config_entries.flow.async_configure(
|
||||||
result["flow_id"], user_input=TUYA_INPUT_DATA
|
result["flow_id"], user_input=TUYA_INPUT_DATA
|
||||||
)
|
)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue