dlna_dms fixes from code review (#67796)
This commit is contained in:
parent
bdb61e0222
commit
62aa7fe10e
11 changed files with 610 additions and 630 deletions
27
homeassistant/components/dlna_dms/util.py
Normal file
27
homeassistant/components/dlna_dms/util.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
"""Small utility functions for the dlna_dms integration."""
|
||||
from __future__ import annotations
|
||||
|
||||
from homeassistant.core import HomeAssistant
|
||||
from homeassistant.util import slugify
|
||||
|
||||
from .const import CONF_SOURCE_ID, DOMAIN
|
||||
|
||||
|
||||
def generate_source_id(hass: HomeAssistant, name: str) -> str:
|
||||
"""Generate a unique source ID."""
|
||||
other_entries = hass.config_entries.async_entries(DOMAIN)
|
||||
other_source_ids: set[str] = {
|
||||
other_source_id
|
||||
for entry in other_entries
|
||||
if (other_source_id := entry.data.get(CONF_SOURCE_ID))
|
||||
}
|
||||
|
||||
source_id_base = slugify(name)
|
||||
if source_id_base not in other_source_ids:
|
||||
return source_id_base
|
||||
|
||||
tries = 1
|
||||
while (suggested_source_id := f"{source_id_base}_{tries}") in other_source_ids:
|
||||
tries += 1
|
||||
|
||||
return suggested_source_id
|
Loading…
Add table
Add a link
Reference in a new issue