ha_tuya_ble: Error after updating to Home Assistant 2024.2.0 update

Description

After updating to the latest Home Assistant version, my Tuya BLE custom integration started throwing an import error on startup. Specifically, there is a failure importing CONF_ACCESS_ID from homeassistant.components.tuya.const.

Log details

Logger: homeassistant.setup
Source: setup.py:251
First occurred: 10:42:15 PM (1 occurrences)
Last logged: 10:42:15 PM

Setup failed for custom integration 'tuya_ble': Unable to import component: cannot import name 'CONF_ACCESS_ID' from 'homeassistant.components.tuya.const' (/usr/src/homeassistant/homeassistant/components/tuya/const.py)
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/setup.py", line 251, in _async_setup_component
    component = integration.get_component()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/src/homeassistant/homeassistant/loader.py", line 827, in get_component
    ComponentProtocol, importlib.import_module(self.pkg_path)
                       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/importlib/__init__.py", line 90, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
  File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 994, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/config/custom_components/tuya_ble/__init__.py", line 17, in <module>
    from .cloud import HASSTuyaBLEDeviceManager
  File "/config/custom_components/tuya_ble/cloud.py", line 18, in <module>
    from homeassistant.components.tuya.const import (
ImportError: cannot import name 'CONF_ACCESS_ID' from 'homeassistant.components.tuya.const' (/usr/src/homeassistant/homeassistant/components/tuya/const.py)

About this issue

  • Original URL
  • State: closed
  • Created 5 months ago
  • Reactions: 7
  • Comments: 40

Commits related to this issue

Most upvoted comments

Thank you everyone, especially @ppcsite & @Chreece , your suggestions revived my Fingerbot back from the dead!

For Anyone curious what’s the fix, this it it:

  1. edit const.py by adding those
CONF_AUTH_TYPE = "auth_type"
CONF_PROJECT_TYPE = "tuya_project_type"
CONF_ENDPOINT = "endpoint"
CONF_ACCESS_ID = "access_id"
CONF_ACCESS_SECRET = "access_secret"
SMARTLIFE_APP = "smartlife"
TUYA_SMART_APP = "tuyaSmart"

  1. edit config_flow.py by making sure those sections look like as follow
from homeassistant.const import (
    CONF_ADDRESS,
    CONF_COUNTRY_CODE,
    CONF_PASSWORD,
    CONF_USERNAME,
)
from homeassistant.components.tuya.const import (
    CONF_APP_TYPE,
    CONF_ENDPOINT,
    TUYA_RESPONSE_CODE,
    TUYA_RESPONSE_MSG,
    TUYA_RESPONSE_SUCCESS,
)
from .const import (
    DOMAIN,
    CONF_ACCESS_ID,
    CONF_ACCESS_SECRET,
    CONF_AUTH_TYPE,
    SMARTLIFE_APP,
    TUYA_SMART_APP,
)

  1. edit cloud.py sections below to look the same
from homeassistant.const import (
    CONF_ADDRESS,
    CONF_COUNTRY_CODE,
    CONF_DEVICE_ID,
    CONF_PASSWORD,
    CONF_USERNAME,
)
from homeassistant.components.tuya.const import (
    CONF_APP_TYPE,
    CONF_ENDPOINT,
    DOMAIN as TUYA_DOMAIN,
    TUYA_RESPONSE_RESULT,
    TUYA_RESPONSE_SUCCESS,
)
from .const import (
    CONF_PRODUCT_MODEL,
    CONF_UUID,
    CONF_LOCAL_KEY,
    CONF_CATEGORY,
    CONF_PRODUCT_ID,
    CONF_DEVICE_NAME,
    CONF_PRODUCT_NAME,
    DOMAIN,
    TUYA_API_DEVICES_URL,
    TUYA_API_FACTORY_INFO_URL,
    TUYA_FACTORY_INFO_MAC,
    TUYA_API_DEVICES_URL,
    TUYA_API_FACTORY_INFO_URL,
    TUYA_FACTORY_INFO_MAC,
    CONF_ACCESS_ID,
    CONF_ACCESS_SECRET,
    CONF_AUTH_TYPE,
    SMARTLIFE_APP,
)

Thank you everyone, especially @ppcsite & @Chreece , your suggestions revived my Fingerbot back from the dead!

For Anyone curious what’s the fix, this it it:

  1. edit const.py by adding those
CONF_AUTH_TYPE = "auth_type"
CONF_PROJECT_TYPE = "tuya_project_type"
CONF_ENDPOINT = "endpoint"
CONF_ACCESS_ID = "access_id"
CONF_ACCESS_SECRET = "access_secret"
SMARTLIFE_APP = "smartlife"
TUYA_SMART_APP = "tuyaSmart"
  1. edit config_flow.py by making sure those sections look like as follow
from homeassistant.const import (
    CONF_ADDRESS,
    CONF_COUNTRY_CODE,
    CONF_PASSWORD,
    CONF_USERNAME,
)
from homeassistant.components.tuya.const import (
    CONF_APP_TYPE,
    CONF_ENDPOINT,
    TUYA_RESPONSE_CODE,
    TUYA_RESPONSE_MSG,
    TUYA_RESPONSE_SUCCESS,
)
from .const import (
    DOMAIN,
    CONF_ACCESS_ID,
    CONF_ACCESS_SECRET,
    CONF_AUTH_TYPE,
    SMARTLIFE_APP,
    TUYA_SMART_APP,
)
  1. edit cloud.py sections below to look the same
from homeassistant.const import (
    CONF_ADDRESS,
    CONF_COUNTRY_CODE,
    CONF_DEVICE_ID,
    CONF_PASSWORD,
    CONF_USERNAME,
)
from homeassistant.components.tuya.const import (
    CONF_APP_TYPE,
    CONF_ENDPOINT,
    DOMAIN as TUYA_DOMAIN,
    TUYA_RESPONSE_RESULT,
    TUYA_RESPONSE_SUCCESS,
)
from .const import (
    CONF_PRODUCT_MODEL,
    CONF_UUID,
    CONF_LOCAL_KEY,
    CONF_CATEGORY,
    CONF_PRODUCT_ID,
    CONF_DEVICE_NAME,
    CONF_PRODUCT_NAME,
    DOMAIN,
    TUYA_API_DEVICES_URL,
    TUYA_API_FACTORY_INFO_URL,
    TUYA_FACTORY_INFO_MAC,
    TUYA_API_DEVICES_URL,
    TUYA_API_FACTORY_INFO_URL,
    TUYA_FACTORY_INFO_MAC,
    CONF_ACCESS_ID,
    CONF_ACCESS_SECRET,
    CONF_AUTH_TYPE,
    SMARTLIFE_APP,
)

Fixed it for me. You’re amazing!

Fantastic work. I have problem as follows: when installing I get: Error Config flow could not be loaded: 500 Internal Server Error Server got itself in trouble

logs: This error originated from a custom integration.

Logger: homeassistant Source: custom_components/tuya_ble/config_flow.py:134 Integration: Tuya BLE First occurred: 10:39:53 (1 occurrences) Last logged: 10:39:53

Error doing job: Task exception was never retrieved Traceback (most recent call last): File “/usr/src/homeassistant/homeassistant/helpers/discovery_flow.py”, line 96, in async_start await gather_with_limited_concurrency( File "/usr/src/homeassistant/homeassistant/util/async.py", line 188, in gather_with_limited_concurrency return await gather( ^^^^^^^^^^^^^ File “/usr/src/homeassistant/homeassistant/util/async_.py”, line 186, in sem_task return await task ^^^^^^^^^^ File “/usr/src/homeassistant/homeassistant/config_entries.py”, line 945, in async_init flow, result = await task ^^^^^^^^^^ File “/usr/src/homeassistant/homeassistant/config_entries.py”, line 973, in _async_init result = await self._async_handle_step(flow, flow.init_step, data) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “/usr/src/homeassistant/homeassistant/data_entry_flow.py”, line 501, in _async_handle_step result: FlowResult = await getattr(flow, method)(user_input) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “/config/custom_components/tuya_ble/config_flow.py”, line 239, in async_step_bluetooth return await self.async_step_login() ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “/config/custom_components/tuya_ble/config_flow.py”, line 282, in async_step_login return _show_login_form(self, user_input, errors, placeholders) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File “/config/custom_components/tuya_ble/config_flow.py”, line 134, in _show_login_form [country.name for country in TUYA_COUNTRIES] ^^^^^^^^^^^^^^ NameError: name ‘TUYA_COUNTRIES’ is not defined

I was able to fix mine, you can take a look here: #112 (comment)

Good work, I still have problem installing with message: Config flow could not be loaded: {"message":"Invalid handler specified"}

and logs:

`Logger: homeassistant.config_entries Source: config_entries.py:2247 First occurred: 05:03:10 (9 occurrences) Last logged: 09:42:50

Error occurred loading flow for integration tuya_ble: cannot import name ‘CONF_ACCESS_ID’ from ‘homeassistant.components.tuya.const’ (/usr/src/homeassistant/homeassistant/components/tuya/const.py) Error occurred loading flow for integration tuya_ble: cannot import name ‘CONF_COUNTRY_CODE’ from ‘homeassistant.components.tuya.const’ (/usr/src/homeassistant/homeassistant/components/tuya/const.py)`

That’s what I’m using. Any other version just errors with invalid config flow

Has anyone else been getting no unconfigured devices found ?

“/config/custom_components/tuya_ble/config_flow.py”, line 134, in _show_login_form [country.name for country in TUYA_COUNTRIES] ^^^^^^^^^^^^^^ NameError: name ‘TUYA_COUNTRIES’ is not defined

recheck your changes, you haven’t done everything as it should… TUYA_COUNTRIES shouldn’t exist

Changes checked, but TUYA_COUNTRIES exists in config flow later in code I think.

Yep, I have it in 3 places. Maybe someone can post a link to the full file contents for the 3 mentioned above? Copy and replace the entire shebang.

I have overcome this by removing integration and downloading it completely from: GITHUB REPO, It must have been other changes to other files previously.