PaulAnnekov / tuyaha

Implements the special Tuya Home Assistant API.
Other
142 stars 106 forks source link

Add checking for color in data to avoid exceptions #13

Closed airens closed 4 years ago

airens commented 4 years ago

For some devices Tuya servers can reply no "color" section in response data for "colour" mode which lead to exceptions in "brightness" function. Example data:

{
"payload": {"data": {"brightness": "255",
    "color_mode": "colour",
    "online": true,
    "state": "true"}},
  "header": {"code": "SUCCESS", "payloadVersion": 1}
}
PaulAnnekov commented 4 years ago

Nice job! ;)

majorsl commented 4 years ago

I tried this change in my HA and, while it does restore functionality to my lights, any of my bulbs with cards have lost the color wheel and have the brightness slider only now.

Setting the color in automations will still work it seems, but you lose the ability to do it "manually" and on the fly for bulbs/groups of bulbs.

airens commented 4 years ago

I tried this change in my HA and, while it does restore functionality to my lights, any of my bulbs with cards have lost the color wheel and have the brightness slider only now.

Setting the color in automations will still work it seems, but you lose the ability to do it "manually" and on the fly for bulbs/groups of bulbs.

Yeah, I actually had to change Tuya component a little bit to make such lights work. Changes are:

supports = SUPPORT_BRIGHTNESS

in light.py to

supports = SUPPORT_BRIGHTNESS | SUPPORT_COLOR

You can also do it. Create tuya folder in custom_components and clone official Tuya component there. Apply changes, that I described, and set tuyaha==0.0.5 in manifest.json. Keep in mind, that It'll forcelly allow Home assistant to control color for ALL Tuya lights

P.S> It's just workaround, unfortunately, and it can't be implemented in official component

majorsl commented 4 years ago

Thanks, that's what I'll probably do since all my lights are color capable. Does a custom_component override a built in component of the same name? I've done customs, but none that duplicate existing official ones.

Strange they changed it yet other services like Alexa still understand the differences. Makes me wonder if the API for the color attribute got moved/renamed and not removed.

Thanks for your work on this!

airens commented 4 years ago

Thanks, that's what I'll probably do since all my lights are color capable. Does a custom_component override a built in component of the same name? I've done customs, but none that duplicate existing official ones.

Strange they changed it yet other services like Alexa still understand the differences. Makes me wonder if the API for the color attribute got moved/renamed and not removed.

Thanks for your work on this!

As far as I know, custom_components has higher priority. Just try