Remove platform YAML from GeoJSON (#103393)
parent
f88e137679
commit
43cab28700
|
@ -2,7 +2,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
from collections.abc import Mapping
|
||||
import logging
|
||||
from typing import Any
|
||||
|
||||
import voluptuous as vol
|
||||
|
@ -20,7 +19,7 @@ from homeassistant.data_entry_flow import FlowResult
|
|||
from homeassistant.helpers import config_validation as cv, selector
|
||||
from homeassistant.util.unit_conversion import DistanceConverter
|
||||
|
||||
from .const import DEFAULT_RADIUS_IN_KM, DEFAULT_RADIUS_IN_M, DOMAIN
|
||||
from .const import DEFAULT_RADIUS_IN_M, DOMAIN
|
||||
|
||||
DATA_SCHEMA = vol.Schema(
|
||||
{
|
||||
|
@ -31,34 +30,10 @@ DATA_SCHEMA = vol.Schema(
|
|||
}
|
||||
)
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class GeoJsonEventsFlowHandler(config_entries.ConfigFlow, domain=DOMAIN):
|
||||
"""Handle a GeoJSON events config flow."""
|
||||
|
||||
async def async_step_import(self, import_config: dict[str, Any]) -> FlowResult:
|
||||
"""Import a config entry from configuration.yaml."""
|
||||
url: str = import_config[CONF_URL]
|
||||
latitude: float = import_config.get(CONF_LATITUDE, self.hass.config.latitude)
|
||||
longitude: float = import_config.get(CONF_LONGITUDE, self.hass.config.longitude)
|
||||
self._async_abort_entries_match(
|
||||
{
|
||||
CONF_URL: url,
|
||||
CONF_LATITUDE: latitude,
|
||||
CONF_LONGITUDE: longitude,
|
||||
}
|
||||
)
|
||||
return self.async_create_entry(
|
||||
title=f"{url} ({latitude}, {longitude})",
|
||||
data={
|
||||
CONF_URL: url,
|
||||
CONF_LATITUDE: latitude,
|
||||
CONF_LONGITUDE: longitude,
|
||||
CONF_RADIUS: import_config.get(CONF_RADIUS, DEFAULT_RADIUS_IN_KM),
|
||||
},
|
||||
)
|
||||
|
||||
async def async_step_user(
|
||||
self, user_input: dict[str, Any] | None = None
|
||||
) -> FlowResult:
|
||||
|
|
|
@ -6,28 +6,17 @@ import logging
|
|||
from typing import Any
|
||||
|
||||
from aio_geojson_generic_client.feed_entry import GenericFeedEntry
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant.components.geo_location import PLATFORM_SCHEMA, GeolocationEvent
|
||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
||||
from homeassistant.const import (
|
||||
CONF_LATITUDE,
|
||||
CONF_LONGITUDE,
|
||||
CONF_RADIUS,
|
||||
CONF_URL,
|
||||
UnitOfLength,
|
||||
)
|
||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant, callback
|
||||
import homeassistant.helpers.config_validation as cv
|
||||
from homeassistant.components.geo_location import GeolocationEvent
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import UnitOfLength
|
||||
from homeassistant.core import HomeAssistant, callback
|
||||
from homeassistant.helpers.dispatcher import async_dispatcher_connect
|
||||
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 . import GeoJsonFeedEntityManager
|
||||
from .const import (
|
||||
ATTR_EXTERNAL_ID,
|
||||
DEFAULT_RADIUS_IN_KM,
|
||||
DOMAIN,
|
||||
SIGNAL_DELETE_ENTITY,
|
||||
SIGNAL_UPDATE_ENTITY,
|
||||
|
@ -36,16 +25,6 @@ from .const import (
|
|||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
# Deprecated.
|
||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
||||
{
|
||||
vol.Required(CONF_URL): cv.string,
|
||||
vol.Optional(CONF_LATITUDE): cv.latitude,
|
||||
vol.Optional(CONF_LONGITUDE): cv.longitude,
|
||||
vol.Optional(CONF_RADIUS, default=DEFAULT_RADIUS_IN_KM): vol.Coerce(float),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
async def async_setup_entry(
|
||||
hass: HomeAssistant, entry: ConfigEntry, async_add_entities: AddEntitiesCallback
|
||||
|
@ -72,34 +51,6 @@ async def async_setup_entry(
|
|||
_LOGGER.debug("Geolocation setup done")
|
||||
|
||||
|
||||
async def async_setup_platform(
|
||||
hass: HomeAssistant,
|
||||
config: ConfigType,
|
||||
async_add_entities: AddEntitiesCallback,
|
||||
discovery_info: DiscoveryInfoType | None = None,
|
||||
) -> None:
|
||||
"""Set up the GeoJSON Events platform."""
|
||||
async_create_issue(
|
||||
hass,
|
||||
HOMEASSISTANT_DOMAIN,
|
||||
f"deprecated_yaml_{DOMAIN}",
|
||||
breaks_in_ha_version="2023.12.0",
|
||||
is_fixable=False,
|
||||
issue_domain=DOMAIN,
|
||||
severity=IssueSeverity.WARNING,
|
||||
translation_key="deprecated_yaml",
|
||||
translation_placeholders={
|
||||
"domain": DOMAIN,
|
||||
"integration_title": "GeoJSON feed",
|
||||
},
|
||||
)
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": SOURCE_IMPORT}, data=config
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
class GeoJsonLocationEvent(GeolocationEvent):
|
||||
"""Represents an external event with GeoJSON data."""
|
||||
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
"""Define tests for the GeoJSON Events config flow."""
|
||||
from datetime import timedelta
|
||||
|
||||
import pytest
|
||||
|
||||
|
@ -10,14 +9,14 @@ from homeassistant.const import (
|
|||
CONF_LOCATION,
|
||||
CONF_LONGITUDE,
|
||||
CONF_RADIUS,
|
||||
CONF_SCAN_INTERVAL,
|
||||
CONF_URL,
|
||||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from .conftest import URL
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
from tests.components.geo_json_events.conftest import URL
|
||||
|
||||
pytestmark = pytest.mark.usefixtures("mock_setup_entry")
|
||||
|
||||
|
@ -49,52 +48,6 @@ async def test_duplicate_error_user(
|
|||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_duplicate_error_import(
|
||||
hass: HomeAssistant, config_entry: MockConfigEntry
|
||||
) -> None:
|
||||
"""Test that errors are shown when duplicates are added."""
|
||||
config_entry.add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={
|
||||
CONF_URL: URL,
|
||||
CONF_LATITUDE: -41.2,
|
||||
CONF_LONGITUDE: 174.7,
|
||||
CONF_RADIUS: 25,
|
||||
},
|
||||
)
|
||||
assert result["type"] == FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
||||
|
||||
async def test_step_import(hass: HomeAssistant) -> None:
|
||||
"""Test that the import step works."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN,
|
||||
context={"source": config_entries.SOURCE_IMPORT},
|
||||
data={
|
||||
CONF_URL: URL,
|
||||
CONF_LATITUDE: -41.2,
|
||||
CONF_LONGITUDE: 174.7,
|
||||
CONF_RADIUS: 25,
|
||||
# This custom scan interval will not be carried over into the configuration.
|
||||
CONF_SCAN_INTERVAL: timedelta(minutes=4),
|
||||
},
|
||||
)
|
||||
assert result["type"] == FlowResultType.CREATE_ENTRY
|
||||
assert (
|
||||
result["title"] == "http://geo.json.local/geo_json_events.json (-41.2, 174.7)"
|
||||
)
|
||||
assert result["data"] == {
|
||||
CONF_URL: URL,
|
||||
CONF_LATITUDE: -41.2,
|
||||
CONF_LONGITUDE: 174.7,
|
||||
CONF_RADIUS: 25,
|
||||
}
|
||||
|
||||
|
||||
async def test_step_user(hass: HomeAssistant) -> None:
|
||||
"""Test that the user step works."""
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
"""The tests for the geojson platform."""
|
||||
from datetime import timedelta
|
||||
from unittest.mock import ANY, call, patch
|
||||
from unittest.mock import patch
|
||||
|
||||
from aio_geojson_generic_client import GenericFeed
|
||||
from freezegun import freeze_time
|
||||
|
||||
from homeassistant.components.geo_json_events.const import (
|
||||
|
@ -25,7 +24,6 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import entity_registry as er
|
||||
from homeassistant.setup import async_setup_component
|
||||
from homeassistant.util import dt as dt_util
|
||||
|
||||
from tests.common import MockConfigEntry, async_fire_time_changed
|
||||
|
@ -44,26 +42,6 @@ CONFIG_LEGACY = {
|
|||
}
|
||||
|
||||
|
||||
async def test_setup_as_legacy_platform(hass: HomeAssistant) -> None:
|
||||
"""Test the setup with YAML legacy configuration."""
|
||||
# Set up some mock feed entries for this test.
|
||||
mock_entry_1 = _generate_mock_feed_entry("1234", "Title 1", 20.5, (-31.1, 150.1))
|
||||
|
||||
with patch(
|
||||
"aio_geojson_generic_client.feed_manager.GenericFeed",
|
||||
wraps=GenericFeed,
|
||||
) as mock_feed, patch(
|
||||
"aio_geojson_client.feed.GeoJsonFeed.update",
|
||||
return_value=("OK", [mock_entry_1]),
|
||||
):
|
||||
assert await async_setup_component(hass, GEO_LOCATION_DOMAIN, CONFIG_LEGACY)
|
||||
await hass.async_block_till_done()
|
||||
|
||||
assert len(hass.states.async_entity_ids(GEO_LOCATION_DOMAIN)) == 1
|
||||
|
||||
assert mock_feed.call_args == call(ANY, ANY, URL, filter_radius=190.0)
|
||||
|
||||
|
||||
async def test_entity_lifecycle(
|
||||
hass: HomeAssistant,
|
||||
entity_registry: er.EntityRegistry,
|
||||
|
|
Loading…
Reference in New Issue