From c78e8eb578846356fd629ae989c7d8fbcd754711 Mon Sep 17 00:00:00 2001 From: Maciej Bieniek Date: Sat, 28 Apr 2018 17:14:34 +0200 Subject: [PATCH] Add support for light sensors with 'lx' unit to HomeKit (#14131) * add support for light sensors with lx unit * add test for light sensor with 'lx' unit --- homeassistant/components/homekit/__init__.py | 2 +- tests/components/homekit/test_get_accessories.py | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/homeassistant/components/homekit/__init__.py b/homeassistant/components/homekit/__init__.py index 24c6dfa8a76..025ef4069e9 100644 --- a/homeassistant/components/homekit/__init__.py +++ b/homeassistant/components/homekit/__init__.py @@ -126,7 +126,7 @@ def get_accessory(hass, state, aid, config): or DEVICE_CLASS_CO2 in state.entity_id: a_type = 'CarbonDioxideSensor' elif device_class == DEVICE_CLASS_LIGHT or unit == 'lm' or \ - unit == 'lux': + unit == 'lux' or unit == 'lx': a_type = 'LightSensor' elif state.domain == 'switch' or state.domain == 'remote' \ diff --git a/tests/components/homekit/test_get_accessories.py b/tests/components/homekit/test_get_accessories.py index c26982e170b..76736ce45ad 100644 --- a/tests/components/homekit/test_get_accessories.py +++ b/tests/components/homekit/test_get_accessories.py @@ -125,6 +125,13 @@ class TestGetAccessories(unittest.TestCase): {ATTR_UNIT_OF_MEASUREMENT: 'lux'}) get_accessory(None, state, 2, {}) + def test_light_sensor_unit_lx(self): + """Test light sensor with lx as unit.""" + with patch.dict(TYPES, {'LightSensor': self.mock_type}): + state = State('sensor.light', '900', + {ATTR_UNIT_OF_MEASUREMENT: 'lx'}) + get_accessory(None, state, 2, {}) + def test_binary_sensor(self): """Test binary sensor with opening class.""" with patch.dict(TYPES, {'BinarySensor': self.mock_type}):