Add translation key for some mqtt exceptions (#104550)
parent
b314df272f
commit
8a1f7b6802
|
@ -245,11 +245,11 @@ async def async_check_config_schema(
|
|||
for config in config_items:
|
||||
try:
|
||||
schema(config)
|
||||
except vol.Invalid as ex:
|
||||
except vol.Invalid as exc:
|
||||
integration = await async_get_integration(hass, DOMAIN)
|
||||
# pylint: disable-next=protected-access
|
||||
message = conf_util.format_schema_error(
|
||||
hass, ex, domain, config, integration.documentation
|
||||
hass, exc, domain, config, integration.documentation
|
||||
)
|
||||
raise ServiceValidationError(
|
||||
message,
|
||||
|
@ -258,7 +258,7 @@ async def async_check_config_schema(
|
|||
translation_placeholders={
|
||||
"domain": domain,
|
||||
},
|
||||
) from ex
|
||||
) from exc
|
||||
|
||||
|
||||
async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
||||
|
|
|
@ -124,7 +124,10 @@ async def async_publish(
|
|||
"""Publish message to a MQTT topic."""
|
||||
if not mqtt_config_entry_enabled(hass):
|
||||
raise HomeAssistantError(
|
||||
f"Cannot publish to topic '{topic}', MQTT is not enabled"
|
||||
f"Cannot publish to topic '{topic}', MQTT is not enabled",
|
||||
translation_key="mqtt_not_setup_cannot_publish",
|
||||
translation_domain=DOMAIN,
|
||||
translation_placeholders={"topic": topic},
|
||||
)
|
||||
mqtt_data = get_mqtt_data(hass)
|
||||
outgoing_payload = payload
|
||||
|
@ -174,15 +177,21 @@ async def async_subscribe(
|
|||
"""
|
||||
if not mqtt_config_entry_enabled(hass):
|
||||
raise HomeAssistantError(
|
||||
f"Cannot subscribe to topic '{topic}', MQTT is not enabled"
|
||||
f"Cannot subscribe to topic '{topic}', MQTT is not enabled",
|
||||
translation_key="mqtt_not_setup_cannot_subscribe",
|
||||
translation_domain=DOMAIN,
|
||||
translation_placeholders={"topic": topic},
|
||||
)
|
||||
try:
|
||||
mqtt_data = get_mqtt_data(hass)
|
||||
except KeyError as ex:
|
||||
except KeyError as exc:
|
||||
raise HomeAssistantError(
|
||||
f"Cannot subscribe to topic '{topic}', "
|
||||
"make sure MQTT is set up correctly"
|
||||
) from ex
|
||||
"make sure MQTT is set up correctly",
|
||||
translation_key="mqtt_not_setup_cannot_subscribe",
|
||||
translation_domain=DOMAIN,
|
||||
translation_placeholders={"topic": topic},
|
||||
) from exc
|
||||
async_remove = await mqtt_data.client.async_subscribe(
|
||||
topic,
|
||||
catch_log_exception(
|
||||
|
@ -606,8 +615,8 @@ class MQTT:
|
|||
del simple_subscriptions[topic]
|
||||
else:
|
||||
self._wildcard_subscriptions.remove(subscription)
|
||||
except (KeyError, ValueError) as ex:
|
||||
raise HomeAssistantError("Can't remove subscription twice") from ex
|
||||
except (KeyError, ValueError) as exc:
|
||||
raise HomeAssistantError("Can't remove subscription twice") from exc
|
||||
|
||||
@callback
|
||||
def _async_queue_subscriptions(
|
||||
|
|
|
@ -457,8 +457,8 @@ async def async_setup_entity_entry_helper(
|
|||
if TYPE_CHECKING:
|
||||
assert entity_class is not None
|
||||
entities.append(entity_class(hass, config, entry, None))
|
||||
except vol.Invalid as ex:
|
||||
error = str(ex)
|
||||
except vol.Invalid as exc:
|
||||
error = str(exc)
|
||||
config_file = getattr(yaml_config, "__config_file__", "?")
|
||||
line = getattr(yaml_config, "__line__", "?")
|
||||
issue_id = hex(hash(frozenset(yaml_config)))
|
||||
|
|
|
@ -247,15 +247,15 @@ class MqttValueTemplate:
|
|||
payload, variables=values
|
||||
)
|
||||
)
|
||||
except Exception as ex:
|
||||
except Exception as exc:
|
||||
_LOGGER.error(
|
||||
"%s: %s rendering template for entity '%s', template: '%s'",
|
||||
type(ex).__name__,
|
||||
ex,
|
||||
type(exc).__name__,
|
||||
exc,
|
||||
self._entity.entity_id if self._entity else "n/a",
|
||||
self._value_template.template,
|
||||
)
|
||||
raise ex
|
||||
raise exc
|
||||
return rendered_payload
|
||||
|
||||
_LOGGER.debug(
|
||||
|
|
|
@ -214,7 +214,13 @@
|
|||
},
|
||||
"exceptions": {
|
||||
"invalid_platform_config": {
|
||||
"message": "Reloading YAML config for manually configured MQTT `{domain}` failed. See logs for more details."
|
||||
"message": "Reloading YAML config for manually configured MQTT `{domain}` item failed. See logs for more details."
|
||||
},
|
||||
"mqtt_not_setup_cannot_subscribe": {
|
||||
"message": "Cannot subscribe to topic '{topic}', make sure MQTT is set up correctly."
|
||||
},
|
||||
"mqtt_not_setup_cannot_publish": {
|
||||
"message": "Cannot publish to topic '{topic}', make sure MQTT is set up correctly."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue