diff --git a/homeassistant/components/github/__init__.py b/homeassistant/components/github/__init__.py index 74575e38e09..dea2acf4f1b 100644 --- a/homeassistant/components/github/__init__.py +++ b/homeassistant/components/github/__init__.py @@ -4,7 +4,6 @@ from __future__ import annotations from aiogithubapi import GitHubAPI -from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_ACCESS_TOKEN, Platform from homeassistant.core import HomeAssistant, callback from homeassistant.helpers import device_registry as dr @@ -14,14 +13,11 @@ from homeassistant.helpers.aiohttp_client import ( ) from .const import CONF_REPOSITORIES, DOMAIN, LOGGER -from .coordinator import GitHubDataUpdateCoordinator +from .coordinator import GithubConfigEntry, GitHubDataUpdateCoordinator PLATFORMS: list[Platform] = [Platform.SENSOR] -type GithubConfigEntry = ConfigEntry[dict[str, GitHubDataUpdateCoordinator]] - - async def async_setup_entry(hass: HomeAssistant, entry: GithubConfigEntry) -> bool: """Set up GitHub from a config entry.""" client = GitHubAPI( @@ -36,6 +32,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: GithubConfigEntry) -> bo for repository in repositories: coordinator = GitHubDataUpdateCoordinator( hass=hass, + config_entry=entry, client=client, repository=repository, ) @@ -57,7 +54,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: GithubConfigEntry) -> bo @callback def async_cleanup_device_registry( hass: HomeAssistant, - entry: ConfigEntry, + entry: GithubConfigEntry, ) -> None: """Remove entries form device registry if we no longer track the repository.""" device_registry = dr.async_get(hass) @@ -92,6 +89,6 @@ async def async_unload_entry(hass: HomeAssistant, entry: GithubConfigEntry) -> b return await hass.config_entries.async_unload_platforms(entry, PLATFORMS) -async def async_reload_entry(hass: HomeAssistant, entry: ConfigEntry) -> None: +async def async_reload_entry(hass: HomeAssistant, entry: GithubConfigEntry) -> None: """Handle an options update.""" await hass.config_entries.async_reload(entry.entry_id) diff --git a/homeassistant/components/github/coordinator.py b/homeassistant/components/github/coordinator.py index e73e02932e9..adeda1fd88a 100644 --- a/homeassistant/components/github/coordinator.py +++ b/homeassistant/components/github/coordinator.py @@ -13,6 +13,7 @@ from aiogithubapi import ( GitHubResponseModel, ) +from homeassistant.config_entries import ConfigEntry from homeassistant.const import EVENT_HOMEASSISTANT_STOP from homeassistant.core import HomeAssistant from homeassistant.helpers.update_coordinator import DataUpdateCoordinator, UpdateFailed @@ -98,13 +99,18 @@ query ($owner: String!, $repository: String!) { } """ +type GithubConfigEntry = ConfigEntry[dict[str, GitHubDataUpdateCoordinator]] + class GitHubDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]): """Data update coordinator for the GitHub integration.""" + config_entry: GithubConfigEntry + def __init__( self, hass: HomeAssistant, + config_entry: GithubConfigEntry, client: GitHubAPI, repository: str, ) -> None: @@ -118,6 +124,7 @@ class GitHubDataUpdateCoordinator(DataUpdateCoordinator[dict[str, Any]]): super().__init__( hass, LOGGER, + config_entry=config_entry, name=repository, update_interval=FALLBACK_UPDATE_INTERVAL, ) diff --git a/homeassistant/components/github/diagnostics.py b/homeassistant/components/github/diagnostics.py index 8d2d496a813..41fef9406a4 100644 --- a/homeassistant/components/github/diagnostics.py +++ b/homeassistant/components/github/diagnostics.py @@ -6,7 +6,6 @@ from typing import Any from aiogithubapi import GitHubAPI, GitHubException -from homeassistant.config_entries import ConfigEntry from homeassistant.const import CONF_ACCESS_TOKEN from homeassistant.core import HomeAssistant from homeassistant.helpers.aiohttp_client import ( @@ -14,10 +13,12 @@ from homeassistant.helpers.aiohttp_client import ( async_get_clientsession, ) +from .coordinator import GithubConfigEntry + async def async_get_config_entry_diagnostics( hass: HomeAssistant, - config_entry: ConfigEntry, + config_entry: GithubConfigEntry, ) -> dict[str, Any]: """Return diagnostics for a config entry.""" data = {"options": {**config_entry.options}} diff --git a/homeassistant/components/github/sensor.py b/homeassistant/components/github/sensor.py index 614ebe254c4..a7ecb4ec8da 100644 --- a/homeassistant/components/github/sensor.py +++ b/homeassistant/components/github/sensor.py @@ -18,9 +18,8 @@ from homeassistant.helpers.entity_platform import AddEntitiesCallback from homeassistant.helpers.typing import StateType from homeassistant.helpers.update_coordinator import CoordinatorEntity -from . import GithubConfigEntry from .const import DOMAIN -from .coordinator import GitHubDataUpdateCoordinator +from .coordinator import GithubConfigEntry, GitHubDataUpdateCoordinator @dataclass(frozen=True, kw_only=True)