Skip to content

Commit 9cd940b

Browse files
zweckjfrenck
authored andcommitted
Add La Marzocco specific client headers (home-assistant#152419)
1 parent 10b186a commit 9cd940b

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

homeassistant/components/lamarzocco/__init__.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import logging
55
import uuid
66

7+
from aiohttp import ClientSession
78
from packaging import version
89
from pylamarzocco import (
910
LaMarzoccoBluetoothClient,
@@ -21,6 +22,7 @@
2122
CONF_TOKEN,
2223
CONF_USERNAME,
2324
Platform,
25+
__version__,
2426
)
2527
from homeassistant.core import HomeAssistant
2628
from homeassistant.exceptions import ConfigEntryAuthFailed, ConfigEntryNotReady
@@ -63,7 +65,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: LaMarzoccoConfigEntry) -
6365
username=entry.data[CONF_USERNAME],
6466
password=entry.data[CONF_PASSWORD],
6567
installation_key=InstallationKey.from_json(entry.data[CONF_INSTALLATION_KEY]),
66-
client=async_create_clientsession(hass),
68+
client=create_client_session(hass),
6769
)
6870

6971
try:
@@ -185,6 +187,7 @@ async def async_migrate_entry(
185187
username=entry.data[CONF_USERNAME],
186188
password=entry.data[CONF_PASSWORD],
187189
installation_key=installation_key,
190+
client=create_client_session(hass),
188191
)
189192
try:
190193
await cloud_client.async_register_client()
@@ -203,3 +206,15 @@ async def async_migrate_entry(
203206
_LOGGER.debug("Migrated La Marzocco config entry to version 4")
204207

205208
return True
209+
210+
211+
def create_client_session(hass: HomeAssistant) -> ClientSession:
212+
"""Create a ClientSession with La Marzocco specific headers."""
213+
214+
return async_create_clientsession(
215+
hass,
216+
headers={
217+
"X-Client": "HOME_ASSISTANT",
218+
"X-Client-Build": __version__,
219+
},
220+
)

homeassistant/components/lamarzocco/config_flow.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
)
3636
from homeassistant.core import callback
3737
from homeassistant.helpers import config_validation as cv
38-
from homeassistant.helpers.aiohttp_client import async_create_clientsession
3938
from homeassistant.helpers.selector import (
4039
SelectOptionDict,
4140
SelectSelector,
@@ -47,6 +46,7 @@
4746
)
4847
from homeassistant.helpers.service_info.dhcp import DhcpServiceInfo
4948

49+
from . import create_client_session
5050
from .const import CONF_INSTALLATION_KEY, CONF_USE_BLUETOOTH, DOMAIN
5151
from .coordinator import LaMarzoccoConfigEntry
5252

@@ -86,7 +86,7 @@ async def async_step_user(
8686
**user_input,
8787
}
8888

89-
self._client = async_create_clientsession(self.hass)
89+
self._client = create_client_session(self.hass)
9090
self._installation_key = generate_installation_key(
9191
str(uuid.uuid4()).lower()
9292
)

0 commit comments

Comments
 (0)