rospogrigio / localtuya

local handling for Tuya devices
GNU General Public License v3.0
2.95k stars 562 forks source link

Setting LED strip to the middle (White) on the colour wheel, breaks the device and makes it Unavailable. #1281

Closed rainyskye closed 1 year ago

rainyskye commented 1 year ago

The problem

Setting the colour of the LED Strip to white, causes an error and is unavailable until the device has it's colour changed from the Tuya app

Environment

Steps to reproduce

  1. Open Device in Home Assistant
  2. Click/Tap in middle of colour wheel
  3. "Unknown format code 'x' for object of type 'str'" will appear in the bottom left corner.

DP dump (Taken when in "invalid/broken" state)

DPS [20] VALUE [True] 
DPS [21] VALUE [white] 
DPS [24] VALUE [013b03e803e8] 
DPS [25] VALUE [07464602000003e803e800000000464602007803e803e80000000046460200f003e803e800000000464602003d03e803e80000000046460200ae03e803e800000000464602011303e803e800000000] 
DPS [26] VALUE [0]

Provide Home Assistant traceback/logs

When attempting to set to white

[139664993592720] Unknown format code 'x' for object of type 'str'
[139664805635664] Unknown format code 'x' for object of type 'str'
Traceback (most recent call last):
  File "/usr/src/homeassistant/homeassistant/components/websocket_api/commands.py", line 200, in handle_call_service
    await hass.services.async_call(
  File "/usr/src/homeassistant/homeassistant/core.py", line 1787, in async_call
    task.result()
  File "/usr/src/homeassistant/homeassistant/core.py", line 1824, in _execute_service
    await cast(Callable[[ServiceCall], Awaitable[None]], handler.job.target)(
  File "/usr/src/homeassistant/homeassistant/helpers/entity_component.py", line 213, in handle_service
    await service.entity_service_call(
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 680, in entity_service_call
    future.result()  # pop exception if have
  File "/usr/src/homeassistant/homeassistant/helpers/entity.py", line 968, in async_request_call
    await coro
  File "/usr/src/homeassistant/homeassistant/helpers/service.py", line 720, in _handle_entity_call
    await result
  File "/usr/src/homeassistant/homeassistant/components/light/__init__.py", line 571, in async_handle_light_on_service
    await light.async_turn_on(**filter_turn_on_params(light, params))
  File "/config/custom_components/localtuya/light.py", line 371, in async_turn_on
    color = "{:04x}{:04x}{:04x}".format(
ValueError: Unknown format code 'x' for object of type 'str'

When attempting to change colour back

[bf5...33c] Failed to set DPs {24: '004b01ad03e8', 21: 'colour'}
[bf5...33c] Failed to set DPs {24: '0078023b03e8', 21: 'colour'}
[bf5...33c] Failed to set DPs {24: '013b03e803e8', 21: 'colour'}
[bf5...33c] Failed to set DPs {24: '00f002ca03e8', 21: 'colour'}
[bf5...33c] Failed to set DPs {24: '012c02ca03e8', 21: 'colour'}
Traceback (most recent call last):
  File "/usr/local/lib/python3.10/asyncio/locks.py", line 390, 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.10/asyncio/tasks.py", line 456, in wait_for
    return 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 334, in set_dps
    await self._interface.set_dps(states)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 840, in set_dps
    return await self.exchange(CONTROL, dps)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 763, in exchange
    msg = await self.dispatcher.wait_for(seqno, payload.cmd)
  File "/config/custom_components/localtuya/pytuya/__init__.py", line 450, in wait_for
    await asyncio.wait_for(self.listeners[seqno].acquire(), timeout=timeout)
  File "/usr/local/lib/python3.10/asyncio/tasks.py", line 458, in wait_for
    raise exceptions.TimeoutError() from exc
asyncio.exceptions.TimeoutError

Additional information

Changing the colour back manually from the Tuya App actually makes it usable again, I'm not sure if it's to do with my janky setup of the DP values or what, but I'd say it somehow is trying to set the light from colour to white, which is an invalid state for the device?

rainyskye commented 1 year ago

Sometimes when clicking the middle of the colour wheel will not only make the device unavailable, but also turn off the LED strip

rainyskye commented 1 year ago

Okay, I might have dingused it somehow, it's working without defining any "white" options


Brightness (only for white color) = *unfilled*
Color Temperature = *unfilled*
Brightness Lower Value = 10
Brightness Upper Value = 1000
Color Mode = <21>
Color = <24>
Scene = <25>