Home Assistant Unofficial Reference 2024.12.1
__init__.py
Go to the documentation of this file.
1 """Support for Azure DevOps."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
7 from homeassistant.config_entries import ConfigEntry
8 from homeassistant.const import Platform
9 from homeassistant.core import HomeAssistant
10 
11 from .const import CONF_PAT, CONF_PROJECT
12 from .coordinator import AzureDevOpsDataUpdateCoordinator
13 
14 type AzureDevOpsConfigEntry = ConfigEntry[AzureDevOpsDataUpdateCoordinator]
15 
16 _LOGGER = logging.getLogger(__name__)
17 
18 PLATFORMS = [Platform.SENSOR]
19 
20 
21 async def async_setup_entry(hass: HomeAssistant, entry: AzureDevOpsConfigEntry) -> bool:
22  """Set up Azure DevOps from a config entry."""
23 
24  # Create the data update coordinator
26  hass,
27  _LOGGER,
28  entry=entry,
29  )
30 
31  # Store the coordinator in runtime data
32  entry.runtime_data = coordinator
33 
34  # If a personal access token is set, authorize the client
35  if entry.data.get(CONF_PAT) is not None:
36  await coordinator.authorize(entry.data[CONF_PAT])
37 
38  # Set the project for the coordinator
39  coordinator.project = await coordinator.get_project(entry.data[CONF_PROJECT])
40 
41  # Fetch initial data so we have data when entities subscribe
42  await coordinator.async_config_entry_first_refresh()
43 
44  # Set up platforms
45  await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
46 
47  return True
48 
49 
50 async def async_unload_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
51  """Unload Azure DevOps config entry."""
52  return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
bool async_setup_entry(HomeAssistant hass, AzureDevOpsConfigEntry entry)
Definition: __init__.py:21
bool async_unload_entry(HomeAssistant hass, ConfigEntry entry)
Definition: __init__.py:50