Remove deprecated Moon YAML configuration (#89161)

* Remove deprecated Moon YAML configuration

* Restore old title defaults
This commit is contained in:
Franck Nijhof 2023-03-05 17:05:32 +01:00 committed by GitHub
parent 7b54061ab7
commit 2fc2c2efbe
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 6 additions and 103 deletions

View file

@ -4,7 +4,6 @@ from __future__ import annotations
from typing import Any from typing import Any
from homeassistant.config_entries import ConfigFlow from homeassistant.config_entries import ConfigFlow
from homeassistant.const import CONF_NAME
from homeassistant.data_entry_flow import FlowResult from homeassistant.data_entry_flow import FlowResult
from .const import DEFAULT_NAME, DOMAIN from .const import DEFAULT_NAME, DOMAIN
@ -23,13 +22,6 @@ class MoonConfigFlow(ConfigFlow, domain=DOMAIN):
return self.async_abort(reason="single_instance_allowed") return self.async_abort(reason="single_instance_allowed")
if user_input is not None: if user_input is not None:
return self.async_create_entry( return self.async_create_entry(title=DEFAULT_NAME, data={})
title=user_input.get(CONF_NAME, DEFAULT_NAME),
data={},
)
return self.async_show_form(step_id="user") return self.async_show_form(step_id="user")
async def async_step_import(self, user_input: dict[str, Any]) -> FlowResult:
"""Handle import from configuration.yaml."""
return await self.async_step_user(user_input)

View file

@ -2,25 +2,16 @@
from __future__ import annotations from __future__ import annotations
from astral import moon from astral import moon
import voluptuous as vol
from homeassistant.components.sensor import ( from homeassistant.components.sensor import SensorDeviceClass, SensorEntity
PLATFORM_SCHEMA as PARENT_PLATFORM_SCHEMA, from homeassistant.config_entries import ConfigEntry
SensorDeviceClass,
SensorEntity,
)
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
import homeassistant.helpers.config_validation as cv
from homeassistant.helpers.device_registry import DeviceEntryType from homeassistant.helpers.device_registry import DeviceEntryType
from homeassistant.helpers.entity import DeviceInfo from homeassistant.helpers.entity import 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
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
from .const import DEFAULT_NAME, DOMAIN from .const import DOMAIN
STATE_FIRST_QUARTER = "first_quarter" STATE_FIRST_QUARTER = "first_quarter"
STATE_FULL_MOON = "full_moon" STATE_FULL_MOON = "full_moon"
@ -42,35 +33,6 @@ MOON_ICONS = {
STATE_WAXING_GIBBOUS: "mdi:moon-waxing-gibbous", STATE_WAXING_GIBBOUS: "mdi:moon-waxing-gibbous",
} }
PLATFORM_SCHEMA = PARENT_PLATFORM_SCHEMA.extend(
{vol.Optional(CONF_NAME, default=DEFAULT_NAME): cv.string}
)
async def async_setup_platform(
hass: HomeAssistant,
config: ConfigType,
async_add_entities: AddEntitiesCallback,
discovery_info: DiscoveryInfoType | None = None,
) -> None:
"""Set up the Moon sensor."""
async_create_issue(
hass,
DOMAIN,
"removed_yaml",
breaks_in_ha_version="2022.12.0",
is_fixable=False,
severity=IssueSeverity.WARNING,
translation_key="removed_yaml",
)
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, hass: HomeAssistant,

View file

@ -1,11 +1,8 @@
"""Tests for the Moon config flow.""" """Tests for the Moon config flow."""
from unittest.mock import MagicMock from unittest.mock import MagicMock
import pytest
from homeassistant.components.moon.const import DOMAIN from homeassistant.components.moon.const import DOMAIN
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER from homeassistant.config_entries import SOURCE_USER
from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.data_entry_flow import FlowResultType from homeassistant.data_entry_flow import FlowResultType
@ -34,34 +31,16 @@ async def test_full_user_flow(
assert result2.get("data") == {} assert result2.get("data") == {}
@pytest.mark.parametrize("source", [SOURCE_USER, SOURCE_IMPORT])
async def test_single_instance_allowed( async def test_single_instance_allowed(
hass: HomeAssistant, hass: HomeAssistant,
mock_config_entry: MockConfigEntry, mock_config_entry: MockConfigEntry,
source: str,
) -> None: ) -> None:
"""Test we abort if already setup.""" """Test we abort if already setup."""
mock_config_entry.add_to_hass(hass) mock_config_entry.add_to_hass(hass)
result = await hass.config_entries.flow.async_init( result = await hass.config_entries.flow.async_init(
DOMAIN, context={"source": source} DOMAIN, context={"source": SOURCE_USER}
) )
assert result.get("type") == FlowResultType.ABORT assert result.get("type") == FlowResultType.ABORT
assert result.get("reason") == "single_instance_allowed" assert result.get("reason") == "single_instance_allowed"
async def test_import_flow(
hass: HomeAssistant,
mock_setup_entry: MagicMock,
) -> None:
"""Test the import configuration flow."""
result = await hass.config_entries.flow.async_init(
DOMAIN,
context={"source": SOURCE_IMPORT},
data={CONF_NAME: "My Moon"},
)
assert result.get("type") == FlowResultType.CREATE_ENTRY
assert result.get("title") == "My Moon"
assert result.get("data") == {}

View file

@ -1,12 +1,8 @@
"""Tests for the Moon integration.""" """Tests for the Moon integration."""
from unittest.mock import AsyncMock
from homeassistant.components.moon.const import DOMAIN from homeassistant.components.moon.const import DOMAIN
from homeassistant.components.sensor import DOMAIN as SENSOR_DOMAIN
from homeassistant.config_entries import ConfigEntryState from homeassistant.config_entries import ConfigEntryState
from homeassistant.const import CONF_NAME
from homeassistant.core import HomeAssistant from homeassistant.core import HomeAssistant
from homeassistant.setup import async_setup_component
from tests.common import MockConfigEntry from tests.common import MockConfigEntry
@ -27,29 +23,3 @@ async def test_load_unload_config_entry(
assert not hass.data.get(DOMAIN) assert not hass.data.get(DOMAIN)
assert mock_config_entry.state is ConfigEntryState.NOT_LOADED assert mock_config_entry.state is ConfigEntryState.NOT_LOADED
async def test_import_config(
hass: HomeAssistant,
mock_setup_entry: AsyncMock,
) -> None:
"""Test Moon being set up from config via import."""
assert await async_setup_component(
hass,
SENSOR_DOMAIN,
{
SENSOR_DOMAIN: {
"platform": DOMAIN,
CONF_NAME: "My Moon",
}
},
)
await hass.async_block_till_done()
config_entries = hass.config_entries.async_entries(DOMAIN)
assert len(config_entries) == 1
entry = config_entries[0]
assert entry.title == "My Moon"
assert entry.unique_id is None
assert entry.data == {}