Skip to content

Commit

Permalink
Return default repairs flow for cloud TTS issues (home-assistant#113981)
Browse files Browse the repository at this point in the history
* Set TTS repairs as not fixable

* Return default confirm flow for fixable cloud issues

* Depend on repairs

* Test default repair flow

---------

Co-authored-by: Martin Hjelmare <[email protected]>
  • Loading branch information
ludeeus and MartinHjelmare authored Mar 22, 2024
1 parent abb2170 commit a2143a7
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 7 deletions.
2 changes: 1 addition & 1 deletion homeassistant/components/cloud/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"name": "Home Assistant Cloud",
"after_dependencies": ["assist_pipeline", "google_assistant", "alexa"],
"codeowners": ["@home-assistant/cloud"],
"dependencies": ["http", "webhook"],
"dependencies": ["http", "repairs", "webhook"],
"documentation": "https://www.home-assistant.io/integrations/cloud",
"integration_type": "system",
"iot_class": "cloud_push",
Expand Down
10 changes: 8 additions & 2 deletions homeassistant/components/cloud/repairs.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@
from hass_nabucasa import Cloud
import voluptuous as vol

from homeassistant.components.repairs import RepairsFlow, repairs_flow_manager
from homeassistant.components.repairs import (
ConfirmRepairFlow,
RepairsFlow,
repairs_flow_manager,
)
from homeassistant.core import HomeAssistant, callback
from homeassistant.data_entry_flow import FlowResult
from homeassistant.helpers import issue_registry as ir
Expand Down Expand Up @@ -120,4 +124,6 @@ async def async_create_fix_flow(
data: dict[str, str | int | float | None] | None,
) -> RepairsFlow:
"""Create flow."""
return LegacySubscriptionRepairFlow()
if issue_id == "legacy_subscription":
return LegacySubscriptionRepairFlow()
return ConfirmRepairFlow()
91 changes: 87 additions & 4 deletions tests/components/cloud/test_tts.py
Original file line number Diff line number Diff line change
Expand Up @@ -526,16 +526,16 @@ async def test_deprecated_voice(
}
await hass.async_block_till_done()

issue_id = f"deprecated_voice_{deprecated_voice}"

assert mock_process_tts.call_count == 1
assert mock_process_tts.call_args is not None
assert mock_process_tts.call_args.kwargs["text"] == "There is someone at the door."
assert mock_process_tts.call_args.kwargs["language"] == language
assert mock_process_tts.call_args.kwargs["gender"] is None
assert mock_process_tts.call_args.kwargs["voice"] == replacement_voice
assert mock_process_tts.call_args.kwargs["output"] == "mp3"
issue = issue_registry.async_get_issue(
"cloud", f"deprecated_voice_{deprecated_voice}"
)
issue = issue_registry.async_get_issue("cloud", issue_id)
assert issue is not None
assert issue.breaks_in_ha_version == "2024.8.0"
assert issue.is_fixable is True
Expand All @@ -547,6 +547,46 @@ async def test_deprecated_voice(
"replacement_voice": replacement_voice,
}

resp = await client.post(
"/api/repairs/issues/fix",
json={"handler": DOMAIN, "issue_id": issue.issue_id},
)

assert resp.status == HTTPStatus.OK
data = await resp.json()

flow_id = data["flow_id"]
assert data == {
"type": "form",
"flow_id": flow_id,
"handler": DOMAIN,
"step_id": "confirm",
"data_schema": [],
"errors": None,
"description_placeholders": {
"deprecated_voice": "XiaoxuanNeural",
"replacement_voice": "XiaozhenNeural",
},
"last_step": None,
"preview": None,
}

resp = await client.post(f"/api/repairs/issues/fix/{flow_id}")

assert resp.status == HTTPStatus.OK
data = await resp.json()

flow_id = data["flow_id"]
assert data == {
"type": "create_entry",
"flow_id": flow_id,
"handler": DOMAIN,
"description": None,
"description_placeholders": None,
}

assert not issue_registry.async_get_issue(DOMAIN, issue_id)


@pytest.mark.parametrize(
("data", "expected_url_suffix"),
Expand Down Expand Up @@ -631,14 +671,16 @@ async def test_deprecated_gender(
}
await hass.async_block_till_done()

issue_id = "deprecated_gender"

assert mock_process_tts.call_count == 1
assert mock_process_tts.call_args is not None
assert mock_process_tts.call_args.kwargs["text"] == "There is someone at the door."
assert mock_process_tts.call_args.kwargs["language"] == language
assert mock_process_tts.call_args.kwargs["gender"] == gender_option
assert mock_process_tts.call_args.kwargs["voice"] == "JennyNeural"
assert mock_process_tts.call_args.kwargs["output"] == "mp3"
issue = issue_registry.async_get_issue("cloud", "deprecated_gender")
issue = issue_registry.async_get_issue("cloud", issue_id)
assert issue is not None
assert issue.breaks_in_ha_version == "2024.10.0"
assert issue.is_fixable is True
Expand All @@ -650,3 +692,44 @@ async def test_deprecated_gender(
"deprecated_option": "gender",
"replacement_option": "voice",
}

resp = await client.post(
"/api/repairs/issues/fix",
json={"handler": DOMAIN, "issue_id": issue.issue_id},
)

assert resp.status == HTTPStatus.OK
data = await resp.json()

flow_id = data["flow_id"]
assert data == {
"type": "form",
"flow_id": flow_id,
"handler": DOMAIN,
"step_id": "confirm",
"data_schema": [],
"errors": None,
"description_placeholders": {
"integration_name": "Home Assistant Cloud",
"deprecated_option": "gender",
"replacement_option": "voice",
},
"last_step": None,
"preview": None,
}

resp = await client.post(f"/api/repairs/issues/fix/{flow_id}")

assert resp.status == HTTPStatus.OK
data = await resp.json()

flow_id = data["flow_id"]
assert data == {
"type": "create_entry",
"flow_id": flow_id,
"handler": DOMAIN,
"description": None,
"description_placeholders": None,
}

assert not issue_registry.async_get_issue(DOMAIN, issue_id)

0 comments on commit a2143a7

Please sign in to comment.