Skip to content

Commit

Permalink
Fix from feedback on supervisor issues to repairs
Browse files Browse the repository at this point in the history
  • Loading branch information
mdegat01 committed Apr 19, 2023
1 parent 090f59a commit 270d77b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
15 changes: 8 additions & 7 deletions homeassistant/components/hassio/issues.py
Expand Up @@ -115,8 +115,8 @@ def key(self) -> str:
"""Get key for suggestion (combination of context and type)."""
return f"{self.context}_{self.type_}"

@staticmethod
def from_dict(data: SuggestionDataType) -> Suggestion:
@classmethod
def from_dict(cls, data: SuggestionDataType) -> Suggestion:
"""Convert from dictionary representation."""
return Suggestion(
uuid=data["uuid"],
Expand Down Expand Up @@ -151,8 +151,8 @@ def key(self) -> str:
"""Get key for issue (combination of context and type)."""
return f"issue_{self.context}_{self.type_}"

@staticmethod
def from_dict(data: IssueDataType) -> Issue:
@classmethod
def from_dict(cls, data: IssueDataType) -> Issue:
"""Convert from dictionary representation."""
suggestions: list[SuggestionDataType] = data.get("suggestions", [])
return Issue(
Expand Down Expand Up @@ -244,16 +244,17 @@ def unsupported_reasons(self, reasons: set[str]) -> None:
def add_issue(self, issue: Issue) -> None:
"""Add or update an issue in the list. Create or update a repair if necessary."""
if issue.key in ISSUE_KEYS_FOR_REPAIRS:
placeholders: dict[str, str] | None = None
if issue.reference:
placeholders = {PLACEHOLDER_KEY_REFERENCE: issue.reference}
async_create_issue(
self._hass,
DOMAIN,
issue.uuid,
is_fixable=bool(issue.suggestions),
severity=IssueSeverity.WARNING,
translation_key=issue.key,
translation_placeholders={PLACEHOLDER_KEY_REFERENCE: issue.reference}
if issue.reference
else None,
translation_placeholders=placeholders,
)

self._issues[issue.uuid] = issue
Expand Down
9 changes: 5 additions & 4 deletions homeassistant/components/hassio/repairs.py
Expand Up @@ -59,12 +59,13 @@ def _async_form_for_suggestion(self, suggestion: Suggestion) -> FlowResult:

async def async_step_init(self, _: None = None) -> FlowResult:
"""Handle the first step of a fix flow."""
# Got out of sync with supervisor, issue is resolved or isn't fixable. Either way, resolve the repair
# Out of sync with supervisor, issue is resolved or not fixable. Remove it
if not self.issue or not self.issue.suggestions:
return self.async_create_entry(data={})

# All suggestions do the same thing: apply them in supervisor, optionally with a confirmation step.
# Generating the required handler for each allows for shared logic but screens can still be translated per step id.
# All suggestions have the same logic: Apply them in supervisor,
# optionally with a confirmation step. Generating the required handler for each
# allows for shared logic but screens can still be translated per step id.
for suggestion in self.issue.suggestions:
setattr(
self,
Expand All @@ -79,7 +80,7 @@ async def async_step_init(self, _: None = None) -> FlowResult:
description_placeholders=self.description_placeholders,
)

# Always show a form if there's only one suggestion so we can explain to the user what's happening
# Always show a form for one suggestion to explain to user what's happening
return self._async_form_for_suggestion(self.issue.suggestions[0])

async def _async_step_apply_suggestion(
Expand Down

0 comments on commit 270d77b

Please sign in to comment.