tplink bulb consecutively dims brightness at each color change #15582
Description
Home Assistant release with the issue:
0.74.0
Last working Home Assistant release (if known):
unknown
Operating environment (Hass.io/Docker/Windows/etc.):
Raspbian GNU/Linux 9 (stretch), installation of homeassistant via pip (Python 3.5.3)
Component/platform:
issue with the tplink
light component: https://www.home-assistant.io/components/light.tplink/
Description of problem:
Tested device: TP-Link Bulb TP130.
Every time the color of the bulb is changed from the Home Assistant Interface, the bulb brightness is reduced (in addition to the successful change of color). For example, starting from 100% brightness, switching to a different color results in the brightness being reduced to 39%. Changing color again, yields 15% brightness, etc... (see my remarks about these specific numbers at the end of this issue).
Problem-relevant configuration.yaml
entries and (fill out even if it seems unimportant):
light:
- platform: tplink
name: SmartBulb
host: !secret smart_bulb_ip
Traceback (if applicable):
Additional information:
My best guess for the cause of this problem is the following: The brightness can be given in percent or values between 1 and 255. Internally, only one of those two options (i.e, percent values) is used, if I read the source code correctly. Now, if at some point, one assumes the brightness to be in the wrong format and does the conversion, the brightness will be updated to wrong values. In the case of the brightness actually being in percent, but assumed as values between 1 and 255, this would result in brightness reductions to values of 100/255=39%, 39/255=15%, etc... - which is exactly the steps in brightness reduction I observe.
Is it possible that the following lines cause this problem by assuming the brightness values to be in absolute 1..255 values (whereas they actually are in percent already)? https://github.com/home-assistant/home-assistant/blob/7bc2362e33f86d41769d753d1701a53ae60224d5/homeassistant/components/light/tplink.py#L96-L97
Thanks, and keep up the excellent work!