From 5b257d2be80430819513874e8e247fb05a90c8f8 Mon Sep 17 00:00:00 2001 From: Jc2k Date: Thu, 8 Jul 2021 17:26:25 +0100 Subject: [PATCH] Fix homebridge devices becoming unavailable frequently (#52753) Update to aiohomekit 0.4.3 and make sure service type UUID is normalised before comparison Co-authored-by: J. Nick Koston --- .../components/homekit_controller/manifest.json | 2 +- homeassistant/components/homekit_controller/sensor.py | 3 ++- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/homekit_controller/test_sensor.py | 10 ++++++++++ 5 files changed, 15 insertions(+), 4 deletions(-) diff --git a/homeassistant/components/homekit_controller/manifest.json b/homeassistant/components/homekit_controller/manifest.json index 496d629d112..2d40cc8a235 100644 --- a/homeassistant/components/homekit_controller/manifest.json +++ b/homeassistant/components/homekit_controller/manifest.json @@ -3,7 +3,7 @@ "name": "HomeKit Controller", "config_flow": true, "documentation": "https://www.home-assistant.io/integrations/homekit_controller", - "requirements": ["aiohomekit==0.4.2"], + "requirements": ["aiohomekit==0.4.3"], "zeroconf": ["_hap._tcp.local."], "after_dependencies": ["zeroconf"], "codeowners": ["@Jc2k", "@bdraco"], diff --git a/homeassistant/components/homekit_controller/sensor.py b/homeassistant/components/homekit_controller/sensor.py index fe98b75130c..b21010e9b1e 100644 --- a/homeassistant/components/homekit_controller/sensor.py +++ b/homeassistant/components/homekit_controller/sensor.py @@ -44,7 +44,8 @@ SIMPLE_SENSOR = { "unit": TEMP_CELSIUS, # This sensor is only for temperature characteristics that are not part # of a temperature sensor service. - "probe": lambda char: char.service.type != ServicesTypes.TEMPERATURE_SENSOR, + "probe": lambda char: char.service.type + != ServicesTypes.get_uuid(ServicesTypes.TEMPERATURE_SENSOR), }, } diff --git a/requirements_all.txt b/requirements_all.txt index 1a2b89864a9..b7f01f0edef 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -175,7 +175,7 @@ aioguardian==1.0.4 aioharmony==0.2.7 # homeassistant.components.homekit_controller -aiohomekit==0.4.2 +aiohomekit==0.4.3 # homeassistant.components.emulated_hue # homeassistant.components.http diff --git a/requirements_test_all.txt b/requirements_test_all.txt index 5afedac092a..34c2d899d23 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -112,7 +112,7 @@ aioguardian==1.0.4 aioharmony==0.2.7 # homeassistant.components.homekit_controller -aiohomekit==0.4.2 +aiohomekit==0.4.3 # homeassistant.components.emulated_hue # homeassistant.components.http diff --git a/tests/components/homekit_controller/test_sensor.py b/tests/components/homekit_controller/test_sensor.py index a79e94c4bb7..604c83e54f7 100644 --- a/tests/components/homekit_controller/test_sensor.py +++ b/tests/components/homekit_controller/test_sensor.py @@ -86,6 +86,16 @@ async def test_temperature_sensor_read_state(hass, utcnow): assert state.attributes["device_class"] == DEVICE_CLASS_TEMPERATURE +async def test_temperature_sensor_not_added_twice(hass, utcnow): + """A standalone temperature sensor should not get a characteristic AND a service entity.""" + helper = await setup_test_component( + hass, create_temperature_sensor_service, suffix="temperature" + ) + + for state in hass.states.async_all(): + assert state.entity_id == helper.entity_id + + async def test_humidity_sensor_read_state(hass, utcnow): """Test reading the state of a HomeKit humidity sensor accessory.""" helper = await setup_test_component(