Skip to content

Commit 5708f61

Browse files
authored
Prepare to move out URL's from MQTT translation strings (home-assistant#154391)
1 parent 4fb3c9f commit 5708f61

File tree

2 files changed

+60
-27
lines changed

2 files changed

+60
-27
lines changed

homeassistant/components/mqtt/config_flow.py

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,26 @@
470470
EXCLUDE_FROM_CONFIG_IF_NONE = {CONF_ENTITY_CATEGORY}
471471
PWD_NOT_CHANGED = "__**password_not_changed**__"
472472

473+
DEVELOPER_DOCUMENTATION_URL = "https://developers.home-assistant.io/"
474+
USER_DOCUMENTATION_URL = "https://www.home-assistant.io/"
475+
476+
INTEGRATION_URL = f"{USER_DOCUMENTATION_URL}integrations/{DOMAIN}/"
477+
TEMPLATING_URL = f"{USER_DOCUMENTATION_URL}docs/configuration/templating/"
478+
AVAILABLE_STATE_CLASSES_URL = (
479+
f"{DEVELOPER_DOCUMENTATION_URL}docs/core/entity/sensor/#available-state-classes"
480+
)
481+
NAMING_ENTITIES_URL = f"{INTEGRATION_URL}#naming-of-mqtt-entities"
482+
REGISTRY_PROPERTIES_URL = (
483+
f"{DEVELOPER_DOCUMENTATION_URL}docs/core/entity/#registry-properties"
484+
)
485+
486+
TRANSLATION_DESCRIPTION_PLACEHOLDERS = {
487+
"templating_url": TEMPLATING_URL,
488+
"available_state_classes_url": AVAILABLE_STATE_CLASSES_URL,
489+
"naming_entities_url": NAMING_ENTITIES_URL,
490+
"registry_properties_url": REGISTRY_PROPERTIES_URL,
491+
}
492+
473493
# Common selectors
474494
BOOLEAN_SELECTOR = BooleanSelector()
475495
TEMPLATE_SELECTOR = TemplateSelector(TemplateSelectorConfig())
@@ -4248,7 +4268,8 @@ async def async_step_entity_platform_config(
42484268
return self.async_show_form(
42494269
step_id="entity_platform_config",
42504270
data_schema=data_schema,
4251-
description_placeholders={
4271+
description_placeholders=TRANSLATION_DESCRIPTION_PLACEHOLDERS
4272+
| {
42524273
"mqtt_device": device_name,
42534274
CONF_PLATFORM: platform,
42544275
"entity": full_entity_name,
@@ -4301,7 +4322,8 @@ async def async_step_mqtt_platform_config(
43014322
return self.async_show_form(
43024323
step_id="mqtt_platform_config",
43034324
data_schema=data_schema,
4304-
description_placeholders={
4325+
description_placeholders=TRANSLATION_DESCRIPTION_PLACEHOLDERS
4326+
| {
43054327
"mqtt_device": device_name,
43064328
CONF_PLATFORM: platform,
43074329
"entity": full_entity_name,
@@ -4517,9 +4539,7 @@ async def async_step_export_yaml(
45174539
step_id="export_yaml",
45184540
last_step=False,
45194541
data_schema=data_schema,
4520-
description_placeholders={
4521-
"url": "https://www.home-assistant.io/integrations/mqtt/"
4522-
},
4542+
description_placeholders={"url": INTEGRATION_URL},
45234543
)
45244544

45254545
async def async_step_export_discovery(
@@ -4571,9 +4591,7 @@ async def async_step_export_discovery(
45714591
step_id="export_discovery",
45724592
last_step=False,
45734593
data_schema=data_schema,
4574-
description_placeholders={
4575-
"url": "https://www.home-assistant.io/integrations/mqtt/"
4576-
},
4594+
description_placeholders={"url": INTEGRATION_URL},
45774595
)
45784596

45794597

tests/components/mqtt/test_config_flow.py

Lines changed: 34 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@
1717
from homeassistant import config_entries
1818
from homeassistant.components import mqtt
1919
from homeassistant.components.hassio import AddonError
20-
from homeassistant.components.mqtt.config_flow import PWD_NOT_CHANGED
20+
from homeassistant.components.mqtt.config_flow import (
21+
PWD_NOT_CHANGED,
22+
TRANSLATION_DESCRIPTION_PLACEHOLDERS,
23+
)
2124
from homeassistant.components.mqtt.util import learn_more_url
2225
from homeassistant.config_entries import ConfigSubentry, ConfigSubentryData
2326
from homeassistant.const import (
@@ -3757,12 +3760,16 @@ async def test_subentry_configflow(
37573760
)
37583761
assert result["type"] is FlowResultType.FORM
37593762
assert result["errors"] == {}
3760-
assert result["description_placeholders"] == {
3761-
"mqtt_device": device_name,
3762-
"platform": component["platform"],
3763-
"entity": entity_name,
3764-
"url": learn_more_url(component["platform"]),
3765-
}
3763+
assert (
3764+
result["description_placeholders"]
3765+
== {
3766+
"mqtt_device": device_name,
3767+
"platform": component["platform"],
3768+
"entity": entity_name,
3769+
"url": learn_more_url(component["platform"]),
3770+
}
3771+
| TRANSLATION_DESCRIPTION_PLACEHOLDERS
3772+
)
37663773

37673774
# Process entity details step
37683775
assert result["step_id"] == "entity_platform_config"
@@ -3784,12 +3791,16 @@ async def test_subentry_configflow(
37843791
)
37853792
assert result["type"] is FlowResultType.FORM
37863793
assert result["errors"] == {}
3787-
assert result["description_placeholders"] == {
3788-
"mqtt_device": device_name,
3789-
"platform": component["platform"],
3790-
"entity": entity_name,
3791-
"url": learn_more_url(component["platform"]),
3792-
}
3794+
assert (
3795+
result["description_placeholders"]
3796+
== {
3797+
"mqtt_device": device_name,
3798+
"platform": component["platform"],
3799+
"entity": entity_name,
3800+
"url": learn_more_url(component["platform"]),
3801+
}
3802+
| TRANSLATION_DESCRIPTION_PLACEHOLDERS
3803+
)
37933804

37943805
# Process mqtt platform config flow
37953806
# Test an invalid mqtt user input case
@@ -5096,12 +5107,16 @@ async def test_subentry_configflow_section_feature(
50965107
user_input={"platform": "fan"},
50975108
)
50985109
assert result["type"] is FlowResultType.FORM
5099-
assert result["description_placeholders"] == {
5100-
"mqtt_device": "Bla",
5101-
"platform": "fan",
5102-
"entity": "Bla",
5103-
"url": learn_more_url("fan"),
5104-
}
5110+
assert (
5111+
result["description_placeholders"]
5112+
== {
5113+
"mqtt_device": "Bla",
5114+
"platform": "fan",
5115+
"entity": "Bla",
5116+
"url": learn_more_url("fan"),
5117+
}
5118+
| TRANSLATION_DESCRIPTION_PLACEHOLDERS
5119+
)
51055120

51065121
# Process entity details step
51075122
assert result["step_id"] == "entity_platform_config"

0 commit comments

Comments
 (0)