Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for dashboards to lovelace cast service #32913

Merged
merged 1 commit into from
Mar 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 9 additions & 1 deletion homeassistant/components/cast/home_assistant_cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

SERVICE_SHOW_VIEW = "show_lovelace_view"
ATTR_VIEW_PATH = "view_path"
ATTR_URL_PATH = "dashboard_path"


async def async_setup_ha_cast(
Expand Down Expand Up @@ -63,11 +64,18 @@ async def handle_show_view(call: core.ServiceCall):
controller,
call.data[ATTR_ENTITY_ID],
call.data[ATTR_VIEW_PATH],
call.data.get(ATTR_URL_PATH),
)

hass.helpers.service.async_register_admin_service(
DOMAIN,
SERVICE_SHOW_VIEW,
handle_show_view,
vol.Schema({ATTR_ENTITY_ID: cv.entity_id, ATTR_VIEW_PATH: str}),
vol.Schema(
{
ATTR_ENTITY_ID: cv.entity_id,
ATTR_VIEW_PATH: str,
vol.Optional(ATTR_URL_PATH): str,
}
),
)
8 changes: 6 additions & 2 deletions homeassistant/components/cast/media_player.py
Original file line number Diff line number Diff line change
Expand Up @@ -948,7 +948,11 @@ async def _async_stop(self, event):
await self._async_disconnect()

def _handle_signal_show_view(
self, controller: HomeAssistantController, entity_id: str, view_path: str
self,
controller: HomeAssistantController,
entity_id: str,
view_path: str,
url_path: Optional[str],
):
"""Handle a show view signal."""
if entity_id != self.entity_id:
Expand All @@ -958,4 +962,4 @@ def _handle_signal_show_view(
self._hass_cast_controller = controller
self._chromecast.register_handler(controller)

self._hass_cast_controller.show_lovelace_view(view_path)
self._hass_cast_controller.show_lovelace_view(view_path, url_path)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to upgrade pychromecast for this or did we already do?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already did

3 changes: 3 additions & 0 deletions homeassistant/components/cast/services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ show_lovelace_view:
entity_id:
description: Media Player entity to show the Lovelace view on.
example: "media_player.kitchen"
dashboard_path:
description: The url path of the Lovelace dashboard to show.
example: lovelace-cast
view_path:
description: The path of the Lovelace view to show.
example: downstairs
27 changes: 26 additions & 1 deletion tests/components/cast/test_home_assistant_cast.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,38 @@ async def test_service_show_view(hass):
)

assert len(calls) == 1
controller, entity_id, view_path = calls[0]
controller, entity_id, view_path, url_path = calls[0]
assert controller.hass_url == "http://example.com"
assert controller.client_id is None
# Verify user did not accidentally submit their dev app id
assert controller.supporting_app_id == "B12CE3CA"
assert entity_id == "media_player.kitchen"
assert view_path == "mock_path"
assert url_path is None


async def test_service_show_view_dashboard(hass):
"""Test casting a specific dashboard."""
hass.config.api = Mock(base_url="http://example.com")
await home_assistant_cast.async_setup_ha_cast(hass, MockConfigEntry())
calls = async_mock_signal(hass, home_assistant_cast.SIGNAL_HASS_CAST_SHOW_VIEW)

await hass.services.async_call(
"cast",
"show_lovelace_view",
{
"entity_id": "media_player.kitchen",
"view_path": "mock_path",
"dashboard_path": "mock-dashboard",
},
blocking=True,
)

assert len(calls) == 1
_controller, entity_id, view_path, url_path = calls[0]
assert entity_id == "media_player.kitchen"
assert view_path == "mock_path"
assert url_path == "mock-dashboard"


async def test_use_cloud_url(hass):
Expand Down