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 Paulus Schoutsen
parent b82da9418d
commit 9f3f71d0c3

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,