Raise issue if not Rova area anymore (#114309)
parent
a00c1fa241
commit
a9fd4e45cd
|
@ -9,6 +9,7 @@ from homeassistant.config_entries import ConfigEntry
|
|||
from homeassistant.const import Platform
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.exceptions import ConfigEntryError, ConfigEntryNotReady
|
||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
||||
|
||||
from .const import CONF_HOUSE_NUMBER, CONF_HOUSE_NUMBER_SUFFIX, CONF_ZIP_CODE, DOMAIN
|
||||
from .coordinator import RovaCoordinator
|
||||
|
@ -31,6 +32,18 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
|
|||
raise ConfigEntryNotReady from ex
|
||||
|
||||
if not rova_area:
|
||||
async_create_issue(
|
||||
hass,
|
||||
DOMAIN,
|
||||
f"no_rova_area_{entry.data[CONF_ZIP_CODE]}",
|
||||
is_fixable=False,
|
||||
issue_domain=DOMAIN,
|
||||
severity=IssueSeverity.ERROR,
|
||||
translation_key="no_rova_area",
|
||||
translation_placeholders={
|
||||
CONF_ZIP_CODE: entry.data[CONF_ZIP_CODE],
|
||||
},
|
||||
)
|
||||
raise ConfigEntryError("Rova does not collect garbage in this area")
|
||||
|
||||
coordinator = RovaCoordinator(hass, api)
|
||||
|
|
|
@ -28,6 +28,10 @@
|
|||
"deprecated_yaml_import_issue_invalid_rova_area": {
|
||||
"title": "The Rova YAML configuration import failed",
|
||||
"description": "There was an error when trying to import your Rova YAML configuration.\n\nRova does not collect at this address.\n\nEnsure the imported configuration is correct and remove the Rova YAML configuration from your configuration.yaml file and continue to [set up the integration]({url}) manually."
|
||||
},
|
||||
"no_rova_area": {
|
||||
"title": "Rova does not collect at this address anymore",
|
||||
"description": "Rova does not collect at {zip_code} anymore.\n\nPlease remove the integration."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
"""Tests for the Rova integration init."""
|
||||
|
||||
from unittest.mock import MagicMock
|
||||
|
||||
from homeassistant.config_entries import ConfigEntryState
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
|
||||
async def test_issue_if_not_rova_area(
|
||||
hass: HomeAssistant,
|
||||
mock_rova: MagicMock,
|
||||
mock_config_entry: MockConfigEntry,
|
||||
issue_registry: ir.IssueRegistry,
|
||||
) -> None:
|
||||
"""Test we create an issue if rova does not collect at the given address."""
|
||||
mock_rova.is_rova_area.return_value = False
|
||||
mock_config_entry.add_to_hass(hass)
|
||||
assert not await hass.config_entries.async_setup(mock_config_entry.entry_id)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert mock_config_entry.state == ConfigEntryState.SETUP_ERROR
|
||||
assert len(issue_registry.issues) == 1
|
Loading…
Reference in New Issue