|
16 | 16 | from homeassistant.auth.permissions import PolicyPermissions |
17 | 17 | import homeassistant.components # noqa: F401 |
18 | 18 | from homeassistant.components.group import DOMAIN as DOMAIN_GROUP, Group |
| 19 | +from homeassistant.components.input_button import DOMAIN as DOMAIN_INPUT_BUTTON |
19 | 20 | from homeassistant.components.logger import DOMAIN as DOMAIN_LOGGER |
20 | 21 | from homeassistant.components.shell_command import DOMAIN as DOMAIN_SHELL_COMMAND |
21 | 22 | from homeassistant.components.system_health import DOMAIN as DOMAIN_SYSTEM_HEALTH |
|
42 | 43 | entity_registry as er, |
43 | 44 | service, |
44 | 45 | ) |
45 | | -from homeassistant.loader import async_get_integration |
| 46 | +from homeassistant.helpers.translation import async_get_translations |
| 47 | +from homeassistant.loader import ( |
| 48 | + Integration, |
| 49 | + async_get_integration, |
| 50 | + async_get_integrations, |
| 51 | +) |
46 | 52 | from homeassistant.setup import async_setup_component |
47 | 53 | from homeassistant.util.yaml.loader import parse_yaml |
48 | 54 |
|
@@ -1092,38 +1098,66 @@ async def test_async_get_all_descriptions_failing_integration( |
1092 | 1098 | """Test async_get_all_descriptions when async_get_integrations returns an exception.""" |
1093 | 1099 | group_config = {DOMAIN_GROUP: {}} |
1094 | 1100 | await async_setup_component(hass, DOMAIN_GROUP, group_config) |
1095 | | - descriptions = await service.async_get_all_descriptions(hass) |
1096 | | - |
1097 | | - assert len(descriptions) == 1 |
1098 | | - |
1099 | | - assert "description" in descriptions["group"]["reload"] |
1100 | | - assert "fields" in descriptions["group"]["reload"] |
1101 | 1101 |
|
1102 | 1102 | logger_config = {DOMAIN_LOGGER: {}} |
1103 | 1103 | await async_setup_component(hass, DOMAIN_LOGGER, logger_config) |
| 1104 | + |
| 1105 | + input_button_config = {DOMAIN_INPUT_BUTTON: {}} |
| 1106 | + await async_setup_component(hass, DOMAIN_INPUT_BUTTON, input_button_config) |
| 1107 | + |
| 1108 | + async def wrap_get_integrations( |
| 1109 | + hass: HomeAssistant, domains: Iterable[str] |
| 1110 | + ) -> dict[str, Integration | Exception]: |
| 1111 | + integrations = await async_get_integrations(hass, domains) |
| 1112 | + integrations[DOMAIN_LOGGER] = ImportError("Failed to load services.yaml") |
| 1113 | + return integrations |
| 1114 | + |
| 1115 | + async def wrap_get_translations( |
| 1116 | + hass: HomeAssistant, |
| 1117 | + language: str, |
| 1118 | + category: str, |
| 1119 | + integrations: Iterable[str] | None = None, |
| 1120 | + config_flow: bool | None = None, |
| 1121 | + ) -> dict[str, str]: |
| 1122 | + translations = await async_get_translations( |
| 1123 | + hass, language, category, integrations, config_flow |
| 1124 | + ) |
| 1125 | + return { |
| 1126 | + key: value |
| 1127 | + for key, value in translations.items() |
| 1128 | + if not key.startswith("component.logger.services.") |
| 1129 | + } |
| 1130 | + |
1104 | 1131 | with ( |
1105 | 1132 | patch( |
1106 | 1133 | "homeassistant.helpers.service.async_get_integrations", |
1107 | | - return_value={"logger": ImportError}, |
| 1134 | + wraps=wrap_get_integrations, |
1108 | 1135 | ), |
1109 | 1136 | patch( |
1110 | 1137 | "homeassistant.helpers.service.translation.async_get_translations", |
1111 | | - return_value={}, |
| 1138 | + wrap_get_translations, |
1112 | 1139 | ), |
1113 | 1140 | ): |
1114 | 1141 | descriptions = await service.async_get_all_descriptions(hass) |
1115 | 1142 |
|
1116 | | - assert len(descriptions) == 2 |
| 1143 | + assert len(descriptions) == 3 |
1117 | 1144 | assert "Failed to load integration: logger" in caplog.text |
1118 | 1145 |
|
1119 | 1146 | # Services are empty defaults if the load fails but should |
1120 | 1147 | # not raise |
| 1148 | + assert descriptions[DOMAIN_GROUP]["remove"]["description"] |
| 1149 | + assert descriptions[DOMAIN_GROUP]["remove"]["fields"] |
| 1150 | + |
1121 | 1151 | assert descriptions[DOMAIN_LOGGER]["set_level"] == { |
1122 | 1152 | "description": "", |
1123 | 1153 | "fields": {}, |
1124 | 1154 | "name": "", |
1125 | 1155 | } |
1126 | 1156 |
|
| 1157 | + assert descriptions[DOMAIN_INPUT_BUTTON]["press"]["description"] |
| 1158 | + assert descriptions[DOMAIN_INPUT_BUTTON]["press"]["fields"] == {} |
| 1159 | + assert "target" in descriptions[DOMAIN_INPUT_BUTTON]["press"] |
| 1160 | + |
1127 | 1161 | hass.services.async_register(DOMAIN_LOGGER, "new_service", lambda x: None, None) |
1128 | 1162 | service.async_set_service_schema( |
1129 | 1163 | hass, DOMAIN_LOGGER, "new_service", {"description": "new service"} |
|
0 commit comments