From 24fe6dfc63a70f414f22cfdf861d3bdb7a333c32 Mon Sep 17 00:00:00 2001 From: Mike Degatano Date: Wed, 19 Apr 2023 19:02:40 -0400 Subject: [PATCH] Fix from feedback on supervisor issues to repairs (#91680) * Fix from feedback on supervisor issues to repairs * Use cls parameter in classmethods --- homeassistant/components/hassio/issues.py | 19 ++++++++++--------- homeassistant/components/hassio/repairs.py | 9 +++++---- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/homeassistant/components/hassio/issues.py b/homeassistant/components/hassio/issues.py index c460731ad39..ac6af7f3489 100644 --- a/homeassistant/components/hassio/issues.py +++ b/homeassistant/components/hassio/issues.py @@ -115,10 +115,10 @@ class Suggestion: """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( + return cls( uuid=data["uuid"], type_=data["type"], context=data["context"], @@ -151,11 +151,11 @@ class Issue: """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( + return cls( uuid=data["uuid"], type_=data["type"], context=data["context"], @@ -244,6 +244,9 @@ class SupervisorIssues: 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, @@ -251,9 +254,7 @@ class SupervisorIssues: 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 diff --git a/homeassistant/components/hassio/repairs.py b/homeassistant/components/hassio/repairs.py index 5040243cc8d..50a9b087a7c 100644 --- a/homeassistant/components/hassio/repairs.py +++ b/homeassistant/components/hassio/repairs.py @@ -59,12 +59,13 @@ class SupervisorIssueRepairFlow(RepairsFlow): 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, @@ -79,7 +80,7 @@ class SupervisorIssueRepairFlow(RepairsFlow): 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(