Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The dnsip component."""
2 
3 from __future__ import annotations
4 
5 from homeassistant.config_entries import ConfigEntry
6 from homeassistant.const import CONF_PORT
7 from homeassistant.core import _LOGGER, HomeAssistant
8 
9 from .const import CONF_PORT_IPV6, DEFAULT_PORT, PLATFORMS
10 
11 
12 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
13  """Set up DNS IP from a config entry."""
14 
15  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
16  entry.async_on_unload(entry.add_update_listener(update_listener))
17  return True
18 
19 
20 async def update_listener(hass: HomeAssistant, entry: ConfigEntry) -> None:
21  """Handle options update."""
22  await hass.config_entries.async_reload(entry.entry_id)
23 
24 
25 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
26  """Unload dnsip config entry."""
27 
28  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
29 
30 
31 async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
32  """Migrate old entry to a newer version."""
33 
34  if config_entry.version > 1:
35  # This means the user has downgraded from a future version
36  return False
37 
38  if config_entry.version < 2 and config_entry.minor_version < 2:
39  version = config_entry.version
40  minor_version = config_entry.minor_version
41  _LOGGER.debug(
42  "Migrating configuration from version %s.%s",
43  version,
44  minor_version,
45  )
46 
47  new_options = {**config_entry.options}
48  new_options[CONF_PORT] = DEFAULT_PORT
49  new_options[CONF_PORT_IPV6] = DEFAULT_PORT
50 
51  hass.config_entries.async_update_entry(
52  config_entry, options=new_options, minor_version=2
53  )
54 
55  _LOGGER.debug(
56  "Migration to configuration version %s.%s successful",
57  1,
58  2,
59  )
60 
61  return True
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:12
bool async_migrate_entry(HomeAssistant hass, ConfigEntry config_entry)
Definition: __init__.py:31
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:25
None update_listener(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:20