mirror of
https://github.com/home-assistant/core.git
synced 2025-07-21 20:27:08 +00:00
Remove YAML import from Brottsplatskartan (#101222)
This commit is contained in:
parent
e652d37f29
commit
56e7e20904
@ -34,21 +34,6 @@ class BPKConfigFlow(config_entries.ConfigFlow, domain=DOMAIN):
|
|||||||
|
|
||||||
VERSION = 1
|
VERSION = 1
|
||||||
|
|
||||||
async def async_step_import(self, config: dict[str, Any]) -> FlowResult:
|
|
||||||
"""Import a configuration from config.yaml."""
|
|
||||||
|
|
||||||
if config.get(CONF_LATITUDE):
|
|
||||||
config[CONF_LOCATION] = {
|
|
||||||
CONF_LATITUDE: config[CONF_LATITUDE],
|
|
||||||
CONF_LONGITUDE: config[CONF_LONGITUDE],
|
|
||||||
}
|
|
||||||
if not config.get(CONF_AREA):
|
|
||||||
config[CONF_AREA] = "none"
|
|
||||||
else:
|
|
||||||
config[CONF_AREA] = config[CONF_AREA][0]
|
|
||||||
|
|
||||||
return await self.async_step_user(user_input=config)
|
|
||||||
|
|
||||||
async def async_step_user(
|
async def async_step_user(
|
||||||
self, user_input: dict[str, Any] | None = None
|
self, user_input: dict[str, Any] | None = None
|
||||||
) -> FlowResult:
|
) -> FlowResult:
|
||||||
|
@ -5,66 +5,18 @@ from collections import defaultdict
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
|
|
||||||
from brottsplatskartan import ATTRIBUTION, BrottsplatsKartan
|
from brottsplatskartan import ATTRIBUTION, BrottsplatsKartan
|
||||||
import voluptuous as vol
|
|
||||||
|
|
||||||
from homeassistant.components.sensor import (
|
from homeassistant.components.sensor import SensorEntity
|
||||||
PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA,
|
from homeassistant.config_entries import ConfigEntry
|
||||||
SensorEntity,
|
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE
|
||||||
)
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
|
||||||
from homeassistant.const import CONF_LATITUDE, CONF_LONGITUDE, CONF_NAME
|
|
||||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant
|
|
||||||
import homeassistant.helpers.config_validation as cv
|
|
||||||
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
|
||||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
|
||||||
from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
|
|
||||||
|
|
||||||
from .const import AREAS, CONF_APP_ID, CONF_AREA, DEFAULT_NAME, DOMAIN, LOGGER
|
from .const import CONF_APP_ID, CONF_AREA, DOMAIN, LOGGER
|
||||||
|
|
||||||
SCAN_INTERVAL = timedelta(minutes=30)
|
SCAN_INTERVAL = timedelta(minutes=30)
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
|
|
||||||
{
|
|
||||||
vol.Inclusive(CONF_LATITUDE, "coordinates"): cv.latitude,
|
|
||||||
vol.Inclusive(CONF_LONGITUDE, "coordinates"): cv.longitude,
|
|
||||||
vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string,
|
|
||||||
vol.Optional(CONF_AREA, default=[]): vol.All(cv.ensure_list, [vol.In(AREAS)]),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(
|
|
||||||
hass: HomeAssistant,
|
|
||||||
config: ConfigType,
|
|
||||||
async_add_entities: AddEntitiesCallback,
|
|
||||||
discovery_info: DiscoveryInfoType | None = None,
|
|
||||||
) -> None:
|
|
||||||
"""Set up the Brottsplatskartan platform."""
|
|
||||||
|
|
||||||
async_create_issue(
|
|
||||||
hass,
|
|
||||||
HOMEASSISTANT_DOMAIN,
|
|
||||||
f"deprecated_yaml_{DOMAIN}",
|
|
||||||
breaks_in_ha_version="2023.11.0",
|
|
||||||
is_fixable=False,
|
|
||||||
issue_domain=DOMAIN,
|
|
||||||
severity=IssueSeverity.WARNING,
|
|
||||||
translation_key="deprecated_yaml",
|
|
||||||
translation_placeholders={
|
|
||||||
"domain": DOMAIN,
|
|
||||||
"integration_title": "Brottsplatskartan",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
hass.async_create_task(
|
|
||||||
hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data=config,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_entry(
|
async def async_setup_entry(
|
||||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
"""Test the Brottsplatskartan config flow."""
|
"""Test the Brottsplatskartan config flow."""
|
||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from homeassistant import config_entries
|
from homeassistant import config_entries
|
||||||
@ -11,8 +9,6 @@ from homeassistant.const import CONF_LATITUDE, CONF_LOCATION, CONF_LONGITUDE
|
|||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
from homeassistant.data_entry_flow import FlowResultType
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
|
||||||
|
|
||||||
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
|
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
|
||||||
|
|
||||||
|
|
||||||
@ -103,107 +99,3 @@ async def test_form_area(hass: HomeAssistant) -> None:
|
|||||||
"area": "Stockholms län",
|
"area": "Stockholms län",
|
||||||
"app_id": "ha-1234567890",
|
"app_id": "ha-1234567890",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
async def test_import_flow_success(hass: HomeAssistant) -> None:
|
|
||||||
"""Test a successful import of yaml."""
|
|
||||||
|
|
||||||
with patch(
|
|
||||||
"homeassistant.components.brottsplatskartan.sensor.BrottsplatsKartan",
|
|
||||||
):
|
|
||||||
result2 = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": config_entries.SOURCE_IMPORT},
|
|
||||||
data={},
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result2["type"] == FlowResultType.CREATE_ENTRY
|
|
||||||
assert result2["title"] == "Brottsplatskartan HOME"
|
|
||||||
assert result2["data"] == {
|
|
||||||
"latitude": hass.config.latitude,
|
|
||||||
"longitude": hass.config.longitude,
|
|
||||||
"area": None,
|
|
||||||
"app_id": "ha-1234567890",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_import_flow_location_success(hass: HomeAssistant) -> None:
|
|
||||||
"""Test a successful import of yaml with location."""
|
|
||||||
|
|
||||||
with patch(
|
|
||||||
"homeassistant.components.brottsplatskartan.sensor.BrottsplatsKartan",
|
|
||||||
):
|
|
||||||
result2 = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": config_entries.SOURCE_IMPORT},
|
|
||||||
data={
|
|
||||||
CONF_LATITUDE: 59.32,
|
|
||||||
CONF_LONGITUDE: 18.06,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result2["type"] == FlowResultType.CREATE_ENTRY
|
|
||||||
assert result2["title"] == "Brottsplatskartan 59.32, 18.06"
|
|
||||||
assert result2["data"] == {
|
|
||||||
"latitude": 59.32,
|
|
||||||
"longitude": 18.06,
|
|
||||||
"area": None,
|
|
||||||
"app_id": "ha-1234567890",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_import_flow_location_area_success(hass: HomeAssistant) -> None:
|
|
||||||
"""Test a successful import of yaml with location and area."""
|
|
||||||
|
|
||||||
with patch(
|
|
||||||
"homeassistant.components.brottsplatskartan.sensor.BrottsplatsKartan",
|
|
||||||
):
|
|
||||||
result2 = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": config_entries.SOURCE_IMPORT},
|
|
||||||
data={
|
|
||||||
CONF_LATITUDE: 59.32,
|
|
||||||
CONF_LONGITUDE: 18.06,
|
|
||||||
CONF_AREA: ["Blekinge län"],
|
|
||||||
},
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result2["type"] == FlowResultType.CREATE_ENTRY
|
|
||||||
assert result2["title"] == "Brottsplatskartan Blekinge län"
|
|
||||||
assert result2["data"] == {
|
|
||||||
"latitude": None,
|
|
||||||
"longitude": None,
|
|
||||||
"area": "Blekinge län",
|
|
||||||
"app_id": "ha-1234567890",
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_import_flow_already_exist(hass: HomeAssistant) -> None:
|
|
||||||
"""Test import of yaml already exist."""
|
|
||||||
|
|
||||||
MockConfigEntry(
|
|
||||||
domain=DOMAIN,
|
|
||||||
data={
|
|
||||||
"latitude": hass.config.latitude,
|
|
||||||
"longitude": hass.config.longitude,
|
|
||||||
"area": None,
|
|
||||||
"app_id": "ha-1234567890",
|
|
||||||
},
|
|
||||||
unique_id="bpk-home",
|
|
||||||
).add_to_hass(hass)
|
|
||||||
|
|
||||||
with patch(
|
|
||||||
"homeassistant.components.brottsplatskartan.sensor.BrottsplatsKartan",
|
|
||||||
):
|
|
||||||
result3 = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": config_entries.SOURCE_IMPORT},
|
|
||||||
data={},
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result3["type"] == FlowResultType.ABORT
|
|
||||||
assert result3["reason"] == "already_configured"
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user