Make repairs out of select supervisor issues (#90893)

* Make repairs out of select supervisor issues

* Fix comment formatting

* Add a test case for API error

* Testing and type fix
This commit is contained in:
Mike Degatano 2023-04-19 02:07:38 -04:00 committed by GitHub
parent 6b5e82ed40
commit a511e7d6bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 1170 additions and 86 deletions

View file

@ -5,6 +5,7 @@ import asyncio
from http import HTTPStatus
import logging
import os
from typing import Any
import aiohttp
@ -249,6 +250,18 @@ async def async_update_core(
)
@bind_hass
@_api_bool
async def async_apply_suggestion(hass: HomeAssistant, suggestion_uuid: str) -> bool:
"""Apply a suggestion from supervisor's resolution center.
The caller of the function should handle HassioAPIError.
"""
hassio = hass.data[DOMAIN]
command = f"/resolution/suggestion/{suggestion_uuid}"
return await hassio.send_command(command, timeout=None)
class HassIO:
"""Small API wrapper for Hass.io."""
@ -416,6 +429,16 @@ class HassIO:
"""
return self.send_command("/resolution/info", method="get")
@api_data
def get_suggestions_for_issue(self, issue_id: str) -> dict[str, Any]:
"""Return suggestions for issue from Supervisor resolution center.
This method returns a coroutine.
"""
return self.send_command(
f"/resolution/issue/{issue_id}/suggestions", method="get"
)
@_api_bool
async def update_hass_api(self, http_config, refresh_token):
"""Update Home Assistant API data on Hass.io."""
@ -454,6 +477,14 @@ class HassIO:
"/supervisor/options", payload={"diagnostics": diagnostics}
)
@_api_bool
def apply_suggestion(self, suggestion_uuid: str):
"""Apply a suggestion from supervisor's resolution center.
This method returns a coroutine.
"""
return self.send_command(f"/resolution/suggestion/{suggestion_uuid}")
async def send_command(
self,
command,