From 2a1d58ee5ff7d4f1a19b7593cb7f56afde4e1d9d Mon Sep 17 00:00:00 2001 From: tr4nt0r Date: Sat, 27 Apr 2024 16:17:18 +0000 Subject: [PATCH] deprecation for yaml import --- homeassistant/components/habitica/__init__.py | 15 ++++++++++++++- homeassistant/components/habitica/config_flow.py | 16 +++++++++++++++- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/habitica/__init__.py b/homeassistant/components/habitica/__init__.py index ce79d3fa1ca..34736116a26 100644 --- a/homeassistant/components/habitica/__init__.py +++ b/homeassistant/components/habitica/__init__.py @@ -7,7 +7,14 @@ 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_URL, Platform +from homeassistant.const import ( + ATTR_NAME, + CONF_API_KEY, + CONF_NAME, + CONF_SENSORS, + CONF_URL, + Platform, +) from homeassistant.core import HomeAssistant, ServiceCall from homeassistant.helpers import config_validation as cv from homeassistant.helpers.aiohttp_client import async_get_clientsession @@ -26,13 +33,19 @@ from .const import ( _LOGGER = logging.getLogger(__name__) +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))] + ), } ), ) diff --git a/homeassistant/components/habitica/config_flow.py b/homeassistant/components/habitica/config_flow.py index 9ee2aef40ba..dd696cab51c 100644 --- a/homeassistant/components/habitica/config_flow.py +++ b/homeassistant/components/habitica/config_flow.py @@ -10,9 +10,10 @@ import voluptuous as vol from homeassistant.config_entries import ConfigFlow from homeassistant.const import CONF_API_KEY, CONF_NAME, CONF_URL -from homeassistant.core import HomeAssistant +from homeassistant.core import DOMAIN as HOMEASSISTANT_DOMAIN, HomeAssistant from homeassistant.exceptions import HomeAssistantError from homeassistant.helpers.aiohttp_client import async_get_clientsession +from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue from .const import CONF_API_USER, DEFAULT_URL, DOMAIN @@ -79,6 +80,19 @@ class HabiticaConfigFlow(ConfigFlow, domain=DOMAIN): async def async_step_import(self, import_data): """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.12.0", + severity=IssueSeverity.WARNING, + translation_key="deprecated_yaml", + translation_placeholders={ + "domain": DOMAIN, + "integration_title": "Habitica", + }, + ) return await self.async_step_user(import_data)