Introduce a UUID configuration option for API token (#88765)

* Introduce a UUID configuration option for API token. (#86547)

If the uuid is configured, it will be used in the HTTP headers. Otherwise,
we'll hash the salted instance URL which should be good enough(tm).

* Generate random 6-digit uuid on startup.
This commit is contained in:
Volker Stolz 2023-03-01 03:52:45 +01:00 committed by GitHub
parent 39f5f0946e
commit 86acc4262e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2,6 +2,7 @@
from __future__ import annotations from __future__ import annotations
from datetime import datetime, timedelta from datetime import datetime, timedelta
from random import randint
from enturclient import EnturPublicTransportData from enturclient import EnturPublicTransportData
import voluptuous as vol import voluptuous as vol
@ -22,7 +23,7 @@ from homeassistant.helpers.typing import ConfigType, DiscoveryInfoType
from homeassistant.util import Throttle from homeassistant.util import Throttle
import homeassistant.util.dt as dt_util import homeassistant.util.dt as dt_util
API_CLIENT_NAME = "homeassistant-homeassistant" API_CLIENT_NAME = "homeassistant-{}"
CONF_STOP_IDS = "stop_ids" CONF_STOP_IDS = "stop_ids"
CONF_EXPAND_PLATFORMS = "expand_platforms" CONF_EXPAND_PLATFORMS = "expand_platforms"
@ -105,7 +106,7 @@ async def async_setup_platform(
quays = [s for s in stop_ids if "Quay" in s] quays = [s for s in stop_ids if "Quay" in s]
data = EnturPublicTransportData( data = EnturPublicTransportData(
API_CLIENT_NAME, API_CLIENT_NAME.format(str(randint(100000, 999999))),
stops=stops, stops=stops,
quays=quays, quays=quays,
line_whitelist=line_whitelist, line_whitelist=line_whitelist,