From 1681bbe5a55a8847eed8053fba4056a33ba1891a Mon Sep 17 00:00:00 2001 From: Jc2k Date: Mon, 26 Jul 2021 22:11:27 +0100 Subject: [PATCH] Make sure that vocolinc flowerbud humidity sensor is exposed (via homekit_controller) (#53518) * Make sure that vocolinc flowerbud humidity sensor is exposed * Was a no-op to request these from humidifier, so remove them * Fix typo --- .../components/homekit_controller/const.py | 3 +++ .../homekit_controller/humidifier.py | 2 -- .../components/homekit_controller/sensor.py | 10 +++++++++ .../test_vocolinc_flowerbud.py | 22 +++++++++++++++++++ 4 files changed, 35 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/homekit_controller/const.py b/homeassistant/components/homekit_controller/const.py index 321113cf8df..5b4c87f53e4 100644 --- a/homeassistant/components/homekit_controller/const.py +++ b/homeassistant/components/homekit_controller/const.py @@ -49,4 +49,7 @@ CHARACTERISTIC_PLATFORMS = { CharacteristicsTypes.Vendor.KOOGEEK_REALTIME_ENERGY_2: "sensor", CharacteristicsTypes.Vendor.VOCOLINC_HUMIDIFIER_SPRAY_LEVEL: "number", CharacteristicsTypes.get_uuid(CharacteristicsTypes.TEMPERATURE_CURRENT): "sensor", + CharacteristicsTypes.get_uuid( + CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT + ): "sensor", } diff --git a/homeassistant/components/homekit_controller/humidifier.py b/homeassistant/components/homekit_controller/humidifier.py index dfddd29f2ff..1505ead993b 100644 --- a/homeassistant/components/homekit_controller/humidifier.py +++ b/homeassistant/components/homekit_controller/humidifier.py @@ -41,7 +41,6 @@ class HomeKitHumidifier(HomeKitEntity, HumidifierEntity): """Define the homekit characteristics the entity cares about.""" return [ CharacteristicsTypes.ACTIVE, - CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT, CharacteristicsTypes.CURRENT_HUMIDIFIER_DEHUMIDIFIER_STATE, CharacteristicsTypes.TARGET_HUMIDIFIER_DEHUMIDIFIER_STATE, CharacteristicsTypes.RELATIVE_HUMIDITY_HUMIDIFIER_THRESHOLD, @@ -143,7 +142,6 @@ class HomeKitDehumidifier(HomeKitEntity, HumidifierEntity): """Define the homekit characteristics the entity cares about.""" return [ CharacteristicsTypes.ACTIVE, - CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT, CharacteristicsTypes.CURRENT_HUMIDIFIER_DEHUMIDIFIER_STATE, CharacteristicsTypes.TARGET_HUMIDIFIER_DEHUMIDIFIER_STATE, CharacteristicsTypes.RELATIVE_HUMIDITY_HUMIDIFIER_THRESHOLD, diff --git a/homeassistant/components/homekit_controller/sensor.py b/homeassistant/components/homekit_controller/sensor.py index c24f46198c0..f34fc3f0a9b 100644 --- a/homeassistant/components/homekit_controller/sensor.py +++ b/homeassistant/components/homekit_controller/sensor.py @@ -53,6 +53,16 @@ SIMPLE_SENSOR = { "probe": lambda char: char.service.type != ServicesTypes.get_uuid(ServicesTypes.TEMPERATURE_SENSOR), }, + CharacteristicsTypes.get_uuid(CharacteristicsTypes.RELATIVE_HUMIDITY_CURRENT): { + "name": "Current Humidity", + "device_class": DEVICE_CLASS_HUMIDITY, + "state_class": STATE_CLASS_MEASUREMENT, + "unit": PERCENTAGE, + # This sensor is only for humidity characteristics that are not part + # of a humidity sensor service. + "probe": lambda char: char.service.type + != ServicesTypes.get_uuid(ServicesTypes.HUMIDITY_SENSOR), + }, } diff --git a/tests/components/homekit_controller/specific_devices/test_vocolinc_flowerbud.py b/tests/components/homekit_controller/specific_devices/test_vocolinc_flowerbud.py index ee4713b012b..e2762b5c153 100644 --- a/tests/components/homekit_controller/specific_devices/test_vocolinc_flowerbud.py +++ b/tests/components/homekit_controller/specific_devices/test_vocolinc_flowerbud.py @@ -68,3 +68,25 @@ async def test_vocolinc_flowerbud_setup(hass): # The sensor and switch should be part of the same device assert entry.device_id == device.id + + # Assert the humidity sensory is detected + entry = entity_registry.async_get( + "sensor.vocolinc_flowerbud_0d324b_current_humidity" + ) + assert entry.unique_id == "homekit-AM01121849000327-aid:1-sid:30-cid:30" + + helper = Helper( + hass, + "sensor.vocolinc_flowerbud_0d324b_current_humidity", + pairing, + accessories[0], + config_entry, + ) + state = await helper.poll_and_get_state() + assert ( + state.attributes["friendly_name"] + == "VOCOlinc-Flowerbud-0d324b - Current Humidity" + ) + + # The sensor and humidifier should be part of the same device + assert entry.device_id == device.id