Fix GDACS import issue creation (#97667)
This commit is contained in:
parent
10dcdbf537
commit
adc7fc0ee4
3 changed files with 68 additions and 20 deletions
|
@ -13,11 +13,10 @@ from homeassistant.const import (
|
||||||
CONF_SCAN_INTERVAL,
|
CONF_SCAN_INTERVAL,
|
||||||
UnitOfLength,
|
UnitOfLength,
|
||||||
)
|
)
|
||||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant, callback
|
from homeassistant.core import HomeAssistant, callback
|
||||||
from homeassistant.helpers import aiohttp_client, config_validation as cv
|
from homeassistant.helpers import aiohttp_client, config_validation as cv
|
||||||
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
from homeassistant.helpers.dispatcher import async_dispatcher_send
|
||||||
from homeassistant.helpers.event import async_track_time_interval
|
from homeassistant.helpers.event import async_track_time_interval
|
||||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
|
||||||
from homeassistant.helpers.typing import ConfigType
|
from homeassistant.helpers.typing import ConfigType
|
||||||
from homeassistant.util.unit_conversion import DistanceConverter
|
from homeassistant.util.unit_conversion import DistanceConverter
|
||||||
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
from homeassistant.util.unit_system import US_CUSTOMARY_SYSTEM
|
||||||
|
@ -78,21 +77,6 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
async_create_issue(
|
|
||||||
hass,
|
|
||||||
HOMEASSISTANT_DOMAIN,
|
|
||||||
f"deprecated_yaml_{DOMAIN}",
|
|
||||||
breaks_in_ha_version="2024.2.0",
|
|
||||||
is_fixable=False,
|
|
||||||
issue_domain=DOMAIN,
|
|
||||||
severity=IssueSeverity.WARNING,
|
|
||||||
translation_key="deprecated_yaml",
|
|
||||||
translation_placeholders={
|
|
||||||
"domain": DOMAIN,
|
|
||||||
"integration_title": "Global Disaster Alert and Coordination System",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -10,7 +10,10 @@ from homeassistant.const import (
|
||||||
CONF_RADIUS,
|
CONF_RADIUS,
|
||||||
CONF_SCAN_INTERVAL,
|
CONF_SCAN_INTERVAL,
|
||||||
)
|
)
|
||||||
|
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN
|
||||||
|
from homeassistant.data_entry_flow import AbortFlow, FlowResultType
|
||||||
from homeassistant.helpers import config_validation as cv
|
from homeassistant.helpers import config_validation as cv
|
||||||
|
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
||||||
|
|
||||||
from .const import CONF_CATEGORIES, DEFAULT_RADIUS, DEFAULT_SCAN_INTERVAL, DOMAIN
|
from .const import CONF_CATEGORIES, DEFAULT_RADIUS, DEFAULT_SCAN_INTERVAL, DOMAIN
|
||||||
|
|
||||||
|
@ -32,7 +35,23 @@ class GdacsFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
|
|
||||||
async def async_step_import(self, import_config):
|
async def async_step_import(self, import_config):
|
||||||
"""Import a config entry from configuration.yaml."""
|
"""Import a config entry from configuration.yaml."""
|
||||||
return await self.async_step_user(import_config)
|
result = await self.async_step_user(import_config)
|
||||||
|
if result["type"] == FlowResultType.CREATE_ENTRY:
|
||||||
|
async_create_issue(
|
||||||
|
self.hass,
|
||||||
|
HOMEASSISTANT_DOMAIN,
|
||||||
|
f"deprecated_yaml_{DOMAIN}",
|
||||||
|
breaks_in_ha_version="2024.2.0",
|
||||||
|
is_fixable=False,
|
||||||
|
issue_domain=DOMAIN,
|
||||||
|
severity=IssueSeverity.WARNING,
|
||||||
|
translation_key="deprecated_yaml",
|
||||||
|
translation_placeholders={
|
||||||
|
"domain": DOMAIN,
|
||||||
|
"integration_title": "Global Disaster Alert and Coordination System",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
return result
|
||||||
|
|
||||||
async def async_step_user(self, user_input=None):
|
async def async_step_user(self, user_input=None):
|
||||||
"""Handle the start of the config flow."""
|
"""Handle the start of the config flow."""
|
||||||
|
@ -48,7 +67,25 @@ class GdacsFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||||
identifier = f"{user_input[CONF_LATITUDE]}, {user_input[CONF_LONGITUDE]}"
|
identifier = f"{user_input[CONF_LATITUDE]}, {user_input[CONF_LONGITUDE]}"
|
||||||
|
|
||||||
await self.async_set_unique_id(identifier)
|
await self.async_set_unique_id(identifier)
|
||||||
self._abort_if_unique_id_configured()
|
try:
|
||||||
|
self._abort_if_unique_id_configured()
|
||||||
|
except AbortFlow:
|
||||||
|
if self.context["source"] == config_entries.SOURCE_IMPORT:
|
||||||
|
async_create_issue(
|
||||||
|
self.hass,
|
||||||
|
HOMEASSISTANT_DOMAIN,
|
||||||
|
f"deprecated_yaml_{DOMAIN}",
|
||||||
|
breaks_in_ha_version="2024.2.0",
|
||||||
|
is_fixable=False,
|
||||||
|
issue_domain=DOMAIN,
|
||||||
|
severity=IssueSeverity.WARNING,
|
||||||
|
translation_key="deprecated_yaml",
|
||||||
|
translation_placeholders={
|
||||||
|
"domain": DOMAIN,
|
||||||
|
"integration_title": "Global Disaster Alert and Coordination System",
|
||||||
|
},
|
||||||
|
)
|
||||||
|
raise
|
||||||
|
|
||||||
scan_interval = user_input.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
|
scan_interval = user_input.get(CONF_SCAN_INTERVAL, DEFAULT_SCAN_INTERVAL)
|
||||||
user_input[CONF_SCAN_INTERVAL] = scan_interval.total_seconds()
|
user_input[CONF_SCAN_INTERVAL] = scan_interval.total_seconds()
|
||||||
|
|
|
@ -12,7 +12,8 @@ from homeassistant.const import (
|
||||||
CONF_RADIUS,
|
CONF_RADIUS,
|
||||||
CONF_SCAN_INTERVAL,
|
CONF_SCAN_INTERVAL,
|
||||||
)
|
)
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
|
||||||
|
import homeassistant.helpers.issue_registry as ir
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture(name="gdacs_setup", autouse=True)
|
@pytest.fixture(name="gdacs_setup", autouse=True)
|
||||||
|
@ -66,6 +67,32 @@ async def test_step_import(hass: HomeAssistant) -> None:
|
||||||
CONF_CATEGORIES: ["Drought", "Earthquake"],
|
CONF_CATEGORIES: ["Drought", "Earthquake"],
|
||||||
}
|
}
|
||||||
|
|
||||||
|
issue_registry = ir.async_get(hass)
|
||||||
|
issue = issue_registry.async_get_issue(
|
||||||
|
HOMEASSISTANT_DOMAIN, "deprecated_yaml_gdacs"
|
||||||
|
)
|
||||||
|
assert issue.translation_key == "deprecated_yaml"
|
||||||
|
|
||||||
|
|
||||||
|
async def test_step_import_already_exist(
|
||||||
|
hass: HomeAssistant, config_entry: config_entries.ConfigEntry
|
||||||
|
) -> None:
|
||||||
|
"""Test that errors are shown when duplicates are added."""
|
||||||
|
conf = {CONF_LATITUDE: -41.2, CONF_LONGITUDE: 174.7, CONF_RADIUS: 25}
|
||||||
|
config_entry.add_to_hass(hass)
|
||||||
|
|
||||||
|
result = await hass.config_entries.flow.async_init(
|
||||||
|
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=conf
|
||||||
|
)
|
||||||
|
assert result["type"] == data_entry_flow.FlowResultType.ABORT
|
||||||
|
assert result["reason"] == "already_configured"
|
||||||
|
|
||||||
|
issue_registry = ir.async_get(hass)
|
||||||
|
issue = issue_registry.async_get_issue(
|
||||||
|
HOMEASSISTANT_DOMAIN, "deprecated_yaml_gdacs"
|
||||||
|
)
|
||||||
|
assert issue.translation_key == "deprecated_yaml"
|
||||||
|
|
||||||
|
|
||||||
async def test_step_user(hass: HomeAssistant) -> None:
|
async def test_step_user(hass: HomeAssistant) -> None:
|
||||||
"""Test that the user step works."""
|
"""Test that the user step works."""
|
||||||
|
|
Loading…
Add table
Reference in a new issue