-
-
Notifications
You must be signed in to change notification settings - Fork 30.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add issue asking users to disable ESPHome assist_in_progress sensor (#…
…125805) * Add issue asking users to disable ESPHome assist_in_progress binary sensor * Include integration name in title and description * Add repair flow * Improve test coverage
- Loading branch information
1 parent
9bfc2ea
commit 6cd99e4
Showing
9 changed files
with
285 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
"""Repairs implementation for the cloud integration.""" | ||
|
||
from __future__ import annotations | ||
|
||
from typing import cast | ||
|
||
import voluptuous as vol | ||
|
||
from homeassistant.components.assist_satellite import DOMAIN as ASSIST_SATELLITE_DOMAIN | ||
from homeassistant.components.repairs import RepairsFlow | ||
from homeassistant.data_entry_flow import FlowResult | ||
from homeassistant.helpers import entity_registry as er | ||
|
||
REQUIRED_KEYS = ("entity_id", "entity_uuid", "integration_name") | ||
|
||
|
||
class AssistInProgressDeprecatedRepairFlow(RepairsFlow): | ||
"""Handler for an issue fixing flow.""" | ||
|
||
def __init__(self, data: dict[str, str | int | float | None] | None) -> None: | ||
"""Initialize.""" | ||
if not data or any(key not in data for key in REQUIRED_KEYS): | ||
raise ValueError("Missing data") | ||
self._data = data | ||
|
||
async def async_step_init(self, _: None = None) -> FlowResult: | ||
"""Handle the first step of a fix flow.""" | ||
return await self.async_step_confirm_disable_entity() | ||
|
||
async def async_step_confirm_disable_entity( | ||
self, | ||
user_input: dict[str, str] | None = None, | ||
) -> FlowResult: | ||
"""Handle the confirm step of a fix flow.""" | ||
if user_input is not None: | ||
entity_registry = er.async_get(self.hass) | ||
entity_entry = entity_registry.async_get( | ||
cast(str, self._data["entity_uuid"]) | ||
) | ||
if entity_entry: | ||
entity_registry.async_update_entity( | ||
entity_entry.entity_id, disabled_by=er.RegistryEntryDisabler.USER | ||
) | ||
return self.async_create_entry(data={}) | ||
|
||
description_placeholders: dict[str, str] = { | ||
"assist_satellite_domain": ASSIST_SATELLITE_DOMAIN, | ||
"entity_id": cast(str, self._data["entity_id"]), | ||
"integration_name": cast(str, self._data["integration_name"]), | ||
} | ||
return self.async_show_form( | ||
step_id="confirm_disable_entity", | ||
data_schema=vol.Schema({}), | ||
description_placeholders=description_placeholders, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
"""Repairs implementation for the cloud integration.""" | ||
|
||
from __future__ import annotations | ||
|
||
from homeassistant.components.assist_pipeline.repair_flows import ( | ||
AssistInProgressDeprecatedRepairFlow, | ||
) | ||
from homeassistant.components.repairs import RepairsFlow | ||
from homeassistant.core import HomeAssistant | ||
|
||
|
||
async def async_create_fix_flow( | ||
hass: HomeAssistant, | ||
issue_id: str, | ||
data: dict[str, str | int | float | None] | None, | ||
) -> RepairsFlow: | ||
"""Create flow.""" | ||
if issue_id.startswith("assist_in_progress_deprecated"): | ||
return AssistInProgressDeprecatedRepairFlow(data) | ||
# If ESPHome adds confirm-only repairs in the future, this should be changed | ||
# to return a ConfirmRepairFlow instead of raising a ValueError | ||
raise ValueError(f"unknown repair {issue_id}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""Test repair flows.""" | ||
|
||
import pytest | ||
|
||
from homeassistant.components.assist_pipeline.repair_flows import ( | ||
AssistInProgressDeprecatedRepairFlow, | ||
) | ||
|
||
|
||
@pytest.mark.parametrize( | ||
"data", [None, {}, {"entity_id": "blah", "entity_uuid": "12345"}] | ||
) | ||
def test_assist_in_progress_deprecated_flow_requires_data(data: dict | None) -> None: | ||
"""Test AssistInProgressDeprecatedRepairFlow requires data.""" | ||
|
||
with pytest.raises(ValueError): | ||
AssistInProgressDeprecatedRepairFlow(data) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
"""Test ESPHome binary sensors.""" | ||
|
||
import pytest | ||
|
||
from homeassistant.components.esphome import repairs | ||
from homeassistant.core import HomeAssistant | ||
|
||
|
||
async def test_create_fix_flow_raises_on_unknown_issue_id(hass: HomeAssistant) -> None: | ||
"""Test reate_fix_flow raises on unknown issue_id.""" | ||
|
||
with pytest.raises(ValueError): | ||
await repairs.async_create_fix_flow(hass, "no_such_issue", None) |