Inject websession for Roborock api client (#141141)

This commit is contained in:
Luke Lashley 2025-03-22 15:19:54 -04:00 committed by GitHub
parent 7f640252a1
commit 6d91bdb02e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 14 additions and 6 deletions

View File

@ -24,6 +24,7 @@ from homeassistant.const import CONF_USERNAME, EVENT_HOMEASSISTANT_STOP
from homeassistant.core import HomeAssistant
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
from homeassistant.helpers import device_registry as dr
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import CONF_BASE_URL, CONF_USER_DATA, DOMAIN, PLATFORMS
from .coordinator import (
@ -45,7 +46,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: RoborockConfigEntry) ->
entry.async_on_unload(entry.add_update_listener(update_listener))
user_data = UserData.from_dict(entry.data[CONF_USER_DATA])
api_client = RoborockApiClient(entry.data[CONF_USERNAME], entry.data[CONF_BASE_URL])
api_client = RoborockApiClient(
entry.data[CONF_USERNAME],
entry.data[CONF_BASE_URL],
session=async_get_clientsession(hass),
)
_LOGGER.debug("Getting home data")
try:
home_data = await api_client.get_home_data_v2(user_data)

View File

@ -28,6 +28,7 @@ from homeassistant.config_entries import (
)
from homeassistant.const import CONF_USERNAME
from homeassistant.core import callback
from homeassistant.helpers.aiohttp_client import async_get_clientsession
from .const import (
CONF_BASE_URL,
@ -63,7 +64,9 @@ class RoborockFlowHandler(ConfigFlow, domain=DOMAIN):
self._abort_if_unique_id_configured(error="already_configured_account")
self._username = username
_LOGGER.debug("Requesting code for Roborock account")
self._client = RoborockApiClient(username)
self._client = RoborockApiClient(
username, session=async_get_clientsession(self.hass)
)
errors = await self._request_code()
if not errors:
return await self.async_step_code()
@ -140,7 +143,9 @@ class RoborockFlowHandler(ConfigFlow, domain=DOMAIN):
"""Perform reauth upon an API authentication error."""
self._username = entry_data[CONF_USERNAME]
assert self._username
self._client = RoborockApiClient(self._username)
self._client = RoborockApiClient(
self._username, session=async_get_clientsession(self.hass)
)
return await self.async_step_reauth_confirm()
async def async_step_reauth_confirm(

View File

@ -73,7 +73,5 @@ rules:
stale-devices: done
# Platinum
async-dependency: todo
inject-websession:
status: todo
comment: Web API uses aiohttp but does not yet inject web session.
inject-websession: done
strict-typing: todo