Better log message for KNX expose conversion error (#89400)

This commit is contained in:
Matthias Alphart 2023-03-08 10:42:07 -11:00 committed by GitHub
parent 0d948a0f11
commit bfae8992a9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 4 deletions

View File

@ -161,8 +161,14 @@ class KNXExposeSensor:
"""Set new value on xknx ExposeSensor."""
try:
await self.device.set(value)
except ConversionError:
_LOGGER.exception("Error during sending of expose sensor value")
except ConversionError as err:
_LOGGER.warning(
'Could not expose %s %s value "%s" to KNX: %s',
self.entity_id,
self.expose_attribute or "state",
value,
err,
)
class KNXExposeTime:

View File

@ -3,6 +3,8 @@ from datetime import timedelta
import time
from unittest.mock import patch
import pytest
from homeassistant.components.knx import CONF_KNX_EXPOSE, DOMAIN, KNX_ADDRESS
from homeassistant.components.knx.schema import ExposeSchema
from homeassistant.const import CONF_ATTRIBUTE, CONF_ENTITY_ID, CONF_TYPE
@ -201,7 +203,7 @@ async def test_expose_cooldown(hass: HomeAssistant, knx: KNXTestKit) -> None:
async def test_expose_conversion_exception(
hass: HomeAssistant, knx: KNXTestKit
hass: HomeAssistant, caplog: pytest.LogCaptureFixture, knx: KNXTestKit
) -> None:
"""Test expose throws exception."""
@ -230,8 +232,11 @@ async def test_expose_conversion_exception(
"on",
{attribute: 101},
)
await knx.assert_no_telegram()
assert (
'Could not expose fake.entity fake_attribute value "101.0" to KNX:'
in caplog.text
)
@patch("time.localtime")