Improve error logging on invalid MQTT entity state (#118006)

* Improve error logging on invalid MQTT entity state

* Explain not hanlding TpeError and ValueError

* Move length check closer to source

* use _LOGGER.exception
This commit is contained in:
Jan Bouwhuis 2024-05-24 13:11:52 +02:00 committed by GitHub
parent 7d44321f0f
commit f12aee28a8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 106 additions and 12 deletions

View file

@ -49,6 +49,7 @@ from .models import (
ReceivePayloadType,
)
from .schemas import MQTT_ENTITY_COMMON_SCHEMA
from .util import check_state_too_long
_LOGGER = logging.getLogger(__name__)
@ -180,6 +181,8 @@ class MqttTextEntity(MqttEntity, TextEntity):
def handle_state_message_received(msg: ReceiveMessage) -> None:
"""Handle receiving state message via MQTT."""
payload = str(self._value_template(msg.payload))
if check_state_too_long(_LOGGER, payload, self.entity_id, msg):
return
self._attr_native_value = payload
add_subscription(topics, CONF_STATE_TOPIC, handle_state_message_received)