From bb76ba67f319775cc8abf1047098b0b723eab7b1 Mon Sep 17 00:00:00 2001 From: cdce8p <30130371+cdce8p@users.noreply.github.com> Date: Fri, 4 May 2018 22:48:38 +0200 Subject: [PATCH] Homekit: Changed device_class requirement Humidity Sensor (#14277) --- homeassistant/components/homekit/__init__.py | 9 ++++----- tests/components/homekit/test_get_accessories.py | 10 ++-------- 2 files changed, 6 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/homekit/__init__.py b/homeassistant/components/homekit/__init__.py index 080dd2a7cbd..3abfffd67e0 100644 --- a/homeassistant/components/homekit/__init__.py +++ b/homeassistant/components/homekit/__init__.py @@ -126,10 +126,10 @@ def get_accessory(hass, state, aid, config): unit = state.attributes.get(ATTR_UNIT_OF_MEASUREMENT) device_class = state.attributes.get(ATTR_DEVICE_CLASS) - if device_class == DEVICE_CLASS_TEMPERATURE or unit == TEMP_CELSIUS \ - or unit == TEMP_FAHRENHEIT: + if device_class == DEVICE_CLASS_TEMPERATURE or \ + unit in (TEMP_CELSIUS, TEMP_FAHRENHEIT): a_type = 'TemperatureSensor' - elif device_class == DEVICE_CLASS_HUMIDITY or unit == '%': + elif device_class == DEVICE_CLASS_HUMIDITY and unit == '%': a_type = 'HumiditySensor' elif device_class == DEVICE_CLASS_PM25 \ or DEVICE_CLASS_PM25 in state.entity_id: @@ -141,8 +141,7 @@ def get_accessory(hass, state, aid, config): unit == 'lux' or unit == 'lx': a_type = 'LightSensor' - elif state.domain == 'switch' or state.domain == 'remote' \ - or state.domain == 'input_boolean' or state.domain == 'script': + elif state.domain in ('switch', 'remote', 'input_boolean', 'script'): a_type = 'Switch' if a_type is None: diff --git a/tests/components/homekit/test_get_accessories.py b/tests/components/homekit/test_get_accessories.py index 76736ce45ad..71f9c8e6656 100644 --- a/tests/components/homekit/test_get_accessories.py +++ b/tests/components/homekit/test_get_accessories.py @@ -68,14 +68,8 @@ class TestGetAccessories(unittest.TestCase): """Test humidity sensor with device class humidity.""" with patch.dict(TYPES, {'HumiditySensor': self.mock_type}): state = State('sensor.humidity', '20', - {ATTR_DEVICE_CLASS: 'humidity'}) - get_accessory(None, state, 2, {}) - - def test_sensor_humidity_unit(self): - """Test humidity sensor with % as unit.""" - with patch.dict(TYPES, {'HumiditySensor': self.mock_type}): - state = State('sensor.humidity', '20', - {ATTR_UNIT_OF_MEASUREMENT: '%'}) + {ATTR_DEVICE_CLASS: 'humidity', + ATTR_UNIT_OF_MEASUREMENT: '%'}) get_accessory(None, state, 2, {}) def test_air_quality_sensor(self):