home-assistant / core

:house_with_garden: Open source home automation that puts local control and privacy first.
https://www.home-assistant.io
Apache License 2.0
73.56k stars 30.73k forks source link

0.73.0 - light.tplink - division by zero #15339

Closed ctalkington closed 6 years ago

ctalkington commented 6 years ago

Home Assistant release with the issue:

0.73.0

Last working Home Assistant release (if known): 0.72.1

Operating environment (Hass.io/Docker/Windows/etc.):

Docker / RPI3B

Component/platform:

light.tplink

Description of problem: LB100 causes division by zero error with kelvin temperature conversion. seems #15020 could be the culprit

Problem-relevant configuration.yaml entries and (fill out even if it seems unimportant):

light:
  - platform: tplink
    host: 192.168.1.111

Traceback (if applicable):

homeassistant.core] Error doing job: Task exception was never retrieved
Traceback (most recent call last):
  File "/usr/lib/python3.6/site-packages/homeassistant/helpers/entity.py", line 214, in async_update_ha_state
    attr = self.state_attributes or {}
  File "/usr/lib/python3.6/site-packages/homeassistant/components/light/__init__.py", line 504, in state_attributes
    value = getattr(self, prop)
  File "/usr/lib/python3.6/site-packages/homeassistant/components/light/tplink.py", line 110, in min_mireds
    return kelvin_to_mired(self.smartbulb.valid_temperature_range[1])
  File "/usr/lib/python3.6/site-packages/homeassistant/util/color.py", line 474, in color_temperature_kelvin_to_mired
    return math.floor(1000000 / kelvin_temperature)
ZeroDivisionError: division by zero

Additional information:

rytilahti commented 6 years ago

Hmm, LB100 does not support temperature changing, so the backend library reports 0 as min & max kelvin. The fix would be to check for that and return whatever is the default return for those methods.

amelchio commented 6 years ago

Probably return None for min_mireds with that bulb?

clickityclickclickclick commented 6 years ago

This was the fix for me. Edit color.py

From:

def color_temperature_kelvin_to_mired(kelvin_temperature):
    """Convert degrees kelvin to mired shift."""
    return math.floor(1000000 / kelvin_temperature)

To:

def color_temperature_kelvin_to_mired(kelvin_temperature):
    """Convert degrees kelvin to mired shift."""
    if kelvin_temperature != None and kelvin_temperature != 0:
      return math.floor(1000000 / kelvin_temperature)
ntompson commented 6 years ago

Same problem here - LB110 doesn't have colour control, so now they are broken in the GUI. Still seem to work in automations, but it would be good to see this fixed. Is there an ETA?

I am using hassio, so hard to fix the source.

rytilahti commented 6 years ago

I'm wondering if the get_features() should already be called in setup_platform()? That way min_mireds and max_mireds should never be accessed and this issue would be solved without other changes. Anyone mind testing if that'd do the trick?

Segfault198 commented 6 years ago

Its interesting to see this issue reappear. It used to occur way back in the early days of the tplink platform. Strange to see it resurface now. Was working fine for me until 0.73.1. For now I'll go back to altering color.py as I did in the old (lol maybe a year ago) days.

tchellomello commented 6 years ago

I had the same issue and the implemented something similar as comment 6 https://github.com/home-assistant/home-assistant/issues/15339#issuecomment-405041884

amelchio commented 6 years ago

If you are going for a local change, please test #15484 since that is what we expect will fix this issue.

ctalkington commented 6 years ago

seems resolved in 0.74.0

amelchio commented 6 years ago

It seems that @rytilahti managed to fix it with #15571 👍