From fced9eb4b5b713ab9425ca83d9d20d45252b42ce Mon Sep 17 00:00:00 2001 From: Robert Resch Date: Tue, 23 Apr 2024 14:33:05 +0200 Subject: [PATCH] Use location name on self hosted Ecovacs config entries (#115294) --- homeassistant/components/ecovacs/config_flow.py | 2 +- homeassistant/components/ecovacs/controller.py | 5 +++-- homeassistant/components/ecovacs/util.py | 8 ++++++-- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/homeassistant/components/ecovacs/config_flow.py b/homeassistant/components/ecovacs/config_flow.py index a1ea19144b0..4a421113f5f 100644 --- a/homeassistant/components/ecovacs/config_flow.py +++ b/homeassistant/components/ecovacs/config_flow.py @@ -71,7 +71,7 @@ async def _validate_input( if errors: return errors - device_id = get_client_device_id() + device_id = get_client_device_id(hass, rest_url is not None) country = user_input[CONF_COUNTRY] rest_config = create_rest_config( aiohttp_client.async_get_clientsession(hass), diff --git a/homeassistant/components/ecovacs/controller.py b/homeassistant/components/ecovacs/controller.py index 5defcdf861f..6b6fe3128dd 100644 --- a/homeassistant/components/ecovacs/controller.py +++ b/homeassistant/components/ecovacs/controller.py @@ -43,7 +43,8 @@ class EcovacsController: self._hass = hass self._devices: list[Device] = [] self.legacy_devices: list[VacBot] = [] - self._device_id = get_client_device_id() + rest_url = config.get(CONF_OVERRIDE_REST_URL) + self._device_id = get_client_device_id(hass, rest_url is not None) country = config[CONF_COUNTRY] self._continent = get_continent(country) @@ -52,7 +53,7 @@ class EcovacsController: aiohttp_client.async_get_clientsession(self._hass), device_id=self._device_id, alpha_2_country=country, - override_rest_url=config.get(CONF_OVERRIDE_REST_URL), + override_rest_url=rest_url, ), config[CONF_USERNAME], md5(config[CONF_PASSWORD]), diff --git a/homeassistant/components/ecovacs/util.py b/homeassistant/components/ecovacs/util.py index ab5db58c579..9d692bbbb8f 100644 --- a/homeassistant/components/ecovacs/util.py +++ b/homeassistant/components/ecovacs/util.py @@ -9,7 +9,8 @@ from typing import TYPE_CHECKING from deebot_client.capabilities import Capabilities -from homeassistant.core import callback +from homeassistant.core import HomeAssistant, callback +from homeassistant.util import slugify from .entity import ( EcovacsCapabilityEntityDescription, @@ -21,8 +22,11 @@ if TYPE_CHECKING: from .controller import EcovacsController -def get_client_device_id() -> str: +def get_client_device_id(hass: HomeAssistant, self_hosted: bool) -> str: """Get client device id.""" + if self_hosted: + return f"HA-{slugify(hass.config.location_name)}" + return "".join( random.choice(string.ascii_uppercase + string.digits) for _ in range(8) )