Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tuya_light: fix float->int conversion while setting color temperature #5067

Merged
merged 3 commits into from Jul 12, 2023

Conversation

kswt
Copy link
Contributor

@kswt kswt commented Jul 6, 2023

What does this implement/fix?

This PR fixes the conversion of the color temperature (CT) value between the components light and tuya_light. Light uses float datatype, but tuya_light uses int. In order to send to Tuya device exactly the same value that was read from it before, converted value must be rounded instead of simple int casting.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Other

Related issue or feature (if applicable): fixes esphome/issues#4669

Test Environment

  • ESP32
  • ESP32 IDF
  • ESP8266
  • RP2040

Example entry for config.yaml:

esp8266:
  board: nodemcuv2

logger:
  baud_rate: 0

uart:
  rx_pin: GPIO3
  tx_pin: GPIO1
  baud_rate: 115200

# Register the Tuya MCU connection
tuya:

light:
  - platform: "tuya"
    name: "Remez Leda"
    switch_datapoint: 20
    dimmer_datapoint: 22
    max_value: 1000
    color_temperature_datapoint: 23
    color_temperature_max_value: 1000
    cold_white_color_temperature: 154 mireds
    warm_white_color_temperature: 333 mireds
    color_temperature_invert: true

Checklist:

  • The code change is tested and works locally.
  • Tests have been added to verify that the new code works (under tests/ folder).

kswt and others added 2 commits July 10, 2023 12:43
Co-authored-by: Jesse Hills <3060199+jesserockz@users.noreply.github.com>
@kswt kswt force-pushed the fix/tuya_color_temp_rounding branch from b8e337c to 4a65559 Compare July 10, 2023 09:43
@jesserockz jesserockz merged commit 6ecc1c1 into esphome:dev Jul 12, 2023
25 checks passed
@jesserockz jesserockz mentioned this pull request Jul 12, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Jul 14, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

tuya_light: getting color temperature from another MCU makes the device uncontrollable
2 participants