Avoid divide by zero errors in tplink light integration#48235
Avoid divide by zero errors in tplink light integration#48235frenck merged 1 commit intohome-assistant:devfrom
Conversation
rytilahti
left a comment
There was a problem hiding this comment.
A couple of comments. I'm wondering if it would make sense to copy over the definitions from python-kasa to this file, and handle the detection here?
That being said, having the fallback values is still better than crashing when an unknown range is reported by pyhs100.
d0528fe to
62b7506
Compare
I hadn't actually considered moving the definitions over. That's a great idea. I've brought them over and added the fallback check in case it's another unknown bulb. |
62b7506 to
9b85b6d
Compare
rytilahti
left a comment
There was a problem hiding this comment.
There used to be this sort of mapping (iirc) which was moved to the backend lib which is the proper place for it. Considering the state of affairs, I think it makes sense rather to reintroduce this mapping inside homeassistant instead of doing a new pyhs100 maintenance release for new devices that were not available when pyhs100 got abandoned.
So 👍 after the changes I mentioned in the comments.
a0f54f2 to
9276630
Compare
|
I'm not really sure what is wrong with the new test I added causing CI problems. They seem to work for me locally.. any ideas? |
|
Let me know if you need me to squash them or you will, but it looks like CI and codecov is working now. |
rytilahti
left a comment
There was a problem hiding this comment.
LGTM, what do you think @TheGardenMonkey?
Some bulbs such as kl125 don't have a definition submitted into
pyHS100. Trying to interact with them will cause a divide by
zero error:
```
File "/usr/src/homeassistant/homeassistant/components/tplink/light.py", line 248, in attempt_update
self._light_features = self._get_light_features()
File "/usr/src/homeassistant/homeassistant/components/tplink/light.py", line 289, in _get_light_features
min_mireds = kelvin_to_mired(min_range)
File "/usr/src/homeassistant/homeassistant/util/color.py", line 515, in color_temperature_kelvin_to_mired
return math.floor(1000000 / kelvin_temperature)
ZeroDivisionError: division by zero
```
As the `pyHS100` project has been abandoned in favor of `python-kasa` but there isn't yet
a component in home assistant for using `python-kasa` move the bulb definitions into this file and
add some fallback code into the component.
If the light specifies it supports color temperature but the range isn't available choose a "safe"
range that is the minimum of what is available in bulbs today.
7a252af to
4c7ae8c
Compare
FYI squashed it and force pushed, and also added a linked documentation update for this change. |
|
This makes sense to me as well. |
|
Anything else needed to merge this? |
|
Thanks, @superm1 👍 |
Proposed change
Some bulbs such as kl125 don't have a definition submitted into
pyHS100. Trying to interact with them will cause a divide by
zero error:
As the
pyHS100project has been abandoned in favor ofpython-kasabut there isn't yeta component in home assistant for using
python-kasaadd some fallback code into the component.If the light specifies it supports color temperature but the range isn't available choose a "safe"
range that is the minimum of what is available in bulbs today.
Type of change
Example entry for
configuration.yaml:Additional information
Checklist
black --fast homeassistant tests)If user exposed functionality or configuration variables are added/changed:
If the code communicates with devices, web services, or third-party tools:
Updated and included derived files by running:
python3 -m script.hassfest.requirements_all.txt.Updated by running
python3 -m script.gen_requirements_all..coveragerc.The integration reached or maintains the following Integration Quality Scale:
To help with the load of incoming pull requests: