mirror of
https://github.com/tomaae/homeassistant-mikrotik_router.git
synced 2025-07-21 19:24:38 +02:00
refactor(mikrotik_router): use existing session for fetching release notes
Optimized the process of fetching release notes in the Mikrotik Router integration by utilizing the existing HTTP client session from Home Assistant's aiohttp_client. This change avoids creating a new session for each request, leading to more efficient resource usage and potentially reducing the likelihood of encountering issues related to session management. By leveraging `async_get_clientsession`, the update component now aligns better with Home Assistant's recommended practices for external HTTP requests, ensuring consistency and reliability in how network calls are made within integrations.
This commit is contained in:
parent
ccc097c438
commit
2aa2191334
1 changed files with 13 additions and 13 deletions
|
@ -9,7 +9,7 @@ from typing import Any
|
|||
from homeassistant.config_entries import ConfigEntry
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers.entity_platform import AddEntitiesCallback
|
||||
from homeassistant.helpers.aiohttp_client import async_create_clientsession
|
||||
from homeassistant.helpers.aiohttp_client import async_get_clientsession
|
||||
|
||||
from homeassistant.components.update import (
|
||||
UpdateEntity,
|
||||
|
@ -92,18 +92,18 @@ class MikrotikRouterOSUpdate(MikrotikEntity, UpdateEntity):
|
|||
async def async_release_notes(self) -> str:
|
||||
"""Return the release notes."""
|
||||
try:
|
||||
async with async_create_clientsession(self.hass) as session:
|
||||
async with session.get(
|
||||
f"https://cdn.mikrotik.com/routeros/{self._data['latest-version']}/CHANGELOG"
|
||||
) as response:
|
||||
if response.status == 200:
|
||||
text = await response.text()
|
||||
return text.replace("*) ", "- ")
|
||||
else:
|
||||
_LOGGER.warning(
|
||||
"Failed to fetch release notes due to a network error."
|
||||
)
|
||||
return "Failed to fetch release notes due to a network error."
|
||||
session = async_get_clientsession(self.hass)
|
||||
async with session.get(
|
||||
f"https://cdn.mikrotik.com/routeros/{self._data['latest-version']}/CHANGELOG"
|
||||
) as response:
|
||||
if response.status == 200:
|
||||
text = await response.text()
|
||||
return text.replace("*) ", "- ")
|
||||
else:
|
||||
_LOGGER.warning(
|
||||
"Failed to fetch release notes due to a network error."
|
||||
)
|
||||
return "Failed to fetch release notes due to a network error."
|
||||
except Exception as e:
|
||||
_LOGGER.warning("Failed to download release notes (%s)", e)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue