From 1aa996d5f0fc5e120da00731e4b2e782c265e100 Mon Sep 17 00:00:00 2001 From: "J. Nick Koston" Date: Sun, 13 Apr 2025 22:12:27 -1000 Subject: [PATCH] Add debug logging to homekit when an sensor entity cannot be classified (#142707) * Add debug logging to homekit when an sensor entity cannot be classified In #132937 many hours were spent investigating an issue which turned out to be that the entity did not have a device class at startup because the group integration does not set the device class if any of the underlying entities state is invalid. closes #132937 * coverage * Update tests/components/homekit/test_get_accessories.py --- homeassistant/components/homekit/accessories.py | 7 +++++++ tests/components/homekit/test_get_accessories.py | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/homeassistant/components/homekit/accessories.py b/homeassistant/components/homekit/accessories.py index d680181f5e4..95842d56094 100644 --- a/homeassistant/components/homekit/accessories.py +++ b/homeassistant/components/homekit/accessories.py @@ -245,6 +245,13 @@ def get_accessory( # noqa: C901 a_type = "CarbonDioxideSensor" elif device_class == SensorDeviceClass.ILLUMINANCE or unit == LIGHT_LUX: a_type = "LightSensor" + else: + _LOGGER.debug( + "%s: Unsupported sensor type (device_class=%s) (unit=%s)", + state.entity_id, + device_class, + unit, + ) elif state.domain == "switch": if switch_type := config.get(CONF_TYPE): diff --git a/tests/components/homekit/test_get_accessories.py b/tests/components/homekit/test_get_accessories.py index 56208961312..de5cda71513 100644 --- a/tests/components/homekit/test_get_accessories.py +++ b/tests/components/homekit/test_get_accessories.py @@ -53,6 +53,12 @@ def test_not_supported(caplog: pytest.LogCaptureFixture) -> None: assert "invalid aid" in caplog.records[0].msg +def test_not_supported_sensor(caplog: pytest.LogCaptureFixture) -> None: + """Test if none is returned if entity isn't supported.""" + assert get_accessory(None, None, State("sensor.xyz", "on"), 2, {}) is None + assert "Unsupported sensor type (device_class=None)" in caplog.text + + def test_not_supported_media_player() -> None: """Test if mode isn't supported and if no supported modes.""" # selected mode for entity not supported