|
11 | 11 | import voluptuous as vol |
12 | 12 |
|
13 | 13 | from homeassistant.config_entries import ( |
14 | | - SOURCE_IMPORT, |
15 | 14 | SOURCE_RECONFIGURE, |
16 | 15 | ConfigFlow, |
17 | 16 | ConfigFlowResult, |
18 | | - ConfigSubentryData, |
19 | 17 | ConfigSubentryFlow, |
20 | 18 | OptionsFlow, |
21 | 19 | SubentryFlowResult, |
22 | 20 | ) |
23 | 21 | from homeassistant.const import CONF_API_KEY, CONF_PLATFORM, CONF_URL |
24 | 22 | from homeassistant.core import callback |
25 | | -from homeassistant.data_entry_flow import AbortFlow, section |
| 23 | +from homeassistant.data_entry_flow import section |
26 | 24 | from homeassistant.helpers import config_validation as cv |
27 | | -from homeassistant.helpers.issue_registry import IssueSeverity, async_create_issue |
28 | 25 | from homeassistant.helpers.network import NoURLAvailableError, get_url |
29 | 26 | from homeassistant.helpers.selector import ( |
30 | 27 | SelectSelector, |
|
39 | 36 | from .const import ( |
40 | 37 | ATTR_PARSER, |
41 | 38 | BOT_NAME, |
42 | | - CONF_ALLOWED_CHAT_IDS, |
43 | | - CONF_BOT_COUNT, |
44 | 39 | CONF_CHAT_ID, |
45 | 40 | CONF_PROXY_URL, |
46 | 41 | CONF_TRUSTED_NETWORKS, |
47 | 42 | DEFAULT_TRUSTED_NETWORKS, |
48 | 43 | DOMAIN, |
49 | 44 | ERROR_FIELD, |
50 | 45 | ERROR_MESSAGE, |
51 | | - ISSUE_DEPRECATED_YAML, |
52 | | - ISSUE_DEPRECATED_YAML_HAS_MORE_PLATFORMS, |
53 | | - ISSUE_DEPRECATED_YAML_IMPORT_ISSUE_ERROR, |
54 | 46 | PARSER_HTML, |
55 | 47 | PARSER_MD, |
56 | 48 | PARSER_MD2, |
@@ -208,111 +200,6 @@ def __init__(self) -> None: |
208 | 200 | # for passing data between steps |
209 | 201 | self._step_user_data: dict[str, Any] = {} |
210 | 202 |
|
211 | | - # triggered by async_setup() from __init__.py |
212 | | - async def async_step_import(self, import_data: dict[str, Any]) -> ConfigFlowResult: |
213 | | - """Handle import of config entry from configuration.yaml.""" |
214 | | - |
215 | | - telegram_bot: str = f"{import_data[CONF_PLATFORM]} Telegram bot" |
216 | | - bot_count: int = import_data[CONF_BOT_COUNT] |
217 | | - |
218 | | - import_data[CONF_TRUSTED_NETWORKS] = ",".join( |
219 | | - import_data[CONF_TRUSTED_NETWORKS] |
220 | | - ) |
221 | | - import_data[SECTION_ADVANCED_SETTINGS] = { |
222 | | - CONF_PROXY_URL: import_data.get(CONF_PROXY_URL) |
223 | | - } |
224 | | - try: |
225 | | - config_flow_result: ConfigFlowResult = await self.async_step_user( |
226 | | - import_data |
227 | | - ) |
228 | | - except AbortFlow: |
229 | | - # this happens if the config entry is already imported |
230 | | - self._create_issue(ISSUE_DEPRECATED_YAML, telegram_bot, bot_count) |
231 | | - raise |
232 | | - else: |
233 | | - errors: dict[str, str] | None = config_flow_result.get("errors") |
234 | | - if errors: |
235 | | - error: str = errors.get("base", "unknown") |
236 | | - self._create_issue( |
237 | | - error, |
238 | | - telegram_bot, |
239 | | - bot_count, |
240 | | - config_flow_result["description_placeholders"], |
241 | | - ) |
242 | | - return self.async_abort(reason="import_failed") |
243 | | - |
244 | | - subentries: list[ConfigSubentryData] = [] |
245 | | - allowed_chat_ids: list[int] = import_data[CONF_ALLOWED_CHAT_IDS] |
246 | | - assert self._bot is not None, "Bot should be initialized during import" |
247 | | - for chat_id in allowed_chat_ids: |
248 | | - chat_name: str = await _async_get_chat_name(self._bot, chat_id) |
249 | | - subentry: ConfigSubentryData = ConfigSubentryData( |
250 | | - data={CONF_CHAT_ID: chat_id}, |
251 | | - subentry_type=CONF_ALLOWED_CHAT_IDS, |
252 | | - title=f"{chat_name} ({chat_id})", |
253 | | - unique_id=str(chat_id), |
254 | | - ) |
255 | | - subentries.append(subentry) |
256 | | - config_flow_result["subentries"] = subentries |
257 | | - |
258 | | - self._create_issue( |
259 | | - ISSUE_DEPRECATED_YAML, |
260 | | - telegram_bot, |
261 | | - bot_count, |
262 | | - config_flow_result["description_placeholders"], |
263 | | - ) |
264 | | - return config_flow_result |
265 | | - |
266 | | - def _create_issue( |
267 | | - self, |
268 | | - issue: str, |
269 | | - telegram_bot_type: str, |
270 | | - bot_count: int, |
271 | | - description_placeholders: Mapping[str, str] | None = None, |
272 | | - ) -> None: |
273 | | - translation_key: str = ( |
274 | | - ISSUE_DEPRECATED_YAML |
275 | | - if bot_count == 1 |
276 | | - else ISSUE_DEPRECATED_YAML_HAS_MORE_PLATFORMS |
277 | | - ) |
278 | | - if issue != ISSUE_DEPRECATED_YAML: |
279 | | - translation_key = ISSUE_DEPRECATED_YAML_IMPORT_ISSUE_ERROR |
280 | | - |
281 | | - telegram_bot = ( |
282 | | - description_placeholders.get(BOT_NAME, telegram_bot_type) |
283 | | - if description_placeholders |
284 | | - else telegram_bot_type |
285 | | - ) |
286 | | - error_field = ( |
287 | | - description_placeholders.get(ERROR_FIELD, "Unknown error") |
288 | | - if description_placeholders |
289 | | - else "Unknown error" |
290 | | - ) |
291 | | - error_message = ( |
292 | | - description_placeholders.get(ERROR_MESSAGE, "Unknown error") |
293 | | - if description_placeholders |
294 | | - else "Unknown error" |
295 | | - ) |
296 | | - |
297 | | - async_create_issue( |
298 | | - self.hass, |
299 | | - DOMAIN, |
300 | | - ISSUE_DEPRECATED_YAML, |
301 | | - breaks_in_ha_version="2025.12.0", |
302 | | - is_fixable=False, |
303 | | - issue_domain=DOMAIN, |
304 | | - severity=IssueSeverity.WARNING, |
305 | | - translation_key=translation_key, |
306 | | - translation_placeholders={ |
307 | | - "domain": DOMAIN, |
308 | | - "integration_title": "Telegram Bot", |
309 | | - "telegram_bot": telegram_bot, |
310 | | - ERROR_FIELD: error_field, |
311 | | - ERROR_MESSAGE: error_message, |
312 | | - }, |
313 | | - learn_more_url="https://github.com/home-assistant/core/pull/144617", |
314 | | - ) |
315 | | - |
316 | 203 | async def async_step_user( |
317 | 204 | self, user_input: dict[str, Any] | None = None |
318 | 205 | ) -> ConfigFlowResult: |
@@ -361,23 +248,13 @@ async def async_step_user( |
361 | 248 | CONF_PROXY_URL |
362 | 249 | ), |
363 | 250 | }, |
364 | | - options={ |
365 | | - # this value may come from yaml import |
366 | | - ATTR_PARSER: user_input.get(ATTR_PARSER, PARSER_MD) |
367 | | - }, |
| 251 | + options={ATTR_PARSER: PARSER_MD}, |
368 | 252 | description_placeholders=description_placeholders, |
369 | 253 | ) |
370 | 254 |
|
371 | 255 | self._bot_name = bot_name |
372 | 256 | self._step_user_data.update(user_input) |
373 | 257 |
|
374 | | - if self.source == SOURCE_IMPORT: |
375 | | - return await self.async_step_webhooks( |
376 | | - { |
377 | | - CONF_URL: user_input.get(CONF_URL), |
378 | | - CONF_TRUSTED_NETWORKS: user_input[CONF_TRUSTED_NETWORKS], |
379 | | - } |
380 | | - ) |
381 | 258 | return await self.async_step_webhooks() |
382 | 259 |
|
383 | 260 | async def _shutdown_bot(self) -> None: |
|
0 commit comments