Skip to content

Commit

Permalink
Add force param to DashCast service #419
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexxIT committed Aug 24, 2023
1 parent 6777802 commit 1037c2a
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
2 changes: 2 additions & 0 deletions custom_components/webrtc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
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,
},
required=True,
Expand Down Expand Up @@ -106,6 +107,7 @@ async def dash_cast(call: ServiceCallType):
hass,
call.data[ATTR_ENTITY_ID],
f"{get_url(hass)}/webrtc/embed?" + urlencode(query),
call.data.get("force"),
)

hass.services.async_register(DOMAIN, "create_link", create_link, CREATE_LINK_SCHEMA)
Expand Down
5 changes: 5 additions & 0 deletions custom_components/webrtc/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ dash_cast:
selector:
text:

force:
description: Force restart DashCast application
selector:
boolean:

entity:
description: Camera entity
example: camera.generic_stream
Expand Down
4 changes: 2 additions & 2 deletions custom_components/webrtc/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ async def init_resource(hass: HomeAssistant, url: str, ver: str) -> bool:


# noinspection PyProtectedMember
def dash_cast(hass: HomeAssistant, cast_entities: list, url: str):
def dash_cast(hass: HomeAssistant, cast_entities: list, url: str, force=False):
"""Cast webpage to chromecast device via DashCast application."""
try:
entities = [
Expand All @@ -188,7 +188,7 @@ def dash_cast(hass: HomeAssistant, cast_entities: list, url: str):
entity._chromecast.register_handler(entity.dashcast)

_LOGGER.debug(f"DashCast to {entity.entity_id}")
entity.dashcast.load_url(url)
entity.dashcast.load_url(url, force)

except Exception:
_LOGGER.exception(f"Can't DashCast to {cast_entities}")
Expand Down

0 comments on commit 1037c2a

Please sign in to comment.