diff --git a/homeassistant/components/lamarzocco/__init__.py b/homeassistant/components/lamarzocco/__init__.py index 15ff1634687..96d4f4c61ac 100644 --- a/homeassistant/components/lamarzocco/__init__.py +++ b/homeassistant/components/lamarzocco/__init__.py @@ -4,6 +4,7 @@ import asyncio import logging import uuid +from aiohttp import ClientSession from packaging import version from pylamarzocco import ( LaMarzoccoBluetoothClient, @@ -21,6 +22,7 @@ from homeassistant.const import ( CONF_TOKEN, CONF_USERNAME, Platform, + __version__, ) from homeassistant.core import HomeAssistant from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady @@ -63,7 +65,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: LaMarzoccoConfigEntry) - username=entry.data[CONF_USERNAME], password=entry.data[CONF_PASSWORD], installation_key=InstallationKey.from_json(entry.data[CONF_INSTALLATION_KEY]), - client=async_create_clientsession(hass), + client=create_client_session(hass), ) try: @@ -185,6 +187,7 @@ async def async_migrate_entry( username=entry.data[CONF_USERNAME], password=entry.data[CONF_PASSWORD], installation_key=installation_key, + client=create_client_session(hass), ) try: await cloud_client.async_register_client() @@ -203,3 +206,15 @@ async def async_migrate_entry( _LOGGER.debug("Migrated La Marzocco config entry to version 4") return True + + +def create_client_session(hass: HomeAssistant) -> ClientSession: + """Create a ClientSession with La Marzocco specific headers.""" + + return async_create_clientsession( + hass, + headers={ + "X-Client": "HOME_ASSISTANT", + "X-Client-Build": __version__, + }, + ) diff --git a/homeassistant/components/lamarzocco/config_flow.py b/homeassistant/components/lamarzocco/config_flow.py index 7f08ac9a48e..ab99fbbc63f 100644 --- a/homeassistant/components/lamarzocco/config_flow.py +++ b/homeassistant/components/lamarzocco/config_flow.py @@ -35,7 +35,6 @@ from homeassistant.const import ( ) from homeassistant.core import callback from homeassistant.helpers import config_validation as cv -from homeassistant.helpers.aiohttp_client import async_create_clientsession from homeassistant.helpers.selector import ( SelectOptionDict, SelectSelector, @@ -47,6 +46,7 @@ from homeassistant.helpers.selector import ( ) from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo +from . import create_client_session from .const import CONF_INSTALLATION_KEY, CONF_USE_BLUETOOTH, DOMAIN from .coordinator import LaMarzoccoConfigEntry @@ -86,7 +86,7 @@ class LmConfigFlow(ConfigFlow, domain=DOMAIN): **user_input, } - self._client = async_create_clientsession(self.hass) + self._client = create_client_session(self.hass) self._installation_key = generate_installation_key( str(uuid.uuid4()).lower() )