Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove platform YAML from GeoJSON #103393

Merged
merged 1 commit into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 1 addition & 26 deletions homeassistant/components/geo_json_events/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
from __future__ import annotations

from collections.abc import Mapping
import logging
from typing import Any

import voluptuous as vol
Expand All @@ -20,7 +19,7 @@
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(
{
Expand All @@ -31,34 +30,10 @@
}
)

_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:
Expand Down
59 changes: 5 additions & 54 deletions homeassistant/components/geo_json_events/geo_location.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,17 @@
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,
Expand All @@ -36,16 +25,6 @@

_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
Expand All @@ -72,34 +51,6 @@ def async_add_geolocation(
_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."""

Expand Down
51 changes: 2 additions & 49 deletions tests/components/geo_json_events/test_config_flow.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Define tests for the GeoJSON Events config flow."""
from datetime import timedelta

import pytest

Expand All @@ -10,14 +9,14 @@
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")

Expand Down Expand Up @@ -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(
Expand Down
24 changes: 1 addition & 23 deletions tests/components/geo_json_events/test_geo_location.py
Original file line number Diff line number Diff line change
@@ -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 (
Expand All @@ -25,7 +24,6 @@
)
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
Expand All @@ -44,26 +42,6 @@
}


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,
Expand Down