Skip to content

Commit

Permalink
Instantiate new httpx client for lamarzocco (home-assistant#132016)
Browse files Browse the repository at this point in the history
  • Loading branch information
zweckj authored Dec 3, 2024
1 parent 9e72375 commit e3885b8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
8 changes: 4 additions & 4 deletions homeassistant/components/lamarzocco/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
)
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
Expand All @@ -46,11 +46,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
Expand All @@ -60,7 +60,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
Expand Down
9 changes: 7 additions & 2 deletions homeassistant/components/lamarzocco/config_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
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
Expand Down Expand Up @@ -36,7 +37,7 @@
)
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,
Expand All @@ -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] = {}
Expand All @@ -79,10 +82,12 @@ async def async_step_user(
**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()
Expand Down Expand Up @@ -163,7 +168,7 @@ async def async_step_machine_selection(
# 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,
):
Expand Down

0 comments on commit e3885b8

Please sign in to comment.