[mqtt.homeassistant] Discovery exceptions processing #11315
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
[mqtt.homeassistant] Discovery exceptions processing
Noticed that exceptions in mqtt message handlers are not processed properly during discovery and even not added to logs.
Mqtt transport implementation doesn't have an information about how to process exceptions, and not handling them.
org.openhab.core.io.transport.mqtt.MqttMessageSubscriber#processMessage
Added exceptions types for component config errors and added exceptions processing to mqtt handlers.
I think the bug could be closed after PR: #11085
Can be reproduced by sending invalid JSON to homeassistant discovery */config topic, for example:
mosquitto_pub -h 127.0.0.1 -p 1883 -t homeassistant/sensor/R5EE70BB9_N321346B4/config -m '{"~":"Bedroom/BME280","dev_cla":"temperature","name":"Bedroom Temperature","stat_t":"~state","unit_of_meas":"°C","json_attributes_topic":"~state","val_tpl":"{{ value_json.temperature }}","uniq_id":"R5EE70BB9_N321346B4","avty_t":"~status","pl_avail":"Online","pl_not_avail":"Offline","device":{"identifiers":["R5EE70BB9"],"connections":["mac","00155D009500"],"name":"BME280 Bedroom"}}'
Before PR there are no messages in the log.
After PR:
15:03:24.623 [WARN ] [rnal.discovery.HomeAssistantDiscovery] - HomeAssistant discover error: Cannot parse JSON array. Each connection must be defined as array with two elements: connection_type, connection identifier. For example: "connections": [["mac", "02:5b:26:a8:dc:12"]]