Skip to content

Commit a020a32

Browse files
authored
Remove translations from WS get_services and REST /api/services (#147120)
1 parent 1ac2ae3 commit a020a32

File tree

9 files changed

+81
-185
lines changed

9 files changed

+81
-185
lines changed

homeassistant/helpers/service.py

Lines changed: 5 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,6 @@
5858
selector,
5959
target as target_helpers,
6060
template,
61-
translation,
6261
)
6362
from .deprecation import deprecated_class, deprecated_function, deprecated_hass_argument
6463
from .selector import TargetSelector
@@ -586,11 +585,6 @@ async def async_get_all_descriptions(
586585
_load_services_files, integrations
587586
)
588587

589-
# Load translations for all service domains
590-
translations = await translation.async_get_translations(
591-
hass, "en", "services", services
592-
)
593-
594588
# Build response
595589
descriptions: dict[str, dict[str, Any]] = {}
596590
for domain, services_map in services.items():
@@ -617,40 +611,11 @@ async def async_get_all_descriptions(
617611

618612
# Don't warn for missing services, because it triggers false
619613
# positives for things like scripts, that register as a service
620-
#
621-
# When name & description are in the translations use those;
622-
# otherwise fallback to backwards compatible behavior from
623-
# the time when we didn't have translations for descriptions yet.
624-
# This mimics the behavior of the frontend.
625-
description = {
626-
"name": translations.get(
627-
f"component.{domain}.services.{service_name}.name",
628-
yaml_description.get("name", ""),
629-
),
630-
"description": translations.get(
631-
f"component.{domain}.services.{service_name}.description",
632-
yaml_description.get("description", ""),
633-
),
634-
"fields": dict(yaml_description.get("fields", {})),
635-
}
636-
637-
# Translate fields names & descriptions as well
638-
for field_name, field_schema in description["fields"].items():
639-
if name := translations.get(
640-
f"component.{domain}.services.{service_name}.fields.{field_name}.name"
641-
):
642-
field_schema["name"] = name
643-
if desc := translations.get(
644-
f"component.{domain}.services.{service_name}.fields.{field_name}.description"
645-
):
646-
field_schema["description"] = desc
647-
if example := translations.get(
648-
f"component.{domain}.services.{service_name}.fields.{field_name}.example"
649-
):
650-
field_schema["example"] = example
651-
652-
if "target" in yaml_description:
653-
description["target"] = yaml_description["target"]
614+
description = {"fields": yaml_description.get("fields", {})}
615+
616+
for item in ("description", "name", "target"):
617+
if item in yaml_description:
618+
description[item] = yaml_description[item]
654619

655620
response = service.supports_response
656621
if response is not SupportsResponse.NONE:

tests/components/api/snapshots/test_init.ambr

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,13 @@
55
'domain': 'group',
66
'services': dict({
77
'reload': dict({
8-
'description': 'Reloads group configuration, entities, and notify services from YAML-configuration.',
98
'fields': dict({
109
}),
11-
'name': 'Reload',
1210
}),
1311
'remove': dict({
14-
'description': 'Removes a group.',
1512
'fields': dict({
1613
'object_id': dict({
17-
'description': 'Object ID of this group. This object ID is used as part of the entity ID. Entity ID format: [domain].[object_id].',
1814
'example': 'test_group',
19-
'name': 'Object ID',
2015
'required': True,
2116
'selector': dict({
2217
'object': dict({
@@ -25,15 +20,11 @@
2520
}),
2621
}),
2722
}),
28-
'name': 'Remove',
2923
}),
3024
'set': dict({
31-
'description': 'Creates/Updates a group.',
3225
'fields': dict({
3326
'add_entities': dict({
34-
'description': 'List of members to be added to the group. Cannot be used in combination with `Entities` or `Remove entities`.',
3527
'example': 'domain.entity_id1, domain.entity_id2',
36-
'name': 'Add entities',
3728
'selector': dict({
3829
'entity': dict({
3930
'multiple': True,
@@ -42,17 +33,13 @@
4233
}),
4334
}),
4435
'all': dict({
45-
'description': 'Enable this option if the group should only be used when all entities are in state `on`.',
46-
'name': 'All',
4736
'selector': dict({
4837
'boolean': dict({
4938
}),
5039
}),
5140
}),
5241
'entities': dict({
53-
'description': 'List of all members in the group. Cannot be used in combination with `Add entities` or `Remove entities`.',
5442
'example': 'domain.entity_id1, domain.entity_id2',
55-
'name': 'Entities',
5643
'selector': dict({
5744
'entity': dict({
5845
'multiple': True,
@@ -61,18 +48,14 @@
6148
}),
6249
}),
6350
'icon': dict({
64-
'description': 'Name of the icon for the group.',
6551
'example': 'mdi:camera',
66-
'name': 'Icon',
6752
'selector': dict({
6853
'icon': dict({
6954
}),
7055
}),
7156
}),
7257
'name': dict({
73-
'description': 'Name of the group.',
7458
'example': 'My test group',
75-
'name': 'Name',
7659
'selector': dict({
7760
'text': dict({
7861
'multiline': False,
@@ -81,9 +64,7 @@
8164
}),
8265
}),
8366
'object_id': dict({
84-
'description': 'Object ID of this group. This object ID is used as part of the entity ID. Entity ID format: [domain].[object_id].',
8567
'example': 'test_group',
86-
'name': 'Object ID',
8768
'required': True,
8869
'selector': dict({
8970
'text': dict({
@@ -93,9 +74,7 @@
9374
}),
9475
}),
9576
'remove_entities': dict({
96-
'description': 'List of members to be removed from a group. Cannot be used in combination with `Entities` or `Add entities`.',
9777
'example': 'domain.entity_id1, domain.entity_id2',
98-
'name': 'Remove entities',
9978
'selector': dict({
10079
'entity': dict({
10180
'multiple': True,
@@ -104,7 +83,6 @@
10483
}),
10584
}),
10685
}),
107-
'name': 'Set',
10886
}),
10987
}),
11088
}),
@@ -139,10 +117,8 @@
139117
'name': 'Translated name',
140118
}),
141119
'set_level': dict({
142-
'description': '',
143120
'fields': dict({
144121
}),
145-
'name': '',
146122
}),
147123
}),
148124
})

tests/components/api/test_init.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -375,10 +375,6 @@ def _load_services_file(integration: Integration) -> JSON_TYPE:
375375
"homeassistant.helpers.service._load_services_file",
376376
side_effect=_load_services_file,
377377
),
378-
patch(
379-
"homeassistant.helpers.service.translation.async_get_translations",
380-
return_value={},
381-
),
382378
):
383379
resp = await mock_api_client.get(const.URL_API_SERVICES)
384380

tests/components/number/test_init.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ async def test_translated_unit(
864864
"""Test translated unit."""
865865

866866
with patch(
867-
"homeassistant.helpers.service.translation.async_get_translations",
867+
"homeassistant.helpers.entity_platform.translation.async_get_translations",
868868
return_value={
869869
"component.test.entity.number.test_translation_key.unit_of_measurement": "Tests"
870870
},
@@ -896,7 +896,7 @@ async def test_translated_unit_with_native_unit_raises(
896896
"""Test that translated unit."""
897897

898898
with patch(
899-
"homeassistant.helpers.service.translation.async_get_translations",
899+
"homeassistant.helpers.entity_platform.translation.async_get_translations",
900900
return_value={
901901
"component.test.entity.number.test_translation_key.unit_of_measurement": "Tests"
902902
},

tests/components/script/test_init.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,9 +627,6 @@ async def test_service_descriptions(hass: HomeAssistant) -> None:
627627

628628
assert descriptions[DOMAIN]["test_name"]["name"] == "ABC"
629629

630-
# Test 4: verify that names from YAML are taken into account as well
631-
assert descriptions[DOMAIN]["turn_on"]["name"] == "Turn on"
632-
633630

634631
async def test_shared_context(hass: HomeAssistant) -> None:
635632
"""Test that the shared context is passed down the chain."""

tests/components/sensor/test_init.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ async def test_translated_unit(
601601
"""Test translated unit."""
602602

603603
with patch(
604-
"homeassistant.helpers.service.translation.async_get_translations",
604+
"homeassistant.helpers.entity_platform.translation.async_get_translations",
605605
return_value={
606606
"component.test.entity.sensor.test_translation_key.unit_of_measurement": "Tests"
607607
},
@@ -633,7 +633,7 @@ async def test_translated_unit_with_native_unit_raises(
633633
"""Test that translated unit."""
634634

635635
with patch(
636-
"homeassistant.helpers.service.translation.async_get_translations",
636+
"homeassistant.helpers.entity_platform.translation.async_get_translations",
637637
return_value={
638638
"component.test.entity.sensor.test_translation_key.unit_of_measurement": "Tests"
639639
},
@@ -664,7 +664,7 @@ async def test_unit_translation_key_without_platform_raises(
664664
"""Test that unit translation key property raises if the entity has no platform yet."""
665665

666666
with patch(
667-
"homeassistant.helpers.service.translation.async_get_translations",
667+
"homeassistant.helpers.entity_platform.translation.async_get_translations",
668668
return_value={
669669
"component.test.entity.sensor.test_translation_key.unit_of_measurement": "Tests"
670670
},

tests/components/websocket_api/snapshots/test_commands.ambr

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,13 @@
22
# name: test_get_services
33
dict({
44
'reload': dict({
5-
'description': 'Reloads group configuration, entities, and notify services from YAML-configuration.',
65
'fields': dict({
76
}),
8-
'name': 'Reload',
97
}),
108
'remove': dict({
11-
'description': 'Removes a group.',
129
'fields': dict({
1310
'object_id': dict({
14-
'description': 'Object ID of this group. This object ID is used as part of the entity ID. Entity ID format: [domain].[object_id].',
1511
'example': 'test_group',
16-
'name': 'Object ID',
1712
'required': True,
1813
'selector': dict({
1914
'object': dict({
@@ -22,15 +17,11 @@
2217
}),
2318
}),
2419
}),
25-
'name': 'Remove',
2620
}),
2721
'set': dict({
28-
'description': 'Creates/Updates a group.',
2922
'fields': dict({
3023
'add_entities': dict({
31-
'description': 'List of members to be added to the group. Cannot be used in combination with `Entities` or `Remove entities`.',
3224
'example': 'domain.entity_id1, domain.entity_id2',
33-
'name': 'Add entities',
3425
'selector': dict({
3526
'entity': dict({
3627
'multiple': True,
@@ -39,17 +30,13 @@
3930
}),
4031
}),
4132
'all': dict({
42-
'description': 'Enable this option if the group should only be used when all entities are in state `on`.',
43-
'name': 'All',
4433
'selector': dict({
4534
'boolean': dict({
4635
}),
4736
}),
4837
}),
4938
'entities': dict({
50-
'description': 'List of all members in the group. Cannot be used in combination with `Add entities` or `Remove entities`.',
5139
'example': 'domain.entity_id1, domain.entity_id2',
52-
'name': 'Entities',
5340
'selector': dict({
5441
'entity': dict({
5542
'multiple': True,
@@ -58,18 +45,14 @@
5845
}),
5946
}),
6047
'icon': dict({
61-
'description': 'Name of the icon for the group.',
6248
'example': 'mdi:camera',
63-
'name': 'Icon',
6449
'selector': dict({
6550
'icon': dict({
6651
}),
6752
}),
6853
}),
6954
'name': dict({
70-
'description': 'Name of the group.',
7155
'example': 'My test group',
72-
'name': 'Name',
7356
'selector': dict({
7457
'text': dict({
7558
'multiline': False,
@@ -78,9 +61,7 @@
7861
}),
7962
}),
8063
'object_id': dict({
81-
'description': 'Object ID of this group. This object ID is used as part of the entity ID. Entity ID format: [domain].[object_id].',
8264
'example': 'test_group',
83-
'name': 'Object ID',
8465
'required': True,
8566
'selector': dict({
8667
'text': dict({
@@ -90,9 +71,7 @@
9071
}),
9172
}),
9273
'remove_entities': dict({
93-
'description': 'List of members to be removed from a group. Cannot be used in combination with `Entities` or `Add entities`.',
9474
'example': 'domain.entity_id1, domain.entity_id2',
95-
'name': 'Remove entities',
9675
'selector': dict({
9776
'entity': dict({
9877
'multiple': True,
@@ -101,7 +80,6 @@
10180
}),
10281
}),
10382
}),
104-
'name': 'Set',
10583
}),
10684
})
10785
# ---
@@ -132,10 +110,8 @@
132110
'name': 'Translated name',
133111
}),
134112
'set_level': dict({
135-
'description': '',
136113
'fields': dict({
137114
}),
138-
'name': '',
139115
}),
140116
})
141117
# ---

tests/components/websocket_api/test_commands.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -784,10 +784,6 @@ def _load_services_file(integration: Integration) -> JSON_TYPE:
784784
"homeassistant.helpers.service._load_services_file",
785785
side_effect=_load_services_file,
786786
),
787-
patch(
788-
"homeassistant.helpers.service.translation.async_get_translations",
789-
return_value={},
790-
),
791787
):
792788
await websocket_client.send_json_auto_id({"type": "get_services"})
793789
msg = await websocket_client.receive_json()

0 commit comments

Comments
 (0)