1 """Custom data update coordinator for the GitHub integration."""
3 from __future__
import annotations
7 from aiogithubapi
import (
9 GitHubConnectionException,
12 GitHubRatelimitException,
20 from .const
import FALLBACK_UPDATE_INTERVAL, LOGGER, REFRESH_EVENT_TYPES
22 GRAPHQL_REPOSITORY_QUERY =
"""
23 query ($owner: String!, $repository: String!) {
28 repository(owner: $owner, name: $repository) {
29 default_branch_ref: defaultBranchRef {
32 message: messageHeadline
38 stargazers_count: stargazerCount
39 forks_count: forkCount
40 full_name: nameWithOwner
45 discussion: discussions(
47 orderBy: {field: CREATED_AT, direction: DESC}
59 orderBy: {field: CREATED_AT, direction: DESC}
68 pull_request: pullRequests(
71 orderBy: {field: CREATED_AT, direction: DESC}
74 pull_requests: nodes {
80 release: latestRelease {
87 refPrefix: "refs/tags/"
88 orderBy: {field: TAG_COMMIT_DATE, direction: DESC}
103 """Data update coordinator for the GitHub integration."""
111 """Initialize GitHub data update coordinator base class."""
114 self.
_last_response_last_response: GitHubResponseModel[dict[str, Any]] |
None =
None
122 update_interval=FALLBACK_UPDATE_INTERVAL,
127 owner, repository = self.
repositoryrepository.split(
"/")
129 response = await self.
_client_client.graphql(
130 query=GRAPHQL_REPOSITORY_QUERY,
131 variables={
"owner": owner,
"repository": repository},
133 except (GitHubConnectionException, GitHubRatelimitException)
as exception:
136 except GitHubException
as exception:
138 LOGGER.exception(exception)
142 return response.data[
"data"][
"repository"]
145 """Handle an event."""
146 if event.type
in REFRESH_EVENT_TYPES:
151 """Handle an error."""
152 LOGGER.error(
"An error occurred while processing new events - %s", error)
155 """Subscribe to repository events."""
161 self.
hasshass.bus.async_listen_once(EVENT_HOMEASSISTANT_STOP, self.
unsubscribeunsubscribe)
164 """Unsubscribe to repository events."""
None unsubscribe(self, *args)
GitHubResponseModel[dict[str, Any]] _async_update_data(self)
None _handle_error(GitHubException error)
None _handle_event(self, GitHubEventModel event)
None __init__(self, HomeAssistant hass, GitHubAPI client, str repository)
None async_request_refresh(self)