Skip to content

Commit ef36d7b

Browse files
authored
Fix blocking call in Tuya initialisation (home-assistant#157477)
1 parent e5346ba commit ef36d7b

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

homeassistant/components/tuya/__init__.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ class HomeAssistantTuyaData(NamedTuple):
4444
listener: SharingDeviceListener
4545

4646

47-
async def async_setup_entry(hass: HomeAssistant, entry: TuyaConfigEntry) -> bool:
48-
"""Async setup hass config entry."""
49-
token_listener = TokenListener(hass, entry)
50-
manager = Manager(
47+
def _create_manager(entry: TuyaConfigEntry, token_listener: TokenListener) -> Manager:
48+
"""Create a Tuya Manager instance."""
49+
return Manager(
5150
TUYA_CLIENT_ID,
5251
entry.data[CONF_USER_CODE],
5352
entry.data[CONF_TERMINAL_ID],
@@ -56,6 +55,15 @@ async def async_setup_entry(hass: HomeAssistant, entry: TuyaConfigEntry) -> bool
5655
token_listener,
5756
)
5857

58+
59+
async def async_setup_entry(hass: HomeAssistant, entry: TuyaConfigEntry) -> bool:
60+
"""Async setup hass config entry."""
61+
token_listener = TokenListener(hass, entry)
62+
63+
# Move to executor as it makes blocking call to import_module
64+
# with args ('.system', 'urllib3.contrib.resolver')
65+
manager = await hass.async_add_executor_job(_create_manager, entry, token_listener)
66+
5967
listener = DeviceListener(hass, manager)
6068
manager.add_device_listener(listener)
6169

0 commit comments

Comments
 (0)