diff --git a/homeassistant/components/hue/light.py b/homeassistant/components/hue/light.py index c9d543dba94..c8d7de55ce8 100644 --- a/homeassistant/components/hue/light.py +++ b/homeassistant/components/hue/light.py @@ -296,18 +296,29 @@ class HueLight(LightEntity): @property def min_mireds(self): """Return the coldest color_temp that this light supports.""" - if self.is_group or "ct" not in self.light.controlcapabilities: + if self.is_group: return super().min_mireds - return self.light.controlcapabilities["ct"]["min"] + min_mireds = self.light.controlcapabilities.get("ct", {}).get("min") + + # We filter out '0' too, which can be incorrectly reported by 3rd party buls + if not min_mireds: + return super().min_mireds + + return min_mireds @property def max_mireds(self): """Return the warmest color_temp that this light supports.""" - if self.is_group or "ct" not in self.light.controlcapabilities: + if self.is_group: return super().max_mireds - return self.light.controlcapabilities["ct"]["max"] + max_mireds = self.light.controlcapabilities.get("ct", {}).get("max") + + if not max_mireds: + return super().max_mireds + + return max_mireds @property def is_on(self): diff --git a/tests/util/test_color.py b/tests/util/test_color.py index 99ebcd72554..8f520f4a7ec 100644 --- a/tests/util/test_color.py +++ b/tests/util/test_color.py @@ -288,28 +288,20 @@ def test_gamut(): assert not color_util.check_valid_gamut(GAMUT_INVALID_4) -def test_should_return_25000_kelvin_when_input_is_40_mired(): - """Function should return 25000K if given 40 mired.""" - kelvin = color_util.color_temperature_mired_to_kelvin(40) - assert kelvin == 25000 +def test_color_temperature_mired_to_kelvin(): + """Test color_temperature_mired_to_kelvin.""" + assert color_util.color_temperature_mired_to_kelvin(40) == 25000 + assert color_util.color_temperature_mired_to_kelvin(200) == 5000 + with pytest.raises(ZeroDivisionError): + assert color_util.color_temperature_mired_to_kelvin(0) -def test_should_return_5000_kelvin_when_input_is_200_mired(): - """Function should return 5000K if given 200 mired.""" - kelvin = color_util.color_temperature_mired_to_kelvin(200) - assert kelvin == 5000 - - -def test_should_return_40_mired_when_input_is_25000_kelvin(): - """Function should return 40 mired when given 25000 Kelvin.""" - mired = color_util.color_temperature_kelvin_to_mired(25000) - assert mired == 40 - - -def test_should_return_200_mired_when_input_is_5000_kelvin(): - """Function should return 200 mired when given 5000 Kelvin.""" - mired = color_util.color_temperature_kelvin_to_mired(5000) - assert mired == 200 +def test_color_temperature_kelvin_to_mired(): + """Test color_temperature_kelvin_to_mired.""" + assert color_util.color_temperature_kelvin_to_mired(25000) == 40 + assert color_util.color_temperature_kelvin_to_mired(5000) == 200 + with pytest.raises(ZeroDivisionError): + assert color_util.color_temperature_kelvin_to_mired(0) def test_returns_same_value_for_any_two_temperatures_below_1000():