feat(ha_adb_common): application-label parser — default-locale from pm dump, localized variants skipped, tolerant of empty/multi-label blocks (P5-1)
This commit is contained in:
1 parent
17648f43c9
commit
80e9a691bc
2 files changed
+29
No files matched your search
@@ -1,6 +1,7 @@
|
||||
"""Shared ADB utilities for Home Assistant custom integrations."""
|
||||
|
||||
from .adb_client import AdbClientBase, parse_wakefulness
|
||||
from .app_label import parse_application_label
|
||||
from .const import (
|
||||
ATTR_MEDIA_DAG_JELLYFIN_ENTITY,
|
||||
ATTR_MEDIA_DAG_NOW_PLAYING,
|
||||
@@ -32,6 +33,7 @@ __all__ = [
|
||||
"PlaybackIntent",
|
||||
"ensure_adb_key",
|
||||
"parse_all_media_sessions",
|
||||
"parse_application_label",
|
||||
"parse_audio_playback",
|
||||
"parse_foreground",
|
||||
"parse_wakefulness",
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
"""App friendly-name resolution from the package manifest (P5-1).
|
||||
|
||||
Parses `pm dump <package>` output for the ``application-label`` line — the
|
||||
default-locale variant; localized suffixed variants
|
||||
(``application-label-<lang>:``) are skipped, and multi-label blocks across
|
||||
locales are tolerated (first default-locale label wins), mirroring the
|
||||
tolerant pattern of the androidtv-adb core helper.
|
||||
"""
|
||||
|
||||
import re
|
||||
|
||||
_APPLICATION_LABEL_RE = re.compile(r"application-label(?:-[A-Za-z_-]+)?:\s*'([^']*)'")
|
||||
|
||||
|
||||
def parse_application_label(dump: str) -> str | None:
|
||||
"""The package's default-locale application label, or None.
|
||||
|
||||
Returns None on empty/failed dumps too — callers fall through to the
|
||||
next name tier.
|
||||
"""
|
||||
if not dump:
|
||||
return None
|
||||
for match in _APPLICATION_LABEL_RE.finditer(dump):
|
||||
label = (match.group(1) or "").strip()
|
||||
if label and label not in ("null", ""):
|
||||
return label
|
||||
return None
|
||||
Reference in new issue
Block a user