From 89899e6e18aed4304290da9558dbfe08f4d323cd Mon Sep 17 00:00:00 2001 From: Alex X Date: Sun, 7 Apr 2024 16:48:57 +0300 Subject: [PATCH] Add hass_url param to dash_cast service --- custom_components/webrtc/__init__.py | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/custom_components/webrtc/__init__.py b/custom_components/webrtc/__init__.py index fe3bfd6..6d5f365 100644 --- a/custom_components/webrtc/__init__.py +++ b/custom_components/webrtc/__init__.py @@ -45,8 +45,9 @@ vol.Required(ATTR_ENTITY_ID): cv.entity_ids, vol.Exclusive("url", "url"): cv.string, vol.Exclusive("entity", "url"): cv.entity_id, - vol.Optional("force", default=False): bool, vol.Optional("extra"): dict, + vol.Optional("force", default=False): bool, + vol.Optional("hass_url"): str, }, required=True, ) @@ -93,20 +94,24 @@ async def create_link(call: ServiceCallType): async def dash_cast(call: ServiceCallType): link_id = uuid.uuid4().hex LINKS[link_id] = { - "url": call.data.get("url"), - "entity": call.data.get("entity"), + "url": call.data.get("url"), # camera URL (rtsp...) + "entity": call.data.get("entity"), # camera entity id "limit": 1, # 1 attempt "ts": time.time() + 30, # for 30 seconds } + hass_url = call.data.get("hass_url") or get_url(hass) query = call.data.get("extra", {}) query["url"] = link_id + cast_url = hass_url + "/webrtc/embed?" + urlencode(query) + + _LOGGER.debug(f"dash_cast: {cast_url}") await hass.async_add_executor_job( utils.dash_cast, hass, call.data[ATTR_ENTITY_ID], - f"{get_url(hass)}/webrtc/embed?" + urlencode(query), + cast_url, call.data.get("force", False), )