Add support for dashboards to lovelace cast service (#32913)
parent
f93e4e3de7
commit
a6d5ed0160
|
@ -12,6 +12,7 @@ from .const import DOMAIN, SIGNAL_HASS_CAST_SHOW_VIEW
|
||||||
|
|
||||||
SERVICE_SHOW_VIEW = "show_lovelace_view"
|
SERVICE_SHOW_VIEW = "show_lovelace_view"
|
||||||
ATTR_VIEW_PATH = "view_path"
|
ATTR_VIEW_PATH = "view_path"
|
||||||
|
ATTR_URL_PATH = "dashboard_path"
|
||||||
|
|
||||||
|
|
||||||
async def async_setup_ha_cast(
|
async def async_setup_ha_cast(
|
||||||
|
@ -63,11 +64,18 @@ async def async_setup_ha_cast(
|
||||||
controller,
|
controller,
|
||||||
call.data[ATTR_ENTITY_ID],
|
call.data[ATTR_ENTITY_ID],
|
||||||
call.data[ATTR_VIEW_PATH],
|
call.data[ATTR_VIEW_PATH],
|
||||||
|
call.data.get(ATTR_URL_PATH),
|
||||||
)
|
)
|
||||||
|
|
||||||
hass.helpers.service.async_register_admin_service(
|
hass.helpers.service.async_register_admin_service(
|
||||||
DOMAIN,
|
DOMAIN,
|
||||||
SERVICE_SHOW_VIEW,
|
SERVICE_SHOW_VIEW,
|
||||||
handle_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,
|
||||||
|
}
|
||||||
|
),
|
||||||
)
|
)
|
||||||
|
|
|
@ -948,7 +948,11 @@ class CastDevice(MediaPlayerDevice):
|
||||||
await self._async_disconnect()
|
await self._async_disconnect()
|
||||||
|
|
||||||
def _handle_signal_show_view(
|
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."""
|
"""Handle a show view signal."""
|
||||||
if entity_id != self.entity_id:
|
if entity_id != self.entity_id:
|
||||||
|
@ -958,4 +962,4 @@ class CastDevice(MediaPlayerDevice):
|
||||||
self._hass_cast_controller = controller
|
self._hass_cast_controller = controller
|
||||||
self._chromecast.register_handler(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)
|
||||||
|
|
|
@ -4,6 +4,9 @@ show_lovelace_view:
|
||||||
entity_id:
|
entity_id:
|
||||||
description: Media Player entity to show the Lovelace view on.
|
description: Media Player entity to show the Lovelace view on.
|
||||||
example: "media_player.kitchen"
|
example: "media_player.kitchen"
|
||||||
|
dashboard_path:
|
||||||
|
description: The url path of the Lovelace dashboard to show.
|
||||||
|
example: lovelace-cast
|
||||||
view_path:
|
view_path:
|
||||||
description: The path of the Lovelace view to show.
|
description: The path of the Lovelace view to show.
|
||||||
example: downstairs
|
example: downstairs
|
||||||
|
|
|
@ -20,13 +20,38 @@ async def test_service_show_view(hass):
|
||||||
)
|
)
|
||||||
|
|
||||||
assert len(calls) == 1
|
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.hass_url == "http://example.com"
|
||||||
assert controller.client_id is None
|
assert controller.client_id is None
|
||||||
# Verify user did not accidentally submit their dev app id
|
# Verify user did not accidentally submit their dev app id
|
||||||
assert controller.supporting_app_id == "B12CE3CA"
|
assert controller.supporting_app_id == "B12CE3CA"
|
||||||
assert entity_id == "media_player.kitchen"
|
assert entity_id == "media_player.kitchen"
|
||||||
assert view_path == "mock_path"
|
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):
|
async def test_use_cloud_url(hass):
|
||||||
|
|
Loading…
Reference in New Issue