Home Assistant Unofficial Reference 2024.12.1
util.py
Go to the documentation of this file.
1 """Utils for sql."""
2 
3 from __future__ import annotations
4 
5 import logging
6 
7 from homeassistant.components.recorder import get_instance
8 from homeassistant.core import HomeAssistant
9 
10 from .const import DB_URL_RE
11 
12 _LOGGER = logging.getLogger(__name__)
13 
14 
15 def redact_credentials(data: str | None) -> str:
16  """Redact credentials from string data."""
17  if not data:
18  return "none"
19  return DB_URL_RE.sub("//****:****@", data)
20 
21 
22 def resolve_db_url(hass: HomeAssistant, db_url: str | None) -> str:
23  """Return the db_url provided if not empty, otherwise return the recorder db_url."""
24  _LOGGER.debug("db_url: %s", redact_credentials(db_url))
25  if db_url and not db_url.isspace():
26  return db_url
27  return get_instance(hass).db_url
str redact_credentials(str|None data)
Definition: util.py:15
str resolve_db_url(HomeAssistant hass, str|None db_url)
Definition: util.py:22
Recorder get_instance(HomeAssistant hass)
Definition: recorder.py:74