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