1 """The repairs websocket API."""
3 from __future__
import annotations
5 from http
import HTTPStatus
8 from aiohttp
import web
9 import voluptuous
as vol
11 from homeassistant
import data_entry_flow
21 FlowManagerResourceView,
24 from .const
import DOMAIN
29 """Set up the repairs websocket API."""
30 websocket_api.async_register_command(hass, ws_get_issue_data)
31 websocket_api.async_register_command(hass, ws_ignore_issue)
32 websocket_api.async_register_command(hass, ws_list_issues)
39 @websocket_api.websocket_command(
{
vol.Required("type"):
"repairs/get_issue_data",
40 vol.Required(
"domain"): str,
41 vol.Required(
"issue_id"): str,
48 issue_registry = ir.async_get(hass)
49 if not (issue := issue_registry.async_get_issue(msg[
"domain"], msg[
"issue_id"])):
50 connection.send_error(
53 f
"Issue '{msg['issue_id']}' not found",
56 connection.send_result(msg[
"id"], {
"issue_data": issue.data})
60 @websocket_api.websocket_command(
{
vol.Required("type"):
"repairs/ignore_issue",
61 vol.Required(
"domain"): str,
62 vol.Required(
"issue_id"): str,
63 vol.Required(
"ignore"): bool,
70 ir.async_ignore_issue(hass, msg[
"domain"], msg[
"issue_id"], msg[
"ignore"])
72 connection.send_result(msg[
"id"])
75 @websocket_api.websocket_command(
{
vol.Required("type"):
"repairs/list_issues",
82 """Return a list of issues."""
83 issue_registry = ir.async_get(hass)
86 "breaks_in_ha_version": issue.breaks_in_ha_version,
87 "created": issue.created,
88 "dismissed_version": issue.dismissed_version,
89 "ignored": issue.dismissed_version
is not None,
90 "domain": issue.domain,
91 "is_fixable": issue.is_fixable,
92 "issue_domain": issue.issue_domain,
93 "issue_id": issue.issue_id,
94 "learn_more_url": issue.learn_more_url,
95 "severity": issue.severity,
96 "translation_key": issue.translation_key,
97 "translation_placeholders": issue.translation_placeholders,
99 for issue
in issue_registry.issues.values()
102 connection.send_result(msg[
"id"], {
"issues": issues})
106 """View to create issue fix flows."""
108 url =
"/api/repairs/issues/fix"
109 name =
"api:repairs:issues:fix"
111 @require_admin(error=Unauthorized(permission=POLICY_EDIT))
112 @RequestDataValidator(
vol.Schema(
{
vol.Required("handler"): str,
113 vol.Required(
"issue_id"): str,
115 extra=vol.ALLOW_EXTRA,
118 async
def post(self, request: web.Request, data: dict[str, Any]) -> web.Response:
119 """Handle a POST request."""
123 data={
"issue_id": data[
"issue_id"]},
126 return self.json_message(
"Invalid handler specified", HTTPStatus.NOT_FOUND)
128 return self.json_message(
129 "Handler does not support user", HTTPStatus.BAD_REQUEST
134 return self.json(result)
138 """View to interact with the option flow manager."""
140 url =
"/api/repairs/issues/fix/{flow_id}"
141 name =
"api:repairs:issues:fix:resource"
143 @require_admin(error=Unauthorized(permission=POLICY_EDIT))
144 async
def get(self, request: web.Request, /, flow_id: str) -> web.Response:
145 """Get the current state of a data_entry_flow."""
146 return await super().
get(request, flow_id)
148 @require_admin(error=Unauthorized(permission=POLICY_EDIT))
149 async
def post(self, request: web.Request, flow_id: str) -> web.Response:
150 """Handle a POST request."""
151 return await super().
post(request, flow_id)
152
web.Response post(self, web.Request request, dict[str, Any] data)
web.Response post(self, web.Request request, str flow_id)
web.Response get(self, web.Request request, str flow_id)
data_entry_flow.FlowResult _prepare_result_json(self, data_entry_flow.FlowResult result)
web.Response get(self, web.Request request, str config_key)
None ws_get_issue_data(HomeAssistant hass, websocket_api.ActiveConnection connection, dict[str, Any] msg)
None async_setup(HomeAssistant hass)
None ws_ignore_issue(HomeAssistant hass, websocket_api.ActiveConnection connection, dict[str, Any] msg)
None ws_list_issues(HomeAssistant hass, websocket_api.ActiveConnection connection, dict[str, Any] msg)