Raise repairs issue if country is not configured (#82685)

This commit is contained in:
Erik Montnemery 2022-11-28 09:54:13 +01:00 committed by GitHub
parent b2b3e14810
commit 67e4f2c202
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 85 additions and 11 deletions

View File

@ -1,5 +1,9 @@
{
"issues": {
"country_not_configured": {
"title": "The country has not been configured",
"description": "No country has been configured, please update the configuration by clicking on the \"learn more\" button below."
},
"historic_currency": {
"title": "The configured currency is no longer in use",
"description": "The currency {currency} is no longer in use, please reconfigure the currency configuration."

View File

@ -1,5 +1,9 @@
{
"issues": {
"country_not_configured": {
"description": "No country has been configured, please update the configuration by clicking on the \"learn more\" button below.",
"title": "The country has not been configured"
},
"historic_currency": {
"description": "The currency {currency} is no longer in use, please reconfigure the currency configuration.",
"title": "The configured currency is no longer in use"

View File

@ -206,16 +206,36 @@ CUSTOMIZE_CONFIG_SCHEMA = vol.Schema(
def _raise_issue_if_historic_currency(hass: HomeAssistant, currency: str) -> None:
if currency in HISTORIC_CURRENCIES:
ir.async_create_issue(
hass,
"homeassistant",
"historic_currency",
is_fixable=False,
severity=ir.IssueSeverity.WARNING,
translation_key="historic_currency",
translation_placeholders={"currency": currency},
)
if currency not in HISTORIC_CURRENCIES:
ir.async_delete_issue(hass, "homeassistant", "historic_currency")
return
ir.async_create_issue(
hass,
"homeassistant",
"historic_currency",
is_fixable=False,
learn_more_url="homeassistant://config/general",
severity=ir.IssueSeverity.WARNING,
translation_key="historic_currency",
translation_placeholders={"currency": currency},
)
def _raise_issue_if_no_country(hass: HomeAssistant, country: str | None) -> None:
if country is not None:
ir.async_delete_issue(hass, "homeassistant", "country_not_configured")
return
ir.async_create_issue(
hass,
"homeassistant",
"country_not_configured",
is_fixable=False,
learn_more_url="homeassistant://config/general",
severity=ir.IssueSeverity.WARNING,
translation_key="country_not_configured",
)
def _validate_currency(data: Any) -> Any:
@ -587,6 +607,7 @@ async def async_process_ha_core_config(hass: HomeAssistant, config: dict) -> Non
setattr(hac, attr, config[key])
_raise_issue_if_historic_currency(hass, hass.config.currency)
_raise_issue_if_no_country(hass, hass.config.country)
if CONF_TIME_ZONE in config:
hac.set_time_zone(config[CONF_TIME_ZONE])

View File

@ -1976,10 +1976,19 @@ class Config:
async def async_update(self, **kwargs: Any) -> None:
"""Update the configuration from a dictionary."""
# pylint: disable-next=import-outside-toplevel
from .config import (
_raise_issue_if_historic_currency,
_raise_issue_if_no_country,
)
self._update(source=ConfigSource.STORAGE, **kwargs)
await self._async_store()
self.hass.bus.async_fire(EVENT_CORE_CONFIG_UPDATE, kwargs)
_raise_issue_if_historic_currency(self.hass, self.currency)
_raise_issue_if_no_country(self.hass, self.country)
async def async_load(self) -> None:
"""Load [homeassistant] core config."""
if not (data := await self._store.async_load()):

View File

@ -179,6 +179,7 @@ class TestComponentsCore(unittest.TestCase):
config.YAML_CONFIG_FILE: yaml.dump(
{
ha.DOMAIN: {
"country": "SE", # To avoid creating issue country_not_configured
"latitude": 10,
"longitude": 20,
"customize": {"test.Entity": {"hello": "world"}},

View File

@ -1315,6 +1315,41 @@ async def test_core_store_historic_currency(hass, hass_storage):
await config_util.async_process_ha_core_config(hass, {})
issue_registry = ir.async_get(hass)
issue = issue_registry.async_get_issue("homeassistant", "historic_currency")
issue_id = "historic_currency"
issue = issue_registry.async_get_issue("homeassistant", issue_id)
assert issue
assert issue.translation_placeholders == {"currency": "LTT"}
await hass.config.async_update(**{"currency": "EUR"})
issue = issue_registry.async_get_issue("homeassistant", issue_id)
assert not issue
async def test_core_config_schema_no_country(hass):
"""Test core config schema."""
await config_util.async_process_ha_core_config(hass, {})
issue_registry = ir.async_get(hass)
issue = issue_registry.async_get_issue("homeassistant", "country_not_configured")
assert issue
async def test_core_store_no_country(hass, hass_storage):
"""Test core config store."""
core_data = {
"data": {},
"key": "core.config",
"version": 1,
"minor_version": 1,
}
hass_storage["core.config"] = dict(core_data)
await config_util.async_process_ha_core_config(hass, {})
issue_registry = ir.async_get(hass)
issue_id = "country_not_configured"
issue = issue_registry.async_get_issue("homeassistant", issue_id)
assert issue
await hass.config.async_update(**{"country": "SE"})
issue = issue_registry.async_get_issue("homeassistant", issue_id)
assert not issue