Skip to content

@mqtt_trigger Failure to Handle Non-UTF-8 Messages #780

@3735943886

Description

@3735943886

The @mqtt_trigger decorator fails to trigger when an MQTT message with a non-UTF-8 encoding is published to the subscribed topic.

This issue appears to be caused by the process where @mqtt_trigger attempts to decode the message payload into a string using the default utf-8 encoding.


Reproduction Steps

  1. Define a Simple PyScript Function: Create a function that uses the @mqtt_trigger decorator to subscribe to a test topic (e.g., 'test_topic').

    @mqtt_trigger('test_topic')
    def test(**kwargs):
        log.info('triggered!')
  2. Publish a Non-UTF-8 Payload: Use an MQTT client (like mosquitto_pub) to publish a payload that contains bytes that are invalid for UTF-8 decoding (e.g., \xfe\xff) to the topic defined in the trigger.

    printf '\xfe\xff' | mosquitto_pub -t test_topic -l

Outcome

When the non-UTF-8 payload is received:

  • The function decorated with @mqtt_trigger is not triggered.
  • An error message related to decoding is logged.

Error Message (From Home Assistant Log)

Can't decode payload b'\xfe\xff' on test_topic with encoding utf-8 (for <Job None HassJobType.Coroutinefunction functools.partial(<function _async_wrapper at 0xe34afe64a480>, <function Mqtt.mqtt_message_handler_maker.<locals>.mqtt_message_handler at 0xe34acc7ab4c0>, functools.partial(<bound method MQTT._exception_message of <homeassistant.components.mqtt.client.MQTT object at 0xe34ad2f68ec0>>, <function Mqtt.mqtt_message_handler_maker.<locals>.mqtt_message_handler at 0xe34acc7ab4c0>))>)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions