Skip to content

Commit

Permalink
Add async_create_repair_issue to CloudClient (#536)
Browse files Browse the repository at this point in the history
* Add async_create_repair_issue to CloudClient

* update mock

* lint

* Simplify

* lint

* Use similar arguments as core
  • Loading branch information
ludeeus authored Dec 13, 2023
1 parent 5377784 commit 98deb38
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
13 changes: 12 additions & 1 deletion hass_nabucasa/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
from abc import ABC, abstractmethod
import asyncio
from pathlib import Path
from typing import TYPE_CHECKING, Any
from typing import TYPE_CHECKING, Any, Literal

import aiohttp
from aiohttp import web
Expand Down Expand Up @@ -113,3 +113,14 @@ def dispatcher_message(self, identifier: str, data: Any = None) -> None:
@abstractmethod
def user_message(self, identifier: str, title: str, message: str) -> None:
"""Create a message for user to UI."""

@abstractmethod
async def async_create_repair_issue(
self,
identifier: str,
translation_key: str,
*,
placeholders: dict[str, str] | None = None,
severity: Literal["error", "warning"] = "warning",
) -> None:
"""Create a repair issue."""
20 changes: 19 additions & 1 deletion tests/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import asyncio
from pathlib import Path
import tempfile
from typing import Any, Coroutine
from typing import Any, Coroutine, Literal
from unittest.mock import Mock

from hass_nabucasa.client import CloudClient
Expand All @@ -27,6 +27,7 @@ def __init__(self, loop, websession):
self.mock_google = []
self.mock_webhooks = []
self.mock_system = []
self.mock_repairs = []
self.mock_connection_info = []

self.mock_return = []
Expand Down Expand Up @@ -127,6 +128,23 @@ async def async_cloudhooks_update(self, data):
"""Update internal cloudhooks data."""
self._cloudhooks = data

async def async_create_repair_issue(
self,
identifier: str,
translation_key: str,
*,
placeholders: dict[str, str] | None = None,
severity: Literal["error", "warning"] = "warning",
) -> None:
self.mock_repairs.append(
{
"identifier": identifier,
"translation_key": translation_key,
"placeholders": placeholders,
"severity": severity,
}
)


class MockAcme:
"""Mock AcmeHandler."""
Expand Down

0 comments on commit 98deb38

Please sign in to comment.