Repository: XKNX/xknx

Issue:
Exception within light when using current master "return math.floor(1000000 / kelvin_temperature)"
```
Traceback (most recent call last):
  File "/home/julius/home-assistant/homeassistant/helpers/entity_platform.py", line 128, in _async_setup_platform
    SLOW_SETUP_MAX_WAIT, loop=hass.loop)
  File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
    return fut.result()
  File "/home/julius/home-assistant/homeassistant/components/knx/light.py", line 69, in async_setup_platform
    async_add_entities_discovery(hass, discovery_info, async_add_entities)
  File "/home/julius/home-assistant/homeassistant/components/knx/light.py", line 80, in async_add_entities_discovery
    entities.append(KNXLight(device))
  File "/home/julius/home-assistant/homeassistant/components/knx/light.py", line 132, in __init__
    color_util.color_temperature_kelvin_to_mired(self._max_kelvin)
  File "/home/julius/home-assistant/homeassistant/util/color.py", line 516, in color_temperature_kelvin_to_mired
    return math.floor(1000000 / kelvin_temperature)
TypeError: unsupported operand type(s) for /: 'int' and 'NoneType'
```

Discussion:

Patch:
diff --git a/xknx/devices/light.py b/xknx/devices/light.py
index 669a6190..541ecac3 100644
--- a/xknx/devices/light.py
+++ b/xknx/devices/light.py
@@ -21,6 +21,8 @@ class Light(Device):
     """Class for managing a light."""
 
     # pylint: disable=too-many-locals
+    DEFAULT_MIN_KELVIN = 2700  # 370 mireds
+    DEFAULT_MAX_KELVIN = 6000  # 166 mireds
 
     def __init__(self,
                  xknx,
@@ -128,9 +130,9 @@ class Light(Device):
         group_address_color_temperature_state = \
             config.get('group_address_color_temperature_state')
         min_kelvin = \
-            config.get('min_kelvin')
+            config.get('min_kelvin', Light.DEFAULT_MIN_KELVIN)
         max_kelvin = \
-            config.get('max_kelvin')
+            config.get('max_kelvin', Light.DEFAULT_MAX_KELVIN)
 
         return cls(xknx,
                    name,


Test patch:
diff --git a/test/config_test.py b/test/config_test.py
index d6eae150..6674b1d1 100644
--- a/test/config_test.py
+++ b/test/config_test.py
@@ -88,6 +88,8 @@ class TestConfig(unittest.TestCase):
             Light(TestConfig.xknx,
                   'Living-Room.Light_1',
                   group_address_switch='1/6/9',
+                  min_kelvin=2700,
+                  max_kelvin=6000,
                   device_updated_cb=TestConfig.xknx.devices.device_updated))
 
     def test_config_light_state(self):
@@ -100,6 +102,8 @@ class TestConfig(unittest.TestCase):
                   group_address_switch_state='1/7/5',
                   group_address_brightness='1/7/6',
                   group_address_brightness_state='1/7/7',
+                  min_kelvin=2700,
+                  max_kelvin=6000,
                   device_updated_cb=TestConfig.xknx.devices.device_updated))
 
     def test_config_light_color(self):
@@ -112,6 +116,8 @@ class TestConfig(unittest.TestCase):
                   group_address_brightness='1/6/6',
                   group_address_color='1/6/7',
                   group_address_color_state='1/6/8',
+                  min_kelvin=2700,
+                  max_kelvin=6000,
                   device_updated_cb=TestConfig.xknx.devices.device_updated))
 
     def test_config_color_temperature(self):
@@ -126,6 +132,8 @@ class TestConfig(unittest.TestCase):
                   group_address_brightness_state='1/6/13',
                   group_address_color_temperature='1/6/14',
                   group_address_color_temperature_state='1/6/15',
+                  min_kelvin=2700,
+                  max_kelvin=6000,
                   device_updated_cb=TestConfig.xknx.devices.device_updated))
 
     def test_config_tunable_white(self):
@@ -140,6 +148,8 @@ class TestConfig(unittest.TestCase):
                   group_address_brightness_state='1/6/23',
                   group_address_tunable_white='1/6/24',
                   group_address_tunable_white_state='1/6/25',
+                  min_kelvin=2700,
+                  max_kelvin=6000,
                   device_updated_cb=TestConfig.xknx.devices.device_updated))
 
     def test_config_switch(self):