Use location name on self hosted Ecovacs config entries (#115294)

pull/116038/head
Robert Resch 2024-04-23 14:33:05 +02:00 committed by GitHub
parent 2c651e190f
commit fced9eb4b5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 10 additions and 5 deletions

View File

@ -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),

View File

@ -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]),

View File

@ -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)
)