mirror of
https://github.com/home-assistant/core.git
synced 2025-07-27 23:27:37 +00:00
Remove platform YAML from LastFM (#103391)
This commit is contained in:
parent
d0603729f2
commit
941239262a
@ -19,7 +19,6 @@ from homeassistant.helpers.selector import (
|
|||||||
SelectSelector,
|
SelectSelector,
|
||||||
SelectSelectorConfig,
|
SelectSelectorConfig,
|
||||||
)
|
)
|
||||||
from homeassistant.helpers.typing import ConfigType
|
|
||||||
|
|
||||||
from .const import CONF_MAIN_USER, CONF_USERS, DOMAIN
|
from .const import CONF_MAIN_USER, CONF_USERS, DOMAIN
|
||||||
|
|
||||||
@ -154,24 +153,6 @@ class LastFmConfigFlowHandler(ConfigFlow, domain=DOMAIN):
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
|
||||||
async def async_step_import(self, import_config: ConfigType) -> FlowResult:
|
|
||||||
"""Import config from yaml."""
|
|
||||||
for entry in self._async_current_entries():
|
|
||||||
if entry.options[CONF_API_KEY] == import_config[CONF_API_KEY]:
|
|
||||||
return self.async_abort(reason="already_configured")
|
|
||||||
users, _ = validate_lastfm_users(
|
|
||||||
import_config[CONF_API_KEY], import_config[CONF_USERS]
|
|
||||||
)
|
|
||||||
return self.async_create_entry(
|
|
||||||
title="LastFM",
|
|
||||||
data={},
|
|
||||||
options={
|
|
||||||
CONF_API_KEY: import_config[CONF_API_KEY],
|
|
||||||
CONF_MAIN_USER: None,
|
|
||||||
CONF_USERS: users,
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
class LastFmOptionsFlowHandler(OptionsFlowWithConfigEntry):
|
class LastFmOptionsFlowHandler(OptionsFlowWithConfigEntry):
|
||||||
"""LastFm Options flow handler."""
|
"""LastFm Options flow handler."""
|
||||||
|
@ -4,17 +4,11 @@ from __future__ import annotations
|
|||||||
import hashlib
|
import hashlib
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
import voluptuous as vol
|
from homeassistant.components.sensor import SensorEntity
|
||||||
|
from homeassistant.config_entries import ConfigEntry
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA, SensorEntity
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, ConfigEntry
|
|
||||||
from homeassistant.const import CONF_API_KEY
|
|
||||||
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 homeassistant.helpers.update_coordinator import CoordinatorEntity
|
from homeassistant.helpers.update_coordinator import CoordinatorEntity
|
||||||
|
|
||||||
from .const import (
|
from .const import (
|
||||||
@ -28,43 +22,6 @@ from .const import (
|
|||||||
)
|
)
|
||||||
from .coordinator import LastFMDataUpdateCoordinator, LastFMUserData
|
from .coordinator import LastFMDataUpdateCoordinator, LastFMUserData
|
||||||
|
|
||||||
PLATFORM_SCHEMA = PLATFORM_SCHEMA.extend(
|
|
||||||
{
|
|
||||||
vol.Required(CONF_API_KEY): cv.string,
|
|
||||||
vol.Required(CONF_USERS, default=[]): vol.All(cv.ensure_list, [cv.string]),
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_platform(
|
|
||||||
hass: HomeAssistant,
|
|
||||||
config: ConfigType,
|
|
||||||
async_add_entities: AddEntitiesCallback,
|
|
||||||
discovery_info: DiscoveryInfoType | None = None,
|
|
||||||
) -> None:
|
|
||||||
"""Set up the Last.fm sensor platform from yaml."""
|
|
||||||
|
|
||||||
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": "LastFM",
|
|
||||||
},
|
|
||||||
)
|
|
||||||
|
|
||||||
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,
|
||||||
|
@ -11,10 +11,9 @@ from homeassistant.components.lastfm.const import (
|
|||||||
DEFAULT_NAME,
|
DEFAULT_NAME,
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
)
|
)
|
||||||
from homeassistant.config_entries import SOURCE_IMPORT, SOURCE_USER
|
from homeassistant.config_entries import SOURCE_USER
|
||||||
from homeassistant.const import CONF_API_KEY
|
from homeassistant.const import CONF_API_KEY
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.data_entry_flow import FlowResultType
|
|
||||||
|
|
||||||
from . import (
|
from . import (
|
||||||
API_KEY,
|
API_KEY,
|
||||||
@ -22,7 +21,6 @@ from . import (
|
|||||||
CONF_FRIENDS_DATA,
|
CONF_FRIENDS_DATA,
|
||||||
CONF_USER_DATA,
|
CONF_USER_DATA,
|
||||||
USERNAME_1,
|
USERNAME_1,
|
||||||
USERNAME_2,
|
|
||||||
MockUser,
|
MockUser,
|
||||||
patch_setup_entry,
|
patch_setup_entry,
|
||||||
)
|
)
|
||||||
@ -158,45 +156,6 @@ async def test_flow_friends_no_friends(
|
|||||||
assert len(result["data_schema"].schema[CONF_USERS].config["options"]) == 0
|
assert len(result["data_schema"].schema[CONF_USERS].config["options"]) == 0
|
||||||
|
|
||||||
|
|
||||||
async def test_import_flow_success(hass: HomeAssistant, default_user: MockUser) -> None:
|
|
||||||
"""Test import flow."""
|
|
||||||
with patch("pylast.User", return_value=default_user):
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data={CONF_API_KEY: API_KEY, CONF_USERS: [USERNAME_1, USERNAME_2]},
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
assert result["type"] == data_entry_flow.FlowResultType.CREATE_ENTRY
|
|
||||||
assert result["title"] == "LastFM"
|
|
||||||
assert result["options"] == {
|
|
||||||
"api_key": "asdasdasdasdasd",
|
|
||||||
"main_user": None,
|
|
||||||
"users": ["testaccount1", "testaccount2"],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_import_flow_already_exist(
|
|
||||||
hass: HomeAssistant,
|
|
||||||
setup_integration: ComponentSetup,
|
|
||||||
imported_config_entry: MockConfigEntry,
|
|
||||||
default_user: MockUser,
|
|
||||||
) -> None:
|
|
||||||
"""Test import of yaml already exist."""
|
|
||||||
await setup_integration(imported_config_entry, default_user)
|
|
||||||
|
|
||||||
with patch("pylast.User", return_value=default_user):
|
|
||||||
result = await hass.config_entries.flow.async_init(
|
|
||||||
DOMAIN,
|
|
||||||
context={"source": SOURCE_IMPORT},
|
|
||||||
data=CONF_DATA,
|
|
||||||
)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
|
|
||||||
assert result["type"] == FlowResultType.ABORT
|
|
||||||
assert result["reason"] == "already_configured"
|
|
||||||
|
|
||||||
|
|
||||||
async def test_options_flow(
|
async def test_options_flow(
|
||||||
hass: HomeAssistant,
|
hass: HomeAssistant,
|
||||||
setup_integration: ComponentSetup,
|
setup_integration: ComponentSetup,
|
||||||
|
@ -1,39 +1,14 @@
|
|||||||
"""Tests for the lastfm sensor."""
|
"""Tests for the lastfm sensor."""
|
||||||
from unittest.mock import patch
|
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
from syrupy.assertion import SnapshotAssertion
|
from syrupy.assertion import SnapshotAssertion
|
||||||
|
|
||||||
from homeassistant.components.lastfm.const import CONF_USERS, DOMAIN
|
|
||||||
from homeassistant.config_entries import ConfigEntryState
|
|
||||||
from homeassistant.const import CONF_API_KEY, CONF_PLATFORM, Platform
|
|
||||||
from homeassistant.core import HomeAssistant
|
from homeassistant.core import HomeAssistant
|
||||||
from homeassistant.helpers import issue_registry as ir
|
|
||||||
from homeassistant.setup import async_setup_component
|
|
||||||
|
|
||||||
from . import API_KEY, USERNAME_1, MockUser
|
|
||||||
from .conftest import ComponentSetup
|
from .conftest import ComponentSetup
|
||||||
|
|
||||||
from tests.common import MockConfigEntry
|
from tests.common import MockConfigEntry
|
||||||
|
|
||||||
LEGACY_CONFIG = {
|
|
||||||
Platform.SENSOR: [
|
|
||||||
{CONF_PLATFORM: DOMAIN, CONF_API_KEY: API_KEY, CONF_USERS: [USERNAME_1]}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async def test_legacy_migration(hass: HomeAssistant) -> None:
|
|
||||||
"""Test migration from yaml to config flow."""
|
|
||||||
with patch("pylast.User", return_value=MockUser()):
|
|
||||||
assert await async_setup_component(hass, Platform.SENSOR, LEGACY_CONFIG)
|
|
||||||
await hass.async_block_till_done()
|
|
||||||
entries = hass.config_entries.async_entries(DOMAIN)
|
|
||||||
assert len(entries) == 1
|
|
||||||
assert entries[0].state is ConfigEntryState.LOADED
|
|
||||||
issue_registry = ir.async_get(hass)
|
|
||||||
assert len(issue_registry.issues) == 1
|
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize(
|
@pytest.mark.parametrize(
|
||||||
("fixture"),
|
("fixture"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user