Fix error handling on subscribe when mqtt is not initialized (#101832)
This commit is contained in:
parent
20a58d2314
commit
485c52568d
2 changed files with 18 additions and 1 deletions
|
@ -176,7 +176,13 @@ async def async_subscribe(
|
|||
raise HomeAssistantError(
|
||||
f"Cannot subscribe to topic '{topic}', MQTT is not enabled"
|
||||
)
|
||||
mqtt_data = get_mqtt_data(hass)
|
||||
try:
|
||||
mqtt_data = get_mqtt_data(hass)
|
||||
except KeyError as ex:
|
||||
raise HomeAssistantError(
|
||||
f"Cannot subscribe to topic '{topic}', "
|
||||
"make sure MQTT is set up correctly"
|
||||
) from ex
|
||||
async_remove = await mqtt_data.client.async_subscribe(
|
||||
topic,
|
||||
catch_log_exception(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue