From 5b4000e7595e49b636ac81f3191701609c90fd7e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joakim=20S=C3=B8rensen?= Date: Tue, 19 Dec 2023 13:08:27 +0100 Subject: [PATCH] Bump hass-nabucasa from 0.74.0 to 0.75.1 (#105958) * Bump hass-nabucasa from 0.74.0 to 0.75.1 * Force sorting of parametrized test * Simplify async_create_issue.severity * use fixtures --- homeassistant/components/cloud/client.py | 29 +++++++++++- homeassistant/components/cloud/manifest.json | 2 +- homeassistant/components/cloud/strings.json | 8 ++++ homeassistant/package_constraints.txt | 2 +- requirements_all.txt | 2 +- requirements_test_all.txt | 2 +- tests/components/cloud/test_client.py | 49 +++++++++++++++++++- 7 files changed, 88 insertions(+), 6 deletions(-) diff --git a/homeassistant/components/cloud/client.py b/homeassistant/components/cloud/client.py index 019936869a1..cef3c5f0d42 100644 --- a/homeassistant/components/cloud/client.py +++ b/homeassistant/components/cloud/client.py @@ -6,7 +6,7 @@ from datetime import datetime from http import HTTPStatus import logging from pathlib import Path -from typing import Any +from typing import Any, Literal import aiohttp from hass_nabucasa.client import CloudClient as Interface @@ -22,12 +22,18 @@ from homeassistant.core import Context, HassJob, HomeAssistant, callback from homeassistant.helpers.aiohttp_client import SERVER_SOFTWARE from homeassistant.helpers.dispatcher import async_dispatcher_send from homeassistant.helpers.event import async_call_later +from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from homeassistant.util.aiohttp import MockRequest, serialize_response from . import alexa_config, google_config from .const import DISPATCHER_REMOTE_UPDATE, DOMAIN from .prefs import CloudPreferences +VALID_REPAIR_TRANSLATION_KEYS = { + "warn_bad_custom_domain_configuration", + "reset_bad_custom_domain_configuration", +} + class CloudClient(Interface): """Interface class for Home Assistant Cloud.""" @@ -302,3 +308,24 @@ class CloudClient(Interface): ) -> None: """Update local list of cloudhooks.""" await self._prefs.async_update(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: + """Create a repair issue.""" + if translation_key not in VALID_REPAIR_TRANSLATION_KEYS: + raise ValueError(f"Invalid translation key {translation_key}") + async_create_issue( + hass=self._hass, + domain=DOMAIN, + issue_id=identifier, + translation_key=translation_key, + translation_placeholders=placeholders, + severity=IssueSeverity(severity), + is_fixable=False, + ) diff --git a/homeassistant/components/cloud/manifest.json b/homeassistant/components/cloud/manifest.json index 6d5c954361b..f7337e1d771 100644 --- a/homeassistant/components/cloud/manifest.json +++ b/homeassistant/components/cloud/manifest.json @@ -8,5 +8,5 @@ "integration_type": "system", "iot_class": "cloud_push", "loggers": ["hass_nabucasa"], - "requirements": ["hass-nabucasa==0.74.0"] + "requirements": ["hass-nabucasa==0.75.1"] } diff --git a/homeassistant/components/cloud/strings.json b/homeassistant/components/cloud/strings.json index 9c1f29cfcaf..8195b78a01e 100644 --- a/homeassistant/components/cloud/strings.json +++ b/homeassistant/components/cloud/strings.json @@ -30,6 +30,14 @@ "operation_took_too_long": "The operation took too long. Please try again later." } } + }, + "warn_bad_custom_domain_configuration": { + "title": "Detected wrong custom domain configuration", + "description": "The DNS configuration for your custom domain ({custom_domains}) is not correct. Please check the DNS configuration of your domain and make sure it points to the correct CNAME." + }, + "reset_bad_custom_domain_configuration": { + "title": "Custom domain ignored", + "description": "The DNS configuration for your custom domain ({custom_domains}) is not correct. This domain has now been ignored and will not be used for Home Assistant Cloud. If you want to use this domain, please fix the DNS configuration and restart Home Assistant. If you do not need this anymore, you can remove it from the account page." } }, "services": { diff --git a/homeassistant/package_constraints.txt b/homeassistant/package_constraints.txt index 9a1af1fe9f5..88f7937bb12 100644 --- a/homeassistant/package_constraints.txt +++ b/homeassistant/package_constraints.txt @@ -24,7 +24,7 @@ fnv-hash-fast==0.5.0 ha-av==10.1.1 ha-ffmpeg==3.1.0 habluetooth==1.0.0 -hass-nabucasa==0.74.0 +hass-nabucasa==0.75.1 hassil==1.5.1 home-assistant-bluetooth==1.11.0 home-assistant-frontend==20231208.2 diff --git a/requirements_all.txt b/requirements_all.txt index cba45c91a21..9ba43eb0ef6 100644 --- a/requirements_all.txt +++ b/requirements_all.txt @@ -992,7 +992,7 @@ habitipy==0.2.0 habluetooth==1.0.0 # homeassistant.components.cloud -hass-nabucasa==0.74.0 +hass-nabucasa==0.75.1 # homeassistant.components.splunk hass-splunk==0.1.1 diff --git a/requirements_test_all.txt b/requirements_test_all.txt index a7e721ab20a..ca091ec8321 100644 --- a/requirements_test_all.txt +++ b/requirements_test_all.txt @@ -791,7 +791,7 @@ habitipy==0.2.0 habluetooth==1.0.0 # homeassistant.components.cloud -hass-nabucasa==0.74.0 +hass-nabucasa==0.75.1 # homeassistant.components.conversation hassil==1.5.1 diff --git a/tests/components/cloud/test_client.py b/tests/components/cloud/test_client.py index ff718262b10..0cd605fd755 100644 --- a/tests/components/cloud/test_client.py +++ b/tests/components/cloud/test_client.py @@ -7,7 +7,10 @@ from aiohttp import web import pytest from homeassistant.components.cloud import DOMAIN -from homeassistant.components.cloud.client import CloudClient +from homeassistant.components.cloud.client import ( + VALID_REPAIR_TRANSLATION_KEYS, + CloudClient, +) from homeassistant.components.cloud.const import ( PREF_ALEXA_REPORT_STATE, PREF_ENABLE_ALEXA, @@ -21,6 +24,7 @@ from homeassistant.components.homeassistant.exposed_entities import ( from homeassistant.const import CONTENT_TYPE_JSON, __version__ as HA_VERSION from homeassistant.core import HomeAssistant, State from homeassistant.helpers import entity_registry as er +from homeassistant.helpers.issue_registry import IssueRegistry from homeassistant.setup import async_setup_component from homeassistant.util import dt as dt_util @@ -381,3 +385,46 @@ async def test_cloud_connection_info(hass: HomeAssistant) -> None: "version": HA_VERSION, "instance_id": "12345678901234567890", } + + +@pytest.mark.parametrize( + "translation_key", + sorted(VALID_REPAIR_TRANSLATION_KEYS), +) +async def test_async_create_repair_issue_known( + cloud: MagicMock, + mock_cloud_setup: None, + issue_registry: IssueRegistry, + translation_key: str, +) -> None: + """Test create repair issue for known repairs.""" + identifier = f"test_identifier_{translation_key}" + await cloud.client.async_create_repair_issue( + identifier=identifier, + translation_key=translation_key, + placeholders={"custom_domains": "example.com"}, + severity="warning", + ) + issue = issue_registry.async_get_issue(domain=DOMAIN, issue_id=identifier) + assert issue is not None + + +async def test_async_create_repair_issue_unknown( + cloud: MagicMock, + mock_cloud_setup: None, + issue_registry: IssueRegistry, +) -> None: + """Test not creating repair issue for unknown repairs.""" + identifier = "abc123" + with pytest.raises( + ValueError, + match="Invalid translation key unknown_translation_key", + ): + await cloud.client.async_create_repair_issue( + identifier=identifier, + translation_key="unknown_translation_key", + placeholders={"custom_domains": "example.com"}, + severity="error", + ) + issue = issue_registry.async_get_issue(domain=DOMAIN, issue_id=identifier) + assert issue is None