Exemple #1
0
async def test_use_cloud_url(hass, mock_zeroconf):
    """Test that we fall back to cloud url."""
    await async_process_ha_core_config(
        hass,
        {"internal_url": "http://example.local:8123"},
    )
    hass.config.components.add("cloud")

    await home_assistant_cast.async_setup_ha_cast(hass, MockConfigEntry())
    calls = async_mock_signal(hass,
                              home_assistant_cast.SIGNAL_HASS_CAST_SHOW_VIEW)

    with patch(
            "homeassistant.components.cloud.async_remote_ui_url",
            return_value="https://something.nabu.casa",
    ):
        await hass.services.async_call(
            "cast",
            "show_lovelace_view",
            {
                "entity_id": "media_player.kitchen",
                "view_path": "mock_path"
            },
            blocking=True,
        )

    assert len(calls) == 1
    controller = calls[0][0]
    assert controller.hass_url == "https://something.nabu.casa"
Exemple #2
0
async def test_service_show_view(hass, mock_zeroconf):
    """Test we don't set app id in prod."""
    await async_process_ha_core_config(
        hass,
        {"external_url": "https://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"
        },
        blocking=True,
    )

    assert len(calls) == 1
    controller, entity_id, view_path, url_path = calls[0]
    assert controller.hass_url == "https://example.com"
    assert controller.client_id is None
    # Verify user did not accidentally submit their dev app id
    assert controller.supporting_app_id == "A078F6B0"
    assert entity_id == "media_player.kitchen"
    assert view_path == "mock_path"
    assert url_path is None
Exemple #3
0
async def test_service_show_view_dashboard(hass, mock_zeroconf):
    """Test casting a specific dashboard."""
    await async_process_ha_core_config(
        hass,
        {"external_url": "https://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"
Exemple #4
0
async def test_ws_subscription(hassio_env, hass: HomeAssistant, hass_ws_client):
    """Test websocket subscription."""
    assert await async_setup_component(hass, "hassio", {})
    client = await hass_ws_client(hass)
    await client.send_json({WS_ID: 5, WS_TYPE: WS_TYPE_SUBSCRIBE})
    response = await client.receive_json()
    assert response["success"]

    calls = async_mock_signal(hass, EVENT_SUPERVISOR_EVENT)
    async_dispatcher_send(hass, EVENT_SUPERVISOR_EVENT, {"lorem": "ipsum"})

    response = await client.receive_json()
    assert response["event"]["lorem"] == "ipsum"
    assert len(calls) == 1

    await client.send_json(
        {
            WS_ID: 6,
            WS_TYPE: "supervisor/event",
            ATTR_DATA: {ATTR_WS_EVENT: "test", "lorem": "ipsum"},
        }
    )
    response = await client.receive_json()
    assert response["success"]
    assert len(calls) == 2

    response = await client.receive_json()
    assert response["event"]["lorem"] == "ipsum"

    # Unsubscribe
    await client.send_json({WS_ID: 7, WS_TYPE: "unsubscribe_events", "subscription": 5})
    response = await client.receive_json()
    assert response["success"]
async def test_no_update_when_get_request_returns_none(hass, config_entry,
                                                       mock_api_object):
    """Test when get request returns None."""
    async def get_request_side_effect(update_type):
        return None

    mock_api_object.get_request.side_effect = get_request_side_effect
    updater_update = mock_api_object.start_websocket_handler.call_args[0][2]
    signal_output_call = async_mock_signal(
        hass, SIGNAL_UPDATE_OUTPUTS.format(config_entry.entry_id))
    signal_player_call = async_mock_signal(
        hass, SIGNAL_UPDATE_PLAYER.format(config_entry.entry_id))
    signal_queue_call = async_mock_signal(
        hass, SIGNAL_UPDATE_QUEUE.format(config_entry.entry_id))
    await updater_update(["outputs", "player", "queue"])
    await hass.async_block_till_done()
    assert len(signal_output_call) == 0
    assert len(signal_player_call) == 0
    assert len(signal_queue_call) == 0