Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """The Homewizard integration."""
2 
3 from homeassistant.config_entries import SOURCE_REAUTH, ConfigEntry
4 from homeassistant.core import HomeAssistant
5 from homeassistant.exceptions import ConfigEntryNotReady
6 
7 from .const import DOMAIN, PLATFORMS
8 from .coordinator import HWEnergyDeviceUpdateCoordinator
9 
10 type HomeWizardConfigEntry = ConfigEntry[HWEnergyDeviceUpdateCoordinator]
11 
12 
13 async def async_setup_entry(hass: HomeAssistant, entry: HomeWizardConfigEntry) -> bool:
14  """Set up Homewizard from a config entry."""
15  coordinator = HWEnergyDeviceUpdateCoordinator(hass)
16  try:
17  await coordinator.async_config_entry_first_refresh()
18 
19  except ConfigEntryNotReady:
20  await coordinator.api.close()
21 
22  if coordinator.api_disabled:
23  entry.async_start_reauth(hass)
24 
25  raise
26 
27  entry.runtime_data = coordinator
28 
29  # Abort reauth config flow if active
30  for progress_flow in hass.config_entries.flow.async_progress_by_handler(DOMAIN):
31  if (
32  "context" in progress_flow
33  and progress_flow["context"].get("source") == SOURCE_REAUTH
34  ):
35  hass.config_entries.flow.async_abort(progress_flow["flow_id"])
36 
37  # Finalize
38  entry.async_on_unload(coordinator.api.close)
39  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
40 
41  return True
42 
43 
44 async def async_unload_entry(hass: HomeAssistant, entry: HomeWizardConfigEntry) -> bool:
45  """Unload a config entry."""
46  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
web.Response get(self, web.Request request, str config_key)
Definition: view.py:88
bool async_setup_entry(HomeAssistant hass, HomeWizardConfigEntry entry)
Definition: __init__.py:13
bool async_unload_entry(HomeAssistant hass, HomeWizardConfigEntry entry)
Definition: __init__.py:44