Document the issue registry (#1447)

* Document the issue registry

* Apply suggestions from code review

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>

* Tweak language

Co-authored-by: Martin Hjelmare <marhje52@gmail.com>
This commit is contained in:
Erik Montnemery 2022-08-29 13:54:04 +02:00 committed by GitHub
parent 686b818df6
commit 63ce526339
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 113 additions and 0 deletions

View File

@ -0,0 +1,52 @@
---
title: "Repairs"
---
A fixable [repairs issue](/docs/issue_registry_index) may optionally be repaired by a custom repairs flow.
This is done by adding the function (`async_create_fix_flow`) to `repairs.py`
## Adding support
Create a new file in your integration folder called `repairs.py` and add code according to the pattern below.
```python
from __future__ import annotations
import voluptuous as vol
from homeassistant import data_entry_flow
from homeassistant.components.repairs import ConfirmRepairFlow, RepairsFlow
from homeassistant.core import HomeAssistant
class Issue1RepairFlow(RepairsFlow):
"""Handler for an issue fixing flow."""
async def async_step_init(
self, user_input: dict[str, str] | None = None
) -> data_entry_flow.FlowResult:
"""Handle the first step of a fix flow."""
return await (self.async_step_confirm())
async def async_step_confirm(
self, user_input: dict[str, str] | None = None
) -> data_entry_flow.FlowResult:
"""Handle the confirm step of a fix flow."""
if user_input is not None:
return self.async_create_entry(title="", data={})
return self.async_show_form(step_id="confirm", data_schema=vol.Schema({}))
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 == "issue_1":
return Issue1RepairFlow()
```

View File

@ -0,0 +1,54 @@
---
title: Repairs Issue Registry
---
The repairs issue registry is a registry where Home Assistant keeps track of repairs issues which should be brought to the user's attention.
## Issue properties
| Attribute | Type | Default | Description |
| --------- | -------- | ------- | ----------- |
| domain | string | | Domain raising the issue
| issue_id | string | | An identifier for the issue, must be unique within `domain`
| breaks_in_ha_version | string | `None` | The version in which the issue is breaking
| data | dict | `None` | Arbitrary data, not shown to the user
| is_fixable | boolean | | True if the issue can be automatically fixed
| is_persistent | boolean | | True if the issue should persists across restarts of Home Assistant
| issue_domain | string | `None` | Set by integrations creating issues on behalf of other integrations
| learn_more_url | string | `None` | URL where the user can find more details about an issue
| severity | IssueSeverity | | Severity of the issue
| translation_key | str | | Translation key with a brief explanation of the issue
| translation_placeholders | dict | `None` | Placeholders which will be injected in the translation
## Creating an issue
```python
from homeassistant.helpers import issue_registry as ir
ir.async_create_issue(
hass,
DOMAIN,
"manual_migration",
breaks_in_ha_version="2022.9.0",
is_fixable=False,
severity=IssueSeverity.ERROR,
translation_key="manual_migration",
)
```
## Deleting an issue
Integrations typically don't need to delete issues, but it may be useful in some cases.
```python
from homeassistant.helpers import issue_registry as ir
ir.async_delete_issue(hass, DOMAIN, "manual_migration")
```
## Fixing an issue
If an issue has the `is_fixable` issue set to `True`, the user will be allowed to fix the issue. An issue which is succesfully fixed will be removed from the issue registry.
If the integration can perform some steps to fix an issue or to verify that the user has made the necessary manual steps, it should implement a [`repairs` platform](/docs/core/platform/repairs.md).
In some cases, fixing an issue may be done by the user by performing some manual steps which can't be verified by the integration, and no repairs platform is needed.

View File

@ -165,6 +165,13 @@ module.exports = {
dirName: 'core/platform',
},
],
Registries: [
"area_registry_index",
"device_registry_index",
"entity_registry_index",
"entity_registry_disabled_by",
"issue_registry_index",
],
"Device Automations": [
"device_automation_index",
"device_automation_trigger",