Instantiate new httpx client for lamarzocco (#132016)
parent
905769f0e8
commit
f1ebda7c6f
|
@ -23,7 +23,7 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.helpers import issue_registry as ir
|
||||
from homeassistant.helpers.httpx_client import get_async_client
|
||||
from homeassistant.helpers.httpx_client import create_async_httpx_client
|
||||
|
||||
from .const import CONF_USE_BLUETOOTH, DOMAIN
|
||||
from .coordinator import LaMarzoccoConfigEntry, LaMarzoccoUpdateCoordinator
|
||||
|
@ -47,11 +47,11 @@ async def async_setup_entry(hass: HomeAssistant, entry: LaMarzoccoConfigEntry) -
|
|||
|
||||
assert entry.unique_id
|
||||
serial = entry.unique_id
|
||||
|
||||
client = create_async_httpx_client(hass)
|
||||
cloud_client = LaMarzoccoCloudClient(
|
||||
username=entry.data[CONF_USERNAME],
|
||||
password=entry.data[CONF_PASSWORD],
|
||||
client=get_async_client(hass),
|
||||
client=client,
|
||||
)
|
||||
|
||||
# initialize local API
|
||||
|
@ -61,7 +61,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: LaMarzoccoConfigEntry) -
|
|||
local_client = LaMarzoccoLocalClient(
|
||||
host=host,
|
||||
local_bearer=entry.data[CONF_TOKEN],
|
||||
client=get_async_client(hass),
|
||||
client=client,
|
||||
)
|
||||
|
||||
# initialize Bluetooth
|
||||
|
|
|
@ -6,6 +6,7 @@ from collections.abc import Mapping
|
|||
import logging
|
||||
from typing import Any
|
||||
|
||||
from httpx import AsyncClient
|
||||
from pylamarzocco.client_cloud import LaMarzoccoCloudClient
|
||||
from pylamarzocco.client_local import LaMarzoccoLocalClient
|
||||
from pylamarzocco.exceptions import AuthFail, RequestNotSuccessful
|
||||
|
@ -37,7 +38,7 @@ from homeassistant.const import (
|
|||
)
|
||||
from homeassistant.core import callback
|
||||
from homeassistant.helpers import config_validation as cv
|
||||
from homeassistant.helpers.httpx_client import get_async_client
|
||||
from homeassistant.helpers.httpx_client import create_async_httpx_client
|
||||
from homeassistant.helpers.selector import (
|
||||
SelectOptionDict,
|
||||
SelectSelector,
|
||||
|
@ -57,6 +58,8 @@ class LmConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
|
||||
VERSION = 2
|
||||
|
||||
_client: AsyncClient
|
||||
|
||||
def __init__(self) -> None:
|
||||
"""Initialize the config flow."""
|
||||
self._config: dict[str, Any] = {}
|
||||
|
@ -79,10 +82,12 @@ class LmConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
**user_input,
|
||||
**self._discovered,
|
||||
}
|
||||
self._client = create_async_httpx_client(self.hass)
|
||||
|
||||
cloud_client = LaMarzoccoCloudClient(
|
||||
username=data[CONF_USERNAME],
|
||||
password=data[CONF_PASSWORD],
|
||||
client=self._client,
|
||||
)
|
||||
try:
|
||||
self._fleet = await cloud_client.get_customer_fleet()
|
||||
|
@ -163,7 +168,7 @@ class LmConfigFlow(ConfigFlow, domain=DOMAIN):
|
|||
# validate local connection if host is provided
|
||||
if user_input.get(CONF_HOST):
|
||||
if not await LaMarzoccoLocalClient.validate_connection(
|
||||
client=get_async_client(self.hass),
|
||||
client=self._client,
|
||||
host=user_input[CONF_HOST],
|
||||
token=selected_device.communication_key,
|
||||
):
|
||||
|
|
Loading…
Reference in New Issue