tuya / tuya-iot-python-sdk

Tuya IoT Python SDK for Tuya Open API.
MIT License
130 stars 49 forks source link

work_mode change can be lost if sent with brightness #43

Open pabigot opened 3 years ago

pabigot commented 3 years ago

As documented in home-assistant/core#58569, if an RGBCCT bulb is in work_mode colour, then sending a command that has switch_led, work_mode, and temp_value_v2 will correctly transition the bulb to color temperature mode at the requested brightness. I.e.:

{
  'switch_led': True,
  'work_mode': 'white',
  'temp_value_v2': 0,
  'bright_value_v2': 1000
}

will produce a response like:

{
  'switch_led': True,
  'work_mode': 'white',
  'bright_value_v2': 1000,
  'temp_value_v2': 0,
  'colour_data_v2': '{"h":30,"s":1000,"v":39}',
  'scene_data_v2': '{"scene_num":1,"scene_units"[{"bright":200,"h":0,"s":0,"temperature":0,"unit_change_mode":"static","unit_gradient_duration":13,"unit_switch_duration":14,"v":0}]}',
  'countdown_1': 0,
  'control_data': ''
}

However, a subsequent command that tries to change it back to colour with a different brightness:

{
  'switch_led': True,
  'work_mode': 'colour',
  'bright_value_v2': 49,
  'colour_data_v2': {"h": 20, "s": 1000, "v": 39},
}

will update the brightness and the colour_data, but not change work_mode, as demonstrated in the response:

{
  'switch_led': True,
  'work_mode': 'white',    <-- should have been updated to 'colour'
  'bright_value_v2': 49,
  'temp_value_v2': 0,
  'colour_data_v2': '{"h":20,"s":1000,"v":39}',
  'scene_data_v2': '{"scene_num":1,"scene_units":[{"bright":200,"h":0,"s":0,"temperature":0,"unit_change_mode":"static","unit_gradient_duration":13,"unit_switch_duration":14,"v":0}]}',
  'countdown_1': 0,
  'control_data': ''
}

The desired final state can only be achieved by sending two commands, one for the color setting, and one for brightness.

Reproduced in Home Assistant 2021.11.0b0 which is using tuya-iot-py-sdk 0.6.3.

frenck commented 3 years ago

You should report this @ Tuya itself, via the developer portal, not on the client library.

The client library cannot do anything about this.