Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make repairs out of select supervisor issues #90893

Merged
merged 4 commits into from
Apr 19, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Make repairs out of select supervisor issues
  • Loading branch information
mdegat01 committed Apr 18, 2023
commit eae02f88d94c74bf32c7ed0787519c20578f7edb
4 changes: 2 additions & 2 deletions homeassistant/components/hassio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@
DATA_KEY_HOST,
DATA_KEY_OS,
DATA_KEY_SUPERVISOR,
DATA_KEY_SUPERVISOR_ISSUES,
DOMAIN,
SupervisorEntityModel,
)
Expand Down Expand Up @@ -126,7 +127,6 @@
DATA_ADDONS_CHANGELOGS = "hassio_addons_changelogs"
DATA_ADDONS_INFO = "hassio_addons_info"
DATA_ADDONS_STATS = "hassio_addons_stats"
DATA_SUPERVISOR_ISSUES = "supervisor_issues"
HASSIO_UPDATE_INTERVAL = timedelta(minutes=5)

ADDONS_COORDINATOR = "hassio_addons_coordinator"
Expand Down Expand Up @@ -611,7 +611,7 @@ async def _async_setup_hardware_integration(hass):
)

# Start listening for problems with supervisor and making issues
hass.data[DATA_SUPERVISOR_ISSUES] = issues = SupervisorIssues(hass, hassio)
hass.data[DATA_KEY_SUPERVISOR_ISSUES] = issues = SupervisorIssues(hass, hassio)
await issues.setup()

return True
Expand Down
7 changes: 7 additions & 0 deletions homeassistant/components/hassio/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
ATTR_HEALTHY = "healthy"
ATTR_HOMEASSISTANT = "homeassistant"
ATTR_INPUT = "input"
ATTR_ISSUES = "issues"
ATTR_METHOD = "method"
ATTR_PANELS = "panels"
ATTR_PASSWORD = "password"
ATTR_RESULT = "result"
ATTR_SUGGESTIONS = "suggestions"
ATTR_SUPPORTED = "supported"
ATTR_TIMEOUT = "timeout"
ATTR_TITLE = "title"
Expand Down Expand Up @@ -49,6 +51,8 @@
EVENT_SUPERVISOR_UPDATE = "supervisor_update"
EVENT_HEALTH_CHANGED = "health_changed"
EVENT_SUPPORTED_CHANGED = "supported_changed"
EVENT_ISSUE_CHANGED = "issue_changed"
EVENT_ISSUE_REMOVED = "issue_removed"

UPDATE_KEY_SUPERVISOR = "supervisor"

Expand All @@ -69,6 +73,9 @@
DATA_KEY_SUPERVISOR = "supervisor"
DATA_KEY_CORE = "core"
DATA_KEY_HOST = "host"
DATA_KEY_SUPERVISOR_ISSUES = "supervisor_issues"

PLACEHOLDER_KEY_REFERENCE = "reference"


class SupervisorEntityModel(str, Enum):
Expand Down
31 changes: 31 additions & 0 deletions homeassistant/components/hassio/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from http import HTTPStatus
import logging
import os
from typing import Any

import aiohttp

Expand Down Expand Up @@ -249,6 +250,18 @@ async def async_update_core(
)


@bind_hass
@_api_bool
async def async_apply_suggestion(hass: HomeAssistant, suggestion_uuid: str) -> dict:
mdegat01 marked this conversation as resolved.
Show resolved Hide resolved
"""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."""

Expand Down Expand Up @@ -416,6 +429,16 @@ def get_resolution_info(self):
"""
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."""
Expand Down Expand Up @@ -454,6 +477,14 @@ def update_diagnostics(self, diagnostics: bool):
"/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,
Expand Down
Loading