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
This commit is contained in:
J. Nick Koston 2025-04-13 22:12:27 -10:00 committed by GitHub
parent a340646e1e
commit 1aa996d5f0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 13 additions and 0 deletions

View File

@ -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):

View File

@ -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