Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Home Assistant SkyConnect integration."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
7 from homeassistant.components.homeassistant_hardware.util import guess_firmware_type
8 from homeassistant.config_entries import ConfigEntry
9 from homeassistant.core import HomeAssistant
10 
11 _LOGGER = logging.getLogger(__name__)
12 
13 
14 async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
15  """Set up a Home Assistant SkyConnect config entry."""
16  return True
17 
18 
19 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
20  """Unload a config entry."""
21  return True
22 
23 
24 async def async_migrate_entry(hass: HomeAssistant, config_entry: ConfigEntry) -> bool:
25  """Migrate old entry."""
26 
27  _LOGGER.debug(
28  "Migrating from version %s:%s", config_entry.version, config_entry.minor_version
29  )
30 
31  if config_entry.version == 1:
32  if config_entry.minor_version == 1:
33  # Add-on startup with type service get started before Core, always (e.g. the
34  # Multi-Protocol add-on). Probing the firmware would interfere with the add-on,
35  # so we can't safely probe here. Instead, we must make an educated guess!
36  firmware_guess = await guess_firmware_type(
37  hass, config_entry.data["device"]
38  )
39 
40  new_data = {**config_entry.data}
41  new_data["firmware"] = firmware_guess.firmware_type.value
42 
43  # Copy `description` to `product`
44  new_data["product"] = new_data["description"]
45 
46  hass.config_entries.async_update_entry(
47  config_entry,
48  data=new_data,
49  version=1,
50  minor_version=2,
51  )
52 
53  _LOGGER.debug(
54  "Migration to version %s.%s successful",
55  config_entry.version,
56  config_entry.minor_version,
57  )
58 
59  return True
60 
61  # This means the user has downgraded from a future version
62  return False
FirmwareGuess guess_firmware_type(HomeAssistant hass, str device_path)
Definition: util.py:73
bool async_setup_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:14
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:19
bool async_migrate_entry(HomeAssistant hass, ConfigEntry config_entry)
Definition: __init__.py:24