Normalize snapshot URLs in HA integration

Convert relative snapshot image_url responses to absolute URLs using configured RelayTV base_url and refresh API helper notes for /playback/play fallback semantics.
This commit is contained in:
2026-03-19 20:33:43 -05:00
parent f86d2fec4a
commit d581a66ef0
2 changed files with 19 additions and 1 deletions
+17
View File
@@ -61,6 +61,22 @@ def _normalize_base_url(raw: str) -> str:
return normalized
def _absolute_url(base_url: str, maybe_url: str | None) -> str | None:
if not maybe_url:
return None
value = str(maybe_url).strip()
if not value:
return None
parsed = urlparse(value)
if parsed.scheme in ("http", "https"):
return value
base = (base_url or "").rstrip("/")
tail = value.lstrip("/")
if not base or not tail:
return None
return f"{base}/{tail}"
async def async_setup(hass: HomeAssistant, config: dict) -> bool:
hass.data.setdefault(DOMAIN, {})
return True
@@ -377,6 +393,7 @@ async def async_setup_entry(hass: HomeAssistant, entry: ConfigEntry) -> bool:
return
data = await store[DATA_API].snapshot() or {}
snapshot_url = data.get("image_url") if isinstance(data, dict) else None
snapshot_url = _absolute_url(store[DATA_API].base_url, snapshot_url)
if snapshot_url:
store[DATA_LAST_SNAPSHOT_URL] = snapshot_url
await store[DATA_COORDINATOR].async_request_refresh()
+2 -1
View File
@@ -9,6 +9,7 @@ We intentionally prefer the canonical endpoints:
- POST /enqueue
- POST /next
- POST /pause | /resume | /toggle_pause
- POST /playback/play
- POST /seek_abs
- POST /volume
- POST /stop
@@ -201,7 +202,7 @@ class RelayTVApi:
async def ensure_playing(self) -> bool:
"""Best-effort play semantics for Home Assistant.
RelayTV does not currently expose a single "resume session or play next" endpoint.
Used as a compatibility fallback when /playback/play is unavailable.
We emulate expected behavior:
- If paused -> POST /resume