mirror of
https://github.com/home-assistant/core.git
synced 2025-07-23 13:17:32 +00:00
Move imports in gitlab_ci component (#27827)
This commit is contained in:
parent
9d583ad9f9
commit
6998687742
@ -2,6 +2,7 @@
|
|||||||
from datetime import timedelta
|
from datetime import timedelta
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
from gitlab import Gitlab, GitlabAuthenticationError, GitlabGetError
|
||||||
import voluptuous as vol
|
import voluptuous as vol
|
||||||
|
|
||||||
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
from homeassistant.components.sensor import PLATFORM_SCHEMA
|
||||||
@ -141,12 +142,10 @@ class GitLabData:
|
|||||||
|
|
||||||
def __init__(self, gitlab_id, priv_token, interval, url):
|
def __init__(self, gitlab_id, priv_token, interval, url):
|
||||||
"""Fetch data from GitLab API for most recent CI job."""
|
"""Fetch data from GitLab API for most recent CI job."""
|
||||||
import gitlab
|
|
||||||
|
|
||||||
self._gitlab_id = gitlab_id
|
self._gitlab_id = gitlab_id
|
||||||
self._gitlab = gitlab.Gitlab(url, private_token=priv_token, per_page=1)
|
self._gitlab = Gitlab(url, private_token=priv_token, per_page=1)
|
||||||
self._gitlab.auth()
|
self._gitlab.auth()
|
||||||
self._gitlab_exceptions = gitlab.exceptions
|
|
||||||
self.update = Throttle(interval)(self._update)
|
self.update = Throttle(interval)(self._update)
|
||||||
|
|
||||||
self.available = False
|
self.available = False
|
||||||
@ -174,9 +173,9 @@ class GitLabData:
|
|||||||
self.build_id = _last_job.attributes.get("id")
|
self.build_id = _last_job.attributes.get("id")
|
||||||
self.branch = _last_job.attributes.get("ref")
|
self.branch = _last_job.attributes.get("ref")
|
||||||
self.available = True
|
self.available = True
|
||||||
except self._gitlab_exceptions.GitlabAuthenticationError as erra:
|
except GitlabAuthenticationError as erra:
|
||||||
_LOGGER.error("Authentication Error: %s", erra)
|
_LOGGER.error("Authentication Error: %s", erra)
|
||||||
self.available = False
|
self.available = False
|
||||||
except self._gitlab_exceptions.GitlabGetError as errg:
|
except GitlabGetError as errg:
|
||||||
_LOGGER.error("Project Not Found: %s", errg)
|
_LOGGER.error("Project Not Found: %s", errg)
|
||||||
self.available = False
|
self.available = False
|
||||||
|
Loading…
x
Reference in New Issue
Block a user