Skip to content

Commit

Permalink
Upgrade aioazuredevops to 2.0.0 (#114537)
Browse files Browse the repository at this point in the history
* Upgrade aioazuredevops to 2.0.0

* Refactor Azure DevOps config flow to use async_get_clientsession

* Wrap conditional in parentesis
  • Loading branch information
timmo001 authored Apr 1, 2024
1 parent 2e11a61 commit 429b5d2
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 11 deletions.
11 changes: 9 additions & 2 deletions homeassistant/components/azure_devops/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
from homeassistant.const import Platform
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from homeassistant.helpers.device_registry import DeviceEntryType, DeviceInfo
from homeassistant.helpers.entity import EntityDescription
from homeassistant.helpers.update_coordinator import (
Expand Down Expand Up @@ -43,7 +44,8 @@ class AzureDevOpsEntityDescription(EntityDescription):

async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
"""Set up Azure DevOps from a config entry."""
client = DevOpsClient()
aiohttp_session = async_get_clientsession(hass)
client = DevOpsClient(session=aiohttp_session)

if entry.data.get(CONF_PAT) is not None:
await client.authorize(entry.data[CONF_PAT], entry.data[CONF_ORG])
Expand All @@ -62,14 +64,19 @@ async def async_update_data() -> list[DevOpsBuild]:
"""Fetch data from Azure DevOps."""

try:
return await client.get_builds(
builds = await client.get_builds(
entry.data[CONF_ORG],
entry.data[CONF_PROJECT],
BUILDS_QUERY,
)
except aiohttp.ClientError as exception:
raise UpdateFailed from exception

if builds is None:
raise UpdateFailed("No builds found")

return builds

coordinator = DataUpdateCoordinator(
hass,
_LOGGER,
Expand Down
4 changes: 3 additions & 1 deletion homeassistant/components/azure_devops/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import voluptuous as vol

from homeassistant.config_entries import ConfigFlow, ConfigFlowResult
from homeassistant.helpers.aiohttp_client import async_get_clientsession

from .const import CONF_ORG, CONF_PAT, CONF_PROJECT, DOMAIN

Expand Down Expand Up @@ -56,7 +57,8 @@ async def _check_setup(self) -> dict[str, str] | None:
"""Check the setup of the flow."""
errors: dict[str, str] = {}

client = DevOpsClient()
aiohttp_session = async_get_clientsession(self.hass)
client = DevOpsClient(session=aiohttp_session)

try:
if self._pat is not None:
Expand Down
2 changes: 1 addition & 1 deletion homeassistant/components/azure_devops/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
"documentation": "https://www.home-assistant.io/integrations/azure_devops",
"iot_class": "cloud_polling",
"loggers": ["aioazuredevops"],
"requirements": ["aioazuredevops==1.4.3"]
"requirements": ["aioazuredevops==2.0.0"]
}
14 changes: 9 additions & 5 deletions homeassistant/components/azure_devops/sensor.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,19 +39,23 @@ async def async_setup_entry(
AzureDevOpsSensor(
coordinator,
AzureDevOpsSensorEntityDescription(
key=f"{build.project.id}_{build.definition.id}_latest_build",
key=f"{build.project.project_id}_{build.definition.build_id}_latest_build",
translation_key="latest_build",
translation_placeholders={"definition_name": build.definition.name},
attrs=lambda build: {
"definition_id": build.definition.id,
"definition_name": build.definition.name,
"id": build.id,
"definition_id": (
build.definition.build_id if build.definition else None
),
"definition_name": (
build.definition.name if build.definition else None
),
"id": build.build_id,
"reason": build.reason,
"result": build.result,
"source_branch": build.source_branch,
"source_version": build.source_version,
"status": build.status,
"url": build.links.web,
"url": build.links.web if build.links else None,
"queue_time": build.queue_time,
"start_time": build.start_time,
"finish_time": build.finish_time,
Expand Down
2 changes: 1 addition & 1 deletion requirements_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ aioasuswrt==1.4.0
aioautomower==2024.3.4

# homeassistant.components.azure_devops
aioazuredevops==1.4.3
aioazuredevops==2.0.0

# homeassistant.components.baf
aiobafi6==0.9.0
Expand Down
2 changes: 1 addition & 1 deletion requirements_test_all.txt
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ aioasuswrt==1.4.0
aioautomower==2024.3.4

# homeassistant.components.azure_devops
aioazuredevops==1.4.3
aioazuredevops==2.0.0

# homeassistant.components.baf
aiobafi6==0.9.0
Expand Down

0 comments on commit 429b5d2

Please sign in to comment.