Core-2022.4.0 upgrade & LocalTuya Issues

Am I the only one experiencing issues with LocaTuya when upgrading to core-2022.4.0?

image

Logger: homeassistant.setup
Source: setup.py:162
First occurred: 1:25:36 PM (1 occurrences)
Last logged: 1:25:36 PM

Setup failed for custom integration localtuya: Unable to import component: cannot import name 'SPEED_HIGH' from 'homeassistant.components.fan' (/usr/src/homeassistant/homeassistant/components/fan/__init__.py)

and

This error originated from a custom integration.

Logger: aiohttp.server
Source: custom_components/localtuya/fan.py:6
Integration: LocalTuya (documentation, issues)
First occurred: 1:46:50 PM (2 occurrences)
Last logged: 1:48:00 PM

Error handling request
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_protocol.py", line 435, in _handle_request
    resp = await request_handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_app.py", line 504, in _handle
    resp = await handler(request)
  File "/usr/local/lib/python3.9/site-packages/aiohttp/web_middlewares.py", line 117, in impl
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/security_filter.py", line 60, in security_filter_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/forwarded.py", line 94, in forwarded_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/request_context.py", line 28, in request_context_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/ban.py", line 79, in ban_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/auth.py", line 219, in auth_middleware
    return await handler(request)
  File "/usr/src/homeassistant/homeassistant/components/http/view.py", line 137, in handle
    result = await result
  File "/usr/src/homeassistant/homeassistant/components/config/config_entries.py", line 267, in post
    return await super().post(request, flow_id)
  File "/usr/src/homeassistant/homeassistant/components/http/data_validator.py", line 62, in wrapper
    result = await method(view, request, *args, **kwargs)
  File "/usr/src/homeassistant/homeassistant/helpers/data_entry_flow.py", line 110, in post
    result = await self._flow_mgr.async_configure(flow_id, data)
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 260, in async_configure
    result = await self._async_handle_step(
  File "/usr/src/homeassistant/homeassistant/data_entry_flow.py", line 335, in _async_handle_step
    result: FlowResult = await getattr(flow, method)(user_input)
  File "/config/custom_components/localtuya/config_flow.py", line 407, in async_step_init
    return await self.async_step_entity()
  File "/config/custom_components/localtuya/config_flow.py", line 438, in async_step_entity
    schema = platform_schema(
  File "/config/custom_components/localtuya/config_flow.py", line 139, in platform_schema
    return vol.Schema(schema).extend(flow_schema(platform, dps_strings))
  File "/config/custom_components/localtuya/config_flow.py", line 145, in flow_schema
    return import_module("." + platform, integration_module).flow_schema(dps_strings)
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 972, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/config/custom_components/localtuya/__init__.py", line 90, in <module>
    CONFIG_SCHEMA = config_schema()
  File "/config/custom_components/localtuya/config_flow.py", line 161, in config_schema
    entity_schemas = [
  File "/config/custom_components/localtuya/config_flow.py", line 162, in <listcomp>
    platform_schema(platform, range(1, 256), yaml=True) for platform in PLATFORMS
  File "/config/custom_components/localtuya/config_flow.py", line 139, in platform_schema
    return vol.Schema(schema).extend(flow_schema(platform, dps_strings))
  File "/config/custom_components/localtuya/config_flow.py", line 145, in flow_schema
    return import_module("." + platform, integration_module).flow_schema(dps_strings)
  File "/usr/local/lib/python3.9/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1030, in _gcd_import
  File "<frozen importlib._bootstrap>", line 1007, in _find_and_load
  File "<frozen importlib._bootstrap>", line 986, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 680, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 850, in exec_module
  File "<frozen importlib._bootstrap>", line 228, in _call_with_frames_removed
  File "/config/custom_components/localtuya/fan.py", line 6, in <module>
    from homeassistant.components.fan import (
ImportError: cannot import name 'SPEED_HIGH' from 'homeassistant.components.fan' (/usr/src/homeassistant/homeassistant/components/fan/__init__.py)

7 Likes

Maybe i would be appropriate to mention, initially, which type of HA installation you are running , i havent upgraded to 2022.4 yet, thou i doubt, i will get same issue, as i i.e. have no Fan controlled yet, through Local_Tuya

Maybe i would be appropriate to mention, initially, which type of HA installation you are running

Good call. Here’s the details:

  • Frontend version: 20220301.2 - latest
  • Home Assistant OS 7.6
  • Core-2022.4.0

Here’s the total HA Info page

Additionally, I also noticed those fan references, but I don’t have a fan in my configuration, so my guess would be that fan is simply some sort of code/script name instead of a true fan.

LOL , i was thinking about it after i posted …i’ve actually seen HA/Local_Tuya loading this at startup( as i think were support for Fan’s) … ok, i guess i have to keep an eye on this, thou maybe i should wait until tommorow, to hit the “upgrade” button … i’ll keep you posted :slight_smile:

1 Like

I don’t think so. I’m seeing this in my log

This error originated from a custom integration.

Logger: custom_components.localtuya.common
Source: custom_components/localtuya/pytuya/__init__.py:247
Integration: LocalTuya (documentation, issues) 
First occurred: 3:19:46 PM (3 occurrences) 
Last logged: 4:08:34 PM

[833...50c] Failed to set DP 1 to 1
[833...50c] Failed to set DP 1 to 0
Traceback (most recent call last):
  File "/usr/local/lib/python3.9/asyncio/locks.py", line 413, in acquire
    await fut
asyncio.exceptions.CancelledError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 492, in wait_for
    fut.result()
asyncio.exceptions.CancelledError

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/config/custom_components/localtuya/common.py", line 209, in set_dp
    await self._interface.set_dp(state, dp_index)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 518, in set_dp
    return await self.exchange(SET, {str(dp_index): value})
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 460, in exchange
    msg = await self.dispatcher.wait_for(seqno)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 247, in wait_for
    await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)
  File "/usr/local/lib/python3.9/asyncio/tasks.py", line 494, in wait_for
    raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

And none of my devices will function

1 Like

For once it’s not me; there’s been an issue ticket opened in github. And seeing the notes, looks to be a fix (or workaround). localtuya not working in HA 2022.4 · Issue #789 · rospogrigio/localtuya · GitHub. Worked for me:

In custom_components/localtuya/const.py line 49
change:

# Platforms in this list must support config flows
PLATFORMS = ["binary_sensor", "cover", "fan", "light", "sensor", "switch"]

to:

# Platforms in this list must support config flows
PLATFORMS = ["binary_sensor", "cover", "light", "sensor", "switch"]

marking this [SOLVED], but I’ll still keep up on the github issue and note if something different is decided to be the fix

5 Likes

Thank you for the solution !! :slight_smile:

1 Like

I’m seeing similar thing in the Gree plugin, Home Assistant core-2022.4.0 running from docker (linuxserver/homeassistant).

Is this something that should be fixed on the plugin side?

Platform error climate.gree - cannot import name 'SPEED_HIGH' from 'homeassistant.components.fan' (/usr/lib/python3.9/site-packages/homeassistant/components/fan/__init__.py)

2022-04-07 13:16:25 ERROR (MainThread) [homeassistant.components.homeassistant] The system cannot restart because the configuration is not valid: Platform error climate.gree - cannot import name 'SPEED_HIGH' from 'homeassistant.components.fan' (/usr/lib/python3.9/site-packages/homeassistant/components/fan/__init__.py)

2022-04-07 13:16:25 ERROR (MainThread) [homeassistant.components.websocket_api.http.connection] [140262602442496] The system cannot restart because the configuration is not valid: Platform error climate.gree - cannot import name 'SPEED_HIGH' from 'homeassistant.components.fan' (/usr/lib/python3.9/site-packages/homeassistant/components/fan/__init__.py)

Traceback (most recent call last):

File "/usr/lib/python3.9/site-packages/homeassistant/components/websocket_api/commands.py", line 193, in handle_call_service

await hass.services.async_call(

File "/usr/lib/python3.9/site-packages/homeassistant/core.py", line 1634, in async_call

task.result()

File "/usr/lib/python3.9/site-packages/homeassistant/core.py", line 1671, in _execute_service

await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(

File "/usr/lib/python3.9/site-packages/homeassistant/helpers/service.py", line 747, in admin_handler

await result

File "/usr/lib/python3.9/site-packages/homeassistant/components/homeassistant/__init__.py", line 173, in async_handle_core_service

raise HomeAssistantError(

homeassistant.exceptions.HomeAssistantError: The system cannot restart because the configuration is not valid: Platform error climate.gree - cannot import name 'SPEED_HIGH' from 'homeassistant.components.fan' (/usr/lib/python3.9/site-packages/homeassistant/components/fan/__init__.py)
1 Like

im first back now, i couldn’t wait with update, so i hit the button, yesterday :slight_smile: , and yes, obviously i got the same errors … but right after, my Fiber-connection went down, and i’ve been calling around all day, as it was still down in the morning, unbelievable … living in a top modern society and a fiber connection can be “down” for 16hours :frowning:
… thanks for the “Solution”, did read some about the “fan turning into light” at the Release note(or somewhere) … before my IP-Provider lost me “out in the sky” … thou id never thought it would affect people who didn’t had any Fan’s, pretty obscure, should have been handled by the “core” or integration,

1 Like

Me too same issue

I didn’t bump into the fan issue when updating to 2022.4.0 and local tuya 3.4.0. I’ve never had any fans though.

I did have a bit of an issue with a local tuya key versus a tuya v2 key however. I had to delete and reload one of my devices(kogan kettle) that was showing up unavailable.

It was previously using a local tuya key that I had acquired prior to setting up a a tuya iot account for tuya v2. I used to switch accounts. The device was working on 2022.3.8 and became unavailable in 2022.4.0. and required changing over to the key from the my tuya v2 account. I will possibly have to do that with some other devices that were created earlier than my v2 account, but would have to wake people up to check atm.

hope that helps someone.

edit: the device was also Offline in my tuya android app.