1 """The GitHub integration."""
3 from __future__
import annotations
5 from aiogithubapi
import GitHubAPI
13 async_get_clientsession,
16 from .const
import CONF_REPOSITORIES, DOMAIN, LOGGER
17 from .coordinator
import GitHubDataUpdateCoordinator
19 PLATFORMS: list[Platform] = [Platform.SENSOR]
22 type GithubConfigEntry = ConfigEntry[dict[str, GitHubDataUpdateCoordinator]]
26 """Set up GitHub from a config entry."""
28 token=entry.data[CONF_ACCESS_TOKEN],
30 client_name=SERVER_SOFTWARE,
33 repositories: list[str] = entry.options[CONF_REPOSITORIES]
35 entry.runtime_data = {}
36 for repository
in repositories:
40 repository=repository,
43 await coordinator.async_config_entry_first_refresh()
45 if not entry.pref_disable_polling:
46 await coordinator.subscribe()
48 entry.runtime_data[repository] = coordinator
52 await hass.config_entries.async_forward_entry_setups(entry, PLATFORMS)
53 entry.async_on_unload(entry.add_update_listener(async_reload_entry))
62 """Remove entries form device registry if we no longer track the repository."""
63 device_registry = dr.async_get(hass)
64 devices = dr.async_entries_for_config_entry(
65 registry=device_registry,
66 config_entry_id=entry.entry_id,
68 for device
in devices:
69 for item
in device.identifiers:
70 if item[0] == DOMAIN
and item[1]
not in entry.options[CONF_REPOSITORIES]:
73 "Unlinking device %s for untracked repository %s from config"
80 device_registry.async_update_device(
81 device.id, remove_config_entry_id=entry.entry_id
87 """Unload a config entry."""
88 repositories = entry.runtime_data
89 for coordinator
in repositories.values():
90 coordinator.unsubscribe()
92 return await hass.config_entries.async_unload_platforms(entry, PLATFORMS)
96 """Handle an options update."""
97 await hass.config_entries.async_reload(entry.entry_id)
bool async_unload_entry(HomeAssistant hass, GithubConfigEntry entry)
None async_reload_entry(HomeAssistant hass, ConfigEntry entry)
bool async_setup_entry(HomeAssistant hass, GithubConfigEntry entry)
None async_cleanup_device_registry(HomeAssistant hass, ConfigEntry entry)
aiohttp.ClientSession async_get_clientsession(HomeAssistant hass, bool verify_ssl=True, socket.AddressFamily family=socket.AF_UNSPEC, ssl_util.SSLCipherList ssl_cipher=ssl_util.SSLCipherList.PYTHON_DEFAULT)