mirror of
https://github.com/home-assistant/core.git
synced 2025-07-09 22:37:11 +00:00
Remove deprecated yaml import from Habitica (#127946)
This commit is contained in:
parent
413a4cd7bd
commit
fa53ec40d6
@ -8,13 +8,11 @@ from aiohttp import ClientResponseError
|
||||
from habitipy.aio import HabitipyAsync
|
||||
import voluptuous as vol
|
||||
|
||||
from homeassistant import config_entries
|
||||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.const import (
|
||||
ATTR_NAME,
|
||||
CONF_API_KEY,
|
||||
CONF_NAME,
|
||||
CONF_SENSORS,
|
||||
CONF_URL,
|
||||
CONF_VERIFY_SSL,
|
||||
Platform,
|
||||
@ -43,7 +41,6 @@ from .const import (
|
||||
ATTR_SKILL,
|
||||
ATTR_TASK,
|
||||
CONF_API_USER,
|
||||
DEFAULT_URL,
|
||||
DOMAIN,
|
||||
EVENT_API_CALL_SUCCESS,
|
||||
SERVICE_API_CALL,
|
||||
@ -52,54 +49,14 @@ from .const import (
|
||||
from .coordinator import HabiticaDataUpdateCoordinator
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
CONFIG_SCHEMA = cv.config_entry_only_config_schema(DOMAIN)
|
||||
|
||||
type HabiticaConfigEntry = ConfigEntry[HabiticaDataUpdateCoordinator]
|
||||
|
||||
SENSORS_TYPES = ["name", "hp", "maxHealth", "mp", "maxMP", "exp", "toNextLevel", "lvl"]
|
||||
|
||||
INSTANCE_SCHEMA = vol.All(
|
||||
cv.deprecated(CONF_SENSORS),
|
||||
vol.Schema(
|
||||
{
|
||||
vol.Optional(CONF_URL, default=DEFAULT_URL): cv.url,
|
||||
vol.Optional(CONF_NAME): cv.string,
|
||||
vol.Required(CONF_API_USER): cv.string,
|
||||
vol.Required(CONF_API_KEY): cv.string,
|
||||
vol.Optional(CONF_SENSORS, default=list(SENSORS_TYPES)): vol.All(
|
||||
cv.ensure_list, vol.Unique(), [vol.In(list(SENSORS_TYPES))]
|
||||
),
|
||||
}
|
||||
),
|
||||
)
|
||||
|
||||
has_unique_values = vol.Schema(vol.Unique())
|
||||
# because we want a handy alias
|
||||
|
||||
|
||||
def has_all_unique_users(value):
|
||||
"""Validate that all API users are unique."""
|
||||
api_users = [user[CONF_API_USER] for user in value]
|
||||
has_unique_values(api_users)
|
||||
return value
|
||||
|
||||
|
||||
def has_all_unique_users_names(value):
|
||||
"""Validate that all user's names are unique and set if any is set."""
|
||||
names = [user.get(CONF_NAME) for user in value]
|
||||
if None in names and any(name is not None for name in names):
|
||||
raise vol.Invalid("user names of all users must be set if any is set")
|
||||
if not all(name is None for name in names):
|
||||
has_unique_values(names)
|
||||
return value
|
||||
|
||||
|
||||
INSTANCE_LIST_SCHEMA = vol.All(
|
||||
cv.ensure_list, has_all_unique_users, has_all_unique_users_names, [INSTANCE_SCHEMA]
|
||||
)
|
||||
CONFIG_SCHEMA = vol.Schema({DOMAIN: INSTANCE_LIST_SCHEMA}, extra=vol.ALLOW_EXTRA)
|
||||
|
||||
PLATFORMS = [Platform.BUTTON, Platform.SENSOR, Platform.SWITCH, Platform.TODO]
|
||||
|
||||
|
||||
SERVICE_API_CALL_SCHEMA = vol.Schema(
|
||||
{
|
||||
vol.Required(ATTR_NAME): str,
|
||||
@ -118,17 +75,6 @@ SERVICE_CAST_SKILL_SCHEMA = vol.Schema(
|
||||
|
||||
async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool:
|
||||
"""Set up the Habitica service."""
|
||||
configs = config.get(DOMAIN, [])
|
||||
|
||||
for conf in configs:
|
||||
if conf.get(CONF_URL) is None:
|
||||
conf[CONF_URL] = DEFAULT_URL
|
||||
|
||||
hass.async_create_task(
|
||||
hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}, data=conf
|
||||
)
|
||||
)
|
||||
|
||||
async def cast_skill(call: ServiceCall) -> ServiceResponse:
|
||||
"""Skill action."""
|
||||
|
@ -18,9 +18,7 @@ from homeassistant.const import (
|
||||
CONF_USERNAME,
|
||||
CONF_VERIFY_SSL,
|
||||
)
|
||||
from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue
|
||||
from homeassistant.helpers.selector import (
|
||||
TextSelector,
|
||||
TextSelectorConfig,
|
||||
@ -178,21 +176,3 @@ class HabiticaConfigFlow(ConfigFlow, domain=DOMAIN):
|
||||
),
|
||||
errors=errors,
|
||||
)
|
||||
|
||||
async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult:
|
||||
"""Import habitica config from configuration.yaml."""
|
||||
|
||||
async_create_issue(
|
||||
self.hass,
|
||||
HOMEASSISTANT_DOMAIN,
|
||||
f"deprecated_yaml_{DOMAIN}",
|
||||
is_fixable=False,
|
||||
breaks_in_ha_version="2024.11.0",
|
||||
severity=IssueSeverity.WARNING,
|
||||
translation_key="deprecated_yaml",
|
||||
translation_placeholders={
|
||||
"domain": DOMAIN,
|
||||
"integration_title": "Habitica",
|
||||
},
|
||||
)
|
||||
return await self.async_step_advanced(import_data)
|
||||
|
@ -17,8 +17,6 @@ from homeassistant.const import (
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.data_entry_flow import FlowResultType
|
||||
|
||||
from tests.common import MockConfigEntry
|
||||
|
||||
MOCK_DATA_LOGIN_STEP = {
|
||||
CONF_USERNAME: "test-email@example.com",
|
||||
CONF_PASSWORD: "test-password",
|
||||
@ -217,38 +215,3 @@ async def test_form_advanced_errors(
|
||||
|
||||
assert result2["type"] is FlowResultType.FORM
|
||||
assert result2["errors"] == {"base": text_error}
|
||||
|
||||
|
||||
async def test_manual_flow_config_exist(hass: HomeAssistant) -> None:
|
||||
"""Test config flow discovers only already configured config."""
|
||||
MockConfigEntry(
|
||||
domain=DOMAIN,
|
||||
unique_id="test-api-user",
|
||||
data={"api_user": "test-api-user", "api_key": "test-api-key"},
|
||||
).add_to_hass(hass)
|
||||
|
||||
result = await hass.config_entries.flow.async_init(
|
||||
DOMAIN, context={"source": config_entries.SOURCE_IMPORT}
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.FORM
|
||||
assert result["step_id"] == "advanced"
|
||||
|
||||
mock_obj = MagicMock()
|
||||
mock_obj.user.get = AsyncMock(return_value={"api_user": "test-api-user"})
|
||||
|
||||
with patch(
|
||||
"homeassistant.components.habitica.config_flow.HabitipyAsync",
|
||||
return_value=mock_obj,
|
||||
):
|
||||
result = await hass.config_entries.flow.async_configure(
|
||||
result["flow_id"],
|
||||
{
|
||||
"url": DEFAULT_URL,
|
||||
"api_user": "test-api-user",
|
||||
"api_key": "test-api-key",
|
||||
},
|
||||
)
|
||||
|
||||
assert result["type"] is FlowResultType.ABORT
|
||||
assert result["reason"] == "already_configured"
|
||||
|
Loading…
x
Reference in New Issue
Block a user