Add test of get_all_descriptions resolving features (#120384)
This commit is contained in:
parent
744161928e
commit
6fb400f76b
1 changed files with 77 additions and 0 deletions
|
@ -971,6 +971,83 @@ async def test_async_get_all_descriptions_dot_keys(hass: HomeAssistant) -> None:
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
async def test_async_get_all_descriptions_filter(hass: HomeAssistant) -> None:
|
||||||
|
"""Test async_get_all_descriptions with filters."""
|
||||||
|
service_descriptions = """
|
||||||
|
test_service:
|
||||||
|
target:
|
||||||
|
entity:
|
||||||
|
domain: alarm_control_panel
|
||||||
|
supported_features:
|
||||||
|
- alarm_control_panel.AlarmControlPanelEntityFeature.ARM_HOME
|
||||||
|
fields:
|
||||||
|
temperature:
|
||||||
|
filter:
|
||||||
|
supported_features:
|
||||||
|
- alarm_control_panel.AlarmControlPanelEntityFeature.ARM_HOME
|
||||||
|
attribute:
|
||||||
|
supported_color_modes:
|
||||||
|
- light.ColorMode.COLOR_TEMP
|
||||||
|
selector:
|
||||||
|
number:
|
||||||
|
"""
|
||||||
|
|
||||||
|
domain = "test_domain"
|
||||||
|
|
||||||
|
hass.services.async_register(domain, "test_service", lambda call: None)
|
||||||
|
mock_integration(hass, MockModule(domain), top_level_files={"services.yaml"})
|
||||||
|
assert await async_setup_component(hass, domain, {})
|
||||||
|
|
||||||
|
def load_yaml(fname, secrets=None):
|
||||||
|
with io.StringIO(service_descriptions) as file:
|
||||||
|
return parse_yaml(file)
|
||||||
|
|
||||||
|
with (
|
||||||
|
patch(
|
||||||
|
"homeassistant.helpers.service._load_services_files",
|
||||||
|
side_effect=service._load_services_files,
|
||||||
|
) as proxy_load_services_files,
|
||||||
|
patch(
|
||||||
|
"homeassistant.util.yaml.loader.load_yaml",
|
||||||
|
side_effect=load_yaml,
|
||||||
|
) as mock_load_yaml,
|
||||||
|
):
|
||||||
|
descriptions = await service.async_get_all_descriptions(hass)
|
||||||
|
|
||||||
|
mock_load_yaml.assert_called_once_with("services.yaml", None)
|
||||||
|
assert proxy_load_services_files.mock_calls[0][1][1] == unordered(
|
||||||
|
[
|
||||||
|
await async_get_integration(hass, domain),
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
test_service_schema = {
|
||||||
|
"description": "",
|
||||||
|
"fields": {
|
||||||
|
"temperature": {
|
||||||
|
"filter": {
|
||||||
|
"attribute": {"supported_color_modes": ["color_temp"]},
|
||||||
|
"supported_features": [1],
|
||||||
|
},
|
||||||
|
"selector": {"number": None},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"name": "",
|
||||||
|
"target": {
|
||||||
|
"entity": [
|
||||||
|
{
|
||||||
|
"domain": ["alarm_control_panel"],
|
||||||
|
"supported_features": [1],
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
assert descriptions == {
|
||||||
|
"test_domain": {"test_service": test_service_schema},
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_async_get_all_descriptions_failing_integration(
|
async def test_async_get_all_descriptions_failing_integration(
|
||||||
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
hass: HomeAssistant, caplog: pytest.LogCaptureFixture
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue